List of usage examples for org.apache.commons.codec CharEncoding ISO_8859_1
String ISO_8859_1
To view the source code for org.apache.commons.codec CharEncoding ISO_8859_1.
Click Source Link
From source file:de.ifgi.mosia.wpswfs.Util.java
public static String readContent(InputStream is, String enc) { if (is == null) { return null; }// w w w. j av a 2 s . c o m Scanner sc = new Scanner(is, enc == null ? CharEncoding.ISO_8859_1 : enc); StringBuilder sb = new StringBuilder(); String sep = System.getProperty("line.separator"); while (sc.hasNext()) { sb.append(sc.nextLine()); sb.append(sep); } sc.close(); return sb.toString(); }
From source file:com.bfd.util.StringUtils.java
/** * Encodes the given string into a sequence of bytes using the ISO-8859-1 charset, storing the result into a new * byte array.//from w w w.j a v a 2 s .c om * * @param string * the String to encode, may be <code>null</code> * @return encoded bytes, or <code>null</code> if the input string was <code>null</code> * @throws IllegalStateException * Thrown when the charset is missing, which should be never according the the Java specification. * @see <a href="http://download.oracle.com/javase/1.5.0/docs/api/java/nio/charset/Charset.html">Standard charsets</a> * @see #getBytesUnchecked(String, String) */ public static byte[] getBytesIso8859_1(String string) { return StringUtils.getBytesUnchecked(string, CharEncoding.ISO_8859_1); }
From source file:de.ifgi.mosia.wpswfs.Util.java
public static String readContent(HttpResponse response) throws IOException { Header encHeader = response.getEntity().getContentEncoding(); String enc;//from w ww . ja va 2s . com if (encHeader != null) { enc = encHeader.getValue(); } else { enc = CharEncoding.ISO_8859_1; } return readContent(response.getEntity().getContent(), enc); }
From source file:de.ifgi.mosia.wpswfs.BaseServlet.java
@Override protected void doPost(final HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { RequestHandler handler;//from w w w. j ava2 s . co m String payload; String enc; try { enc = req.getCharacterEncoding(); if (enc == null || enc.isEmpty()) { enc = CharEncoding.ISO_8859_1; } payload = Util.readContent(req.getInputStream(), enc); handler = resolveHandlerFromPost(payload); } catch (ServiceException e) { throw new RuntimeException(e); } if (handler == null) { handler = genericHandler; } try { handler.handlePostRequest(req, resp, payload, enc); } catch (ServiceException e) { throw new IOException(e); } }
From source file:io.datenwelt.cargo.rest.utils.Rfc2047.java
public static String encodeHeader(String input) { StringTokenizer tokenizer = new StringTokenizer(input, "\t ,;:-/=+#*", true); CharsetEncoder charsetEncoder = Charset.forName(CharEncoding.ISO_8859_1).newEncoder(); QCodec qcodec = new QCodec(Charset.forName(CharEncoding.UTF_8)); StringBuilder encoded = new StringBuilder(); while (tokenizer.hasMoreTokens()) { String token = tokenizer.nextToken(); if (!charsetEncoder.canEncode(token)) { try { encoded.append(qcodec.encode(token)); } catch (EncoderException ex) { LOG.debug("Skipping the Q encoding of header value for non ISO-8859-1 string: {}", input, ex); encoded.append(token);//from w ww . j a v a2s .c o m } } else { encoded.append(token); } } return encoded.toString(); }
From source file:com.bfd.util.StringUtils.java
/** * Constructs a new <code>String</code> by decoding the specified array of bytes using the ISO-8859-1 charset. * //from w w w . j a va 2 s. co m * @param bytes * The bytes to be decoded into characters, may be <code>null</code> * @return A new <code>String</code> decoded from the specified array of bytes using the ISO-8859-1 charset, * or <code>null</code> if the input byte array was <code>null</code>. * @throws IllegalStateException * Thrown when a {@link UnsupportedEncodingException} is caught, which should never happen since the * charset is required. */ public static String newStringIso8859_1(byte[] bytes) { return StringUtils.newString(bytes, CharEncoding.ISO_8859_1); }
From source file:com.google.android.gms.common.GooglePlayServicesUtil.java
private static byte[] ag(String str) { try {/*from w w w .jav a 2 s . c om*/ return str.getBytes(CharEncoding.ISO_8859_1); } catch (UnsupportedEncodingException e) { throw new AssertionError(e); } }
From source file:org.apache.hawq.pxf.service.rest.RestResource.java
/** * Converts the request headers multivalued map to a case-insensitive * regular map by taking only first values and storing them in a * CASE_INSENSITIVE_ORDER TreeMap. All values are converted from ISO_8859_1 * (ISO-LATIN-1) to UTF_8.//from w ww .j a v a2 s .c o m * * @param requestHeaders request headers multi map. * @return a regular case-insensitive map. * @throws UnsupportedEncodingException if the named charsets ISO_8859_1 and * UTF_8 are not supported */ public Map<String, String> convertToCaseInsensitiveMap(MultivaluedMap<String, String> requestHeaders) throws UnsupportedEncodingException { Map<String, String> result = new TreeMap<>(String.CASE_INSENSITIVE_ORDER); for (Map.Entry<String, List<String>> entry : requestHeaders.entrySet()) { String key = entry.getKey(); List<String> values = entry.getValue(); if (values != null) { String value = values.get(0); if (value != null) { // converting to value UTF-8 encoding value = new String(value.getBytes(CharEncoding.ISO_8859_1), CharEncoding.UTF_8); LOG.trace("key: " + key + ". value: " + value); result.put(key, value.replace("\\\"", "\"")); } } } return result; }
From source file:org.apache.hawq.pxf.service.rest.RestResourceTest.java
@Test public void testConvertToCaseInsensitiveMapUtf8() throws Exception { byte[] bytes = { (byte) 0x61, (byte) 0x32, (byte) 0x63, (byte) 0x5c, (byte) 0x22, (byte) 0x55, (byte) 0x54, (byte) 0x46, (byte) 0x38, (byte) 0x5f, (byte) 0xe8, (byte) 0xa8, (byte) 0x88, (byte) 0xe7, (byte) 0xae, (byte) 0x97, (byte) 0xe6, (byte) 0xa9, (byte) 0x9f, (byte) 0xe7, (byte) 0x94, (byte) 0xa8, (byte) 0xe8, (byte) 0xaa, (byte) 0x9e, (byte) 0x5f, (byte) 0x30, (byte) 0x30, (byte) 0x30, (byte) 0x30, (byte) 0x30, (byte) 0x30, (byte) 0x30, (byte) 0x30, (byte) 0x5c, (byte) 0x22, (byte) 0x6f, (byte) 0x35 }; String value = new String(bytes, CharEncoding.ISO_8859_1); multivaluedMap.put("one", Collections.singletonList(value)); Map<String, String> caseInsensitiveMap = restResource.convertToCaseInsensitiveMap(multivaluedMap); assertEquals("Only one key should have exist", caseInsensitiveMap.keySet().size(), 1); assertEquals("Value should be converted to UTF-8", caseInsensitiveMap.get("one"), "a2c\"UTF8__00000000\"o5"); }