Package java.nio.charset

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


        final CodingErrorAction malformedInputAction = cconfig.getMalformedInputAction() != null ?
                cconfig.getMalformedInputAction() : CodingErrorAction.REPORT;
        final CodingErrorAction unmappableInputAction = cconfig.getUnmappableInputAction() != null ?
                cconfig.getUnmappableInputAction() : CodingErrorAction.REPORT;
        if (charset != null) {
            chardecoder = charset.newDecoder();
            chardecoder.onMalformedInput(malformedInputAction);
            chardecoder.onUnmappableCharacter(unmappableInputAction);
            charencoder = charset.newEncoder();
            charencoder.onMalformedInput(malformedInputAction);
            charencoder.onUnmappableCharacter(unmappableInputAction);
View Full Code Here


   */
  public void setCharacterEncoding(String char_encoding) {
    this.char_encoding_ = char_encoding;
    if (this.char_encoding_ != null) {
      Charset charset = Charset.forName(char_encoding_);
      this.char_decoder_ = charset.newDecoder();
      this.char_encoder_ = charset.newEncoder();
      char_decoder_.onMalformedInput(CodingErrorAction.IGNORE);
      char_decoder_.onUnmappableCharacter(CodingErrorAction.IGNORE);

      ByteBuffer replacement = charset.encode(BAD_INPUT_REPLACEMENT);
View Full Code Here

   */
  public void setCharacterEncoding(String char_encoding) {
    this.char_encoding_ = char_encoding;
    if (this.char_encoding_ != null) {
      Charset charset = Charset.forName(char_encoding_);
      this.char_decoder_ = charset.newDecoder();
      this.char_encoder_ = charset.newEncoder();
      char_decoder_.onMalformedInput(CodingErrorAction.IGNORE);
      char_decoder_.onUnmappableCharacter(CodingErrorAction.IGNORE);

      ByteBuffer replacement = charset.encode(BAD_INPUT_REPLACEMENT);
View Full Code Here

           
            conn.disconnect();
            is.close();
            Charset charset = Charset.forName("UTF-8");
           
            CharsetDecoder decoder = charset.newDecoder()
            .onMalformedInput(CodingErrorAction.REPLACE)
            .onUnmappableCharacter(CodingErrorAction.REPLACE);
           
            ByteBuffer bb = ByteBuffer.wrap(os.toByteArray());
            String result = decoder.decode(bb).toString();
View Full Code Here

    s = s.replace("\u03c7", "chi");
    s = s.replace("\u03c8", "psi");
    s = s.replace("\u03c9", "omega");
   
    Charset charset = Charset.forName("ISO-8859-1");
      CharsetDecoder decoder = charset.newDecoder();
      CharsetEncoder encoder = charset.newEncoder();     
      try {
          ByteBuffer bbuf = encoder.encode(CharBuffer.wrap(s));
          CharBuffer cbuf = decoder.decode(bbuf);
          return cbuf.toString();
View Full Code Here

        private void writeTo(Writer out, String encoding) throws IOException{
            //Get the charset based on the encoding or return the default if
            //encoding == null
            Charset charset = (encoding == null) ?
                    Charset.defaultCharset() : Charset.forName(encoding);
            CharsetDecoder decoder = charset.newDecoder();
            CharBuffer decodedBuffer = decoder.decode(
                    ByteBuffer.wrap(_byteArrayOutputStream.getInnerArray(),
                            0,_byteArrayOutputStream.getInnerCount()));
            if (decodedBuffer.hasArray()){
                out.write(decodedBuffer.array());
View Full Code Here

        Charset charset = Charset.forName("UTF-8");
        buf.clear();
        buf.putString("hello", charset.newEncoder());
        buf.put((byte) 0);
        buf.flip();
        Assert.assertEquals("hello", buf.getString(charset.newDecoder()));

        buf.clear();
        buf.putString("hello", charset.newEncoder());
        buf.flip();
        Assert.assertEquals("hello", buf.getString(charset.newDecoder()));
View Full Code Here

        Assert.assertEquals("hello", buf.getString(charset.newDecoder()));

        buf.clear();
        buf.putString("hello", charset.newEncoder());
        buf.flip();
        Assert.assertEquals("hello", buf.getString(charset.newDecoder()));

        decoder = Charset.forName("ISO-8859-1").newDecoder();
        buf.clear();
        buf.put((byte) 'A');
        buf.put((byte) 'B');
View Full Code Here

        Charset charset = Charset.forName( "UTF-8" );
        buf.clear();
        buf.putString( "hello", charset.newEncoder() );
        buf.put( (byte)0 );
        buf.flip();
        Assert.assertEquals( "hello", buf.getString( charset.newDecoder() ) );

        buf.clear();
        buf.putString( "hello", charset.newEncoder() );
        buf.flip();
        Assert.assertEquals( "hello", buf.getString( charset.newDecoder() ) );
View Full Code Here

        Assert.assertEquals( "hello", buf.getString( charset.newDecoder() ) );

        buf.clear();
        buf.putString( "hello", charset.newEncoder() );
        buf.flip();
        Assert.assertEquals( "hello", buf.getString( charset.newDecoder() ) );

        decoder = Charset.forName( "ISO-8859-1" ).newDecoder();
        buf.clear();
        buf.put( (byte) 'A' );
        buf.put( (byte) 'B' );
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.