List of utility methods to do Charset Create
CharsetEncoder | getEncoder() get Encoder final CharsetEncoder encoder; if (Charset.isSupported(ENCODING)) { encoder = Charset.forName(ENCODING).newEncoder(); } else { encoder = Charset.defaultCharset().newEncoder(); return encoder; |
CharsetEncoder | getEncoder(String encoding) get Encoder return getCharset(encoding).newEncoder();
|
Charset | getEncoding(byte[] htmlData) get Encoding Charset charset = null; String charsetName = getEncodingName(htmlData); if (charsetName != null) { try { charset = Charset.forName(charsetName); } catch (Exception e) { System.err.println("Charset encoding " + charsetName + " not found"); charset = null; ... |
String | getEncoding(OutputStreamWriter inWriter) Get the default system encoding using a writer String encoding = inWriter.getEncoding(); try { encoding = Charset.forName(encoding).name(); } catch (Exception e) { return encoding; |
Charset | getEncoding(String text) get Encoding Pattern xml = Pattern.compile("^\\s*<\\?xml\\s+[^>]*\\s*encoding\\s*=\\s*(\"[^\"]*\")", Pattern.DOTALL | Pattern.MULTILINE); Matcher xmlMatcher = xml.matcher(text); if (xmlMatcher.find()) return getEncoding(xmlMatcher); Pattern html = Pattern.compile( "^\\s*<(html|HTML).*<(meta|META)\\s+[^>]*\\s*(charset|CHARSET)\\s*=\\s*(\"[^\"]*\"|[^\"\\s]*)", Pattern.DOTALL | Pattern.MULTILINE); ... |
String | getEncodingOfXml(File file) Try to find the encoding of a xml file. byte[] bs = readFile(file, 150); String encoding = "utf-8"; boolean findEncoding = false; Map chars = Charset.availableCharsets(); Set keys = chars.keySet(); Iterator iterator = keys.iterator(); Pattern pattern = Pattern.compile("encoding=\"([^\"]*?)\""); while (iterator.hasNext()) { ... |
Charset | getEncodingOption(List Extract the encoding flag from the list of javac options. int i = options.lastIndexOf("-encoding"); return (i >= 0) ? Charset.forName(options.get(i + 1)) : null; |
String[] | getEncodings() get Encodings if (encodings == null) { SortedMap<String, Charset> m = Charset.availableCharsets(); Set<String> keySet = m.keySet(); encodings = keySet.toArray(new String[keySet.size()]); return encodings; |
String[] | getEncodings() Returns a list of supported character encodings. List returnValue = new ArrayList(); Map map = Charset.availableCharsets(); Iterator iter = map.keySet().iterator(); returnValue.add(UTF_8_Y); while (iter.hasNext()) returnValue.add(iter.next()); return (String[]) returnValue.toArray(new String[returnValue.size()]); |