Exemple #1
0
  static byte[] encode(String charsetName, char[] ca, int off, int len)
      throws UnsupportedEncodingException {

    StringEncoder se = (StringEncoder) deref(encoder);

    String csn = (charsetName == null) ? "ISO-8859-1" : charsetName;

    if ((se == null) || !(csn.equals(se.requestedCharsetName()) || csn.equals(se.charsetName()))) {

      se = null;

      try {

        Charset cs = lookupCharset(csn);

        if (cs != null) se = new CharsetSE(cs, csn);

      } catch (IllegalCharsetNameException x) {

        // FALL THROUGH to CharToByteConverter, for compatibility

      }

      if (se == null) se = new ConverterSE(CharToByteConverter.getConverter(csn), csn);

      set(encoder, se);
    }

    return se.encode(ca, off, len);
  }
 static byte[] encode(String charsetName, char[] ca, int off, int len)
     throws UnsupportedEncodingException {
   StringEncoder se = deref(encoder);
   String csn = (charsetName == null) ? "ISO-8859-1" : charsetName;
   if ((se == null) || !(csn.equals(se.requestedCharsetName()) || csn.equals(se.charsetName()))) {
     se = null;
     try {
       Charset cs = lookupCharset(csn);
       if (cs != null) se = new StringEncoder(cs, csn);
     } catch (IllegalCharsetNameException x) {
     }
     if (se == null) throw new UnsupportedEncodingException(csn);
     set(encoder, se);
   }
   return se.encode(ca, off, len);
 }
Exemple #3
0
 /**
  * Helper function that serializes a SerializableEntity to a byte array.
  *
  * @param entity The entity to serialize.
  * @return The resulting byte array.
  */
 public static byte[] serializeToBytes(final SerializableEntity entity) {
   return StringEncoder.getBytes(serializeToJson(entity).toJSONString());
 }
Exemple #4
0
 public static String encode(String src) throws IOException {
   StringEncoder encoder = new StringEncoder();
   encoder.feed(src.getBytes("utf-8"), 0, src.length());
   encoder.finish();
   return encoder.getValue();
 }