Package java.nio.charset

Examples of java.nio.charset.Charset.decode()


             * XML parse.
             */
            Charset contentCharset = Charset.forName(contentEncoding);
            byte[] contentBytes = baos.toByteArray();
            CharBuffer contentChars =
                contentCharset.decode(ByteBuffer.wrap(contentBytes)); // not the most efficient way.
            responseText = contentChars.toString();
            LOG.fine(responseText);
           
            if (responseBytes.length > 0
                && ("text/xml".equals(contentType)
View Full Code Here


        // start + length could overflow, start/length maybe MaxInt
        if (start >= 0 && 0 <= length && length <= data.length - start) {
            offset = 0;
            Charset charset = defaultCharset();
            int result;
            CharBuffer cb = charset
                    .decode(ByteBuffer.wrap(data, start, length));
            if ((result = cb.length()) > 0) {
                value = cb.array();
                count = result;
            } else {
View Full Code Here

            Charset charset = getCharset(encoding);

            int result;
          CharBuffer cb;
            try {
              cb = charset.decode(ByteBuffer.wrap(data, start, length));
            } catch (Exception e) {
              // do nothing. according to spec:
              // behavior is unspecified for invalid array
              cb = CharBuffer.wrap("\u003f".toCharArray()); //$NON-NLS-1$
            }
View Full Code Here

            ByteBuffer byteBuffer = (ByteBuffer) message;
            // Keep current position in the buffer
            int currentPos = byteBuffer.position();
            // Decode buffer
            Charset encoder = Charset.forName("UTF-8");
            CharBuffer charBuffer = encoder.decode(byteBuffer.buf());
            // Print buffer content
            System.out.println(prefix + " - RECV (" + session.hashCode() + "): " + charBuffer);
            // Reset to old position in the buffer
            byteBuffer.position(currentPos);
        }
View Full Code Here

  public static char[] getChars (byte[] bytes) {
    Charset cs = Charset.forName ("UTF-8");
    ByteBuffer bb = ByteBuffer.allocate (bytes.length);
    bb.put (bytes);
                bb.flip ();
    CharBuffer cb = cs.decode (bb);
   
    return cb.array();
  }

}
View Full Code Here

  public static char[] getChars (byte[] bytes) {
    Charset cs = Charset.forName ("UTF-8");
    ByteBuffer bb = ByteBuffer.allocate (bytes.length);
    bb.put (bytes);
                bb.flip ();
    CharBuffer cb = cs.decode (bb);
   
    return cb.array();
  }

}
View Full Code Here

 
  public static String toString(byte[] value, int offset, int length,
      String encoding) throws UnsupportedEncodingException {
    Charset cs = findCharset(encoding);

    return cs.decode(ByteBuffer.wrap(value, offset, length)).toString();
  }

  public static String toString(byte[] value, String encoding)
      throws UnsupportedEncodingException {
    Charset cs = findCharset(encoding);
View Full Code Here

  public static String toString(byte[] value, String encoding)
      throws UnsupportedEncodingException {
    Charset cs = findCharset(encoding);

    return cs.decode(ByteBuffer.wrap(value)).toString();
  }

  public static String toString(byte[] value, int offset, int length) {
    try {
      Charset cs = findCharset(platformEncoding);
View Full Code Here

  public static String toString(byte[] value, int offset, int length) {
    try {
      Charset cs = findCharset(platformEncoding);
     
      return cs.decode(ByteBuffer.wrap(value, offset, length)).toString();
    } catch (UnsupportedEncodingException e) {
      // can't happen, emulating new String(byte[])
    }
   
    return null;
View Full Code Here

  public static String toString(byte[] value) {
    try {
      Charset cs = findCharset(platformEncoding);
     
      return cs.decode(ByteBuffer.wrap(value)).toString();
    } catch (UnsupportedEncodingException e) {
      // can't happen, emulating new String(byte[])
    }
   
    return null;
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.