Package java.nio.charset

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


  // convert byte array to char array, assuming UTF-8 encoding

  static protected char[] convertByteToCharUTF(byte[] byteArray) {
    Charset c = Charset.forName("UTF-8");
    CharBuffer output = c.decode(ByteBuffer.wrap(byteArray));
    return output.array();
  }

  // convert char array to byte array, assuming UTF-8 encoding
  static protected byte[] convertCharToByteUTF(char[] from) {
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

        // TODO: Make sure that the entire world settles on one encoding and
        // that every file in existance is re-encoded.
        final Charset cs = Charset.forName("UTF-8");
        while (fc.read(buf) != -1) {
            buf.rewind();
            final CharBuffer chbuf = cs.decode(buf);
            sb.append(chbuf.array());
            buf.clear();
        }

        in.close();
View Full Code Here

     * @param charsetName
     * @return
     */
    private String convert(byte[] byteArray, String charsetName) {
        final Charset charSet = Charset.forName(charsetName);
        final CharBuffer buf = charSet.decode(ByteBuffer.wrap(byteArray));
        return buf.toString();
    }

    public String toString() {
        StringBuffer s = new StringBuffer();
View Full Code Here

    appBuffer.clear();
    result = serverEngine.unwrap(cnetBuffer, appBuffer);
    if (result.getStatus() != Status.OK)
      throw new SSLException("unexpected status: " + result.getStatus());
    appBuffer.flip();
    String msg = cs.decode(appBuffer).toString();
    if (!msg.equals(TEST_MESSAGE))
      throw new SSLException("message decode failed");

    appBuffer.clear();
    enc.encode(CharBuffer.wrap(msg), appBuffer, true);
View Full Code Here

    appBuffer.clear();
    result = clientEngine.unwrap(snetBuffer, appBuffer);
    if (result.getStatus() != Status.OK)
      throw new SSLException("unexpected status: " + result.getStatus());
    appBuffer.flip();
    msg = cs.decode(appBuffer).toString();
    if (!msg.equals(TEST_MESSAGE))
      throw new SSLException("message decode (2) failed");
  }
}
View Full Code Here

    **/
    protected static CharBuffer getXMPChars(ByteBuffer xmpBytes){
        CharBuffer result = null;
        if(xmpBytes != null){
            Charset utf8 = Charset.forName("utf-8");
            result = utf8.decode(xmpBytes);
        }
        return(result);
    }


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

        if (start >= 0 && 0 <= length && length <= data.length - start) {
            offset = 0;
            Charset charset = getCharset(encoding);

            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 = encodingToCharset.get(encoding);
      if (charset == null) {
        charset = Charset.forName(encoding);
        encodingToCharset.put(encoding, charset);
      }
      responseString = charset.decode(ByteBuffer.wrap(responseBytes)).toString();

      // Strip BOM if present
      if (responseString.length() > 0 && responseString.codePointAt(0) == 0xFEFF) {
        responseString = responseString.substring(1);
      }
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.