Package java.nio.charset

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


  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


            }
           
            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);
           
            // For a one-way message or whatever, there may not be a content type.
            // throw away any encoding modifier.
View Full Code Here

            if (enc == null) {
                charset = DEFAULT_CHARSET;
            } else {
                charset = B2CConverter.getCharset(enc);
            }
            strValue = charset.decode(
                    ByteBuffer.wrap(buff, start, end-start)).toString();
            /*
             Does not improve the speed too much on most systems,
             it's safer to use the "clasical" new String().
            
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

        while (i < len && data[i] != '\'') i++;
        i++;
      } while (i < len && data[i] != ','); // word must end with "',"
     
      if (i >= len) break; // EOF
      String word = charset.decode(ByteBuffer.wrap(data, start, i-start-1)).toString();
//      String word = new String(data, 0, start, i-start-1); // ASCII
     
      /*
       * Part B: ignore phrases (with spaces and hyphens) and
       * non-alphabetic words, and let user customize word (e.g. do some
View Full Code Here

        contentSource = null;
      } else if (document != null) {
        content = HtmlSerialization.serialize(document);
      } else if (contentBytes != null) {
        Charset useEncoding = contentEncoding != null ? contentEncoding : Charsets.UTF_8;
        content = useEncoding.decode(ByteBuffer.wrap(contentBytes)).toString();
      }
    }
    return content;
  }
View Full Code Here

     
      while(!fin)
      {
        byte in = data[currChar];
        ByteBuffer bb = ByteBuffer.wrap(new byte[] { (byte) in });
        CharBuffer cb = csets.decode(bb);
        char c = cb.charAt(0);
     
        if(data.length > 0 && (c == '\n' || c == '\r'))
          currChar++;
        else
View Full Code Here

      fin = false;
      for(int i = 0; i < data.length && !fin; i++, currChar++)
      {
        byte in = data[currChar];
        ByteBuffer bb = ByteBuffer.wrap(new byte[] { (byte) in });
        CharBuffer cb = csets.decode(bb);
        char c = cb.charAt(0);
       
        if(c == '\n' || c == '\r')
          fin = true;
        else
View Full Code Here

      if(currChar >= data.length)
        break;

      byte in = data[currChar];
      ByteBuffer bb = ByteBuffer.wrap(new byte[] { (byte) in });
      CharBuffer cb = csets.decode(bb);
      char c = cb.charAt(0);

      if(data.length > 0 && (c == '\n' || c == '\r'))
        currChar++;
      else
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.