1 package com.atlassian.seraph.util;
2
3 import java.io.UnsupportedEncodingException;
4
5
6
7
8 public class CharsetUtils
9 {
10 private CharsetUtils()
11 {
12
13 }
14
15 public static final String UTF_8_CHARSET = "UTF-8";
16 public static final String ISO_LATIN_1_CHARSET = "ISO-8859-1";
17 public static final String US_ASCII_CHARSET = "US-ASCII";
18
19 public static byte[] bytesFromString(String str, String charset)
20 {
21 try
22 {
23 return str.getBytes(charset);
24 }
25 catch (UnsupportedEncodingException uee)
26 {
27
28 throw new RuntimeException(uee);
29 }
30 }
31
32 public static String stringFromBytes(byte[] bytes, String charset)
33 {
34 try
35 {
36 return new String(bytes, charset);
37 }
38 catch (UnsupportedEncodingException uee)
39 {
40
41 throw new RuntimeException(uee);
42 }
43 }
44 }