Package java.nio.charset

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


            Charset charset = Charset.forName("UTF-8");
            byte[] bytes = new byte[str.length()];
            //we have to use a deprecated method because it's the only one that works.
            str.getBytes(0, str.length(), bytes, 0);
            ByteBuffer bb = ByteBuffer.wrap(bytes);
            value = (T) charset.decode(bb).toString();
        }
        return value;
    }

    public boolean isDecodeUTF8() {
View Full Code Here


        FileInputStream stream = new FileInputStream(file);
        try  {
            FileChannel channel = stream.getChannel();
            try {
                MappedByteBuffer map = channel.map(MapMode.READ_ONLY, 0, channel.size());
                CharBuffer chars = charset.decode(map);
                Matcher matcher = pattern.matcher(chars);
                asserter.makeAssertions(matcher);
            } finally {
                channel.close();
            }
View Full Code Here

    }

    public static String convert(byte[] data, int offset, int length) {
        Charset ch = Charset.forName("utf-8");
        ByteBuffer buff = ByteBuffer.wrap(data, offset, length);
        return ch.decode(buff).toString();
    }

    public static String convert(ByteBuffer value) {
        Charset ch = Charset.forName("utf-8");
        return ch.decode(value).toString();
View Full Code Here

        return ch.decode(buff).toString();
    }

    public static String convert(ByteBuffer value) {
        Charset ch = Charset.forName("utf-8");
        return ch.decode(value).toString();
    }

    public static String prepareWordForIndex(String word) {
        word = reduceCharacterDiversityLevel2(word);
        return new String(addSpaces(word));
View Full Code Here

    *
    * @return this returns the bytes sequence as a string object
    */
   private String encode(String encoding, ByteBuffer segment) throws IOException {
      Charset charset = Charset.forName(encoding);
      CharBuffer text = charset.decode(segment);

      return text.toString();
   }

   /**
 
View Full Code Here

    *
    * @return this returns the bytes sequence as a string object
    */  
   private String encode(String encoding, ByteBuffer buffer) throws IOException {
      Charset charset = Charset.forName(encoding);
      CharBuffer text = charset.decode(buffer);

      return text.toString();
   }

   /**
 
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

      cs = Charset.defaultCharset();
    }else {
      cs = Charset.forName(charset);
    }
   
    return cs.decode(data).toString();
  }
 
  /**
   * 字符串转换为byteBuffer
   * @param str 字符串
View Full Code Here

  public String readMultiByte(int length, String charSet) {
    final Charset cs = Charset.forName(charSet);
    int limit = buffer.limit();
    final java.nio.ByteBuffer strBuf = buffer.buf();
    strBuf.limit(strBuf.position() + length);
    final String string = cs.decode(strBuf).toString();
    buffer.limit(limit); // Reset the limit
    return string;
  }

  /** {@inheritDoc} */
 
View Full Code Here

  }

  public static String bytesToString(final byte[] bytes) {
    Charset charset = new CharsetToolkit(bytes, getIDEOptionsCharset()).guessEncoding(bytes.length);
    int bomLength = getBOMLength(bytes, charset);
    final CharBuffer charBuffer = charset.decode(ByteBuffer.wrap(bytes, bomLength, bytes.length - bomLength));
    return charBuffer.toString();
  }

  public enum GuessedEncoding {
    SEVEN_BIT,
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.