Examples of onMalformedInput()


Examples of java.nio.charset.CharsetDecoder.onMalformedInput()

        if (ignoreEncodingErrors)
            action = CodingErrorAction.REPLACE;
        else
            action = CodingErrorAction.REPORT;

        return decoder
            .onMalformedInput(action)
            .onUnmappableCharacter(action);
    }
    // </editor-fold>
View Full Code Here

Examples of java.nio.charset.CharsetDecoder.onMalformedInput()

        Map<Charset, CharsetDecoder> map = decoders.get();
        CharsetDecoder d = map.get(charset);
        if (d != null) {
            d.reset();
            d.onMalformedInput(CodingErrorAction.REPLACE);
            d.onUnmappableCharacter(CodingErrorAction.REPLACE);
            return d;
        }

        d = charset.newDecoder();
View Full Code Here

Examples of java.nio.charset.CharsetDecoder.onMalformedInput()

            d.onUnmappableCharacter(CodingErrorAction.REPLACE);
            return d;
        }

        d = charset.newDecoder();
        d.onMalformedInput(CodingErrorAction.REPLACE);
        d.onUnmappableCharacter(CodingErrorAction.REPLACE);
        map.put(charset, d);
        return d;
    }
}
View Full Code Here

Examples of java.nio.charset.CharsetDecoder.onMalformedInput()

        {
            return null;
        }

        CharsetDecoder decoder = Charset.forName(encoding).newDecoder();
        decoder.onMalformedInput(CodingErrorAction.REPORT);
        decoder.onUnmappableCharacter(CodingErrorAction.REPORT);

        int len = path.length();
        ByteBuffer buf = ByteBuffer.allocate(len);
        StringBuilder sb = new StringBuilder();
View Full Code Here

Examples of java.nio.charset.CharsetDecoder.onMalformedInput()

  }

  private String tryDecodeAsString(byte[] data) {
    try {
      CharsetDecoder decoder = Utf8.CHARSET.newDecoder();
      decoder.onMalformedInput(CodingErrorAction.REPORT);
      decoder.onUnmappableCharacter(CodingErrorAction.REPORT);

      ByteBuffer byteBuffer = ByteBuffer.wrap(data);
      CharBuffer charBuffer = decoder.decode(byteBuffer);
      return charBuffer.toString();
View Full Code Here

Examples of java.nio.charset.CharsetDecoder.onMalformedInput()

  private String tryDecodeAsString(byte[] data) {
    try {
      // We do this so we get strict input processing
      CharsetDecoder decoder = Charsets.UTF_8.newDecoder();
      decoder.onMalformedInput(CodingErrorAction.REPORT);
      decoder.onUnmappableCharacter(CodingErrorAction.REPORT);

      ByteBuffer byteBuffer = ByteBuffer.wrap(data);
      CharBuffer charBuffer = decoder.decode(byteBuffer);
      return charBuffer.toString();
View Full Code Here

Examples of java.nio.charset.CharsetDecoder.onMalformedInput()

            if (looksLikeAscii(bytes)) {
                final Charset[] css = { Charsets.UTF_8, Charsets.ISO_8859_1 };
                final Charset[] tryCharsets = css;
                for (final Charset cset : tryCharsets) {
                    final CharsetDecoder cd = cset.newDecoder();
                    cd.onMalformedInput(CodingErrorAction.REPORT);
                    cd.onUnmappableCharacter(CodingErrorAction.REPORT);
                    try {
                        cb = cd.decode(ByteBuffer.wrap(bytes));
                        break;
                    } catch (final CharacterCodingException e) {
View Full Code Here

Examples of java.nio.charset.CharsetDecoder.onMalformedInput()

                new byte[] { -32, -96 }), Charset.forName("UTF-8"));
        assertEquals("read() return incorrect value", 65533, isr2.read());
       
        // if the decoder is passed in, keep its status intacted
        CharsetDecoder decoder = Charset.forName("UTF-8").newDecoder();
        decoder.onMalformedInput(CodingErrorAction.REPORT);
        InputStreamReader isr3 = new InputStreamReader(new ByteArrayInputStream(
                new byte[] { -32, -96 }), decoder);
        try{
           isr3.read();
           fail("Should throw MalformedInputException");
View Full Code Here

Examples of java.nio.charset.CharsetDecoder.onMalformedInput()

        }catch(MalformedInputException e){
            //expected
        }
       
        CharsetDecoder decoder2 = Charset.forName("UTF-8").newDecoder();
        decoder2.onMalformedInput(CodingErrorAction.IGNORE);
        InputStreamReader isr4 = new InputStreamReader(new ByteArrayInputStream(
                new byte[] { -32, -96 }), decoder2);
        assertEquals("read() return incorrect value", -1, isr4.read());
       
        CharsetDecoder decoder3 = Charset.forName("UTF-8").newDecoder();
View Full Code Here

Examples of java.nio.charset.CharsetDecoder.onMalformedInput()

        InputStreamReader isr4 = new InputStreamReader(new ByteArrayInputStream(
                new byte[] { -32, -96 }), decoder2);
        assertEquals("read() return incorrect value", -1, isr4.read());
       
        CharsetDecoder decoder3 = Charset.forName("UTF-8").newDecoder();
        decoder3.onMalformedInput(CodingErrorAction.REPLACE);
        InputStreamReader isr5 = new InputStreamReader(new ByteArrayInputStream(
                new byte[] { -32, -96 }), decoder3);
        assertEquals("read() return incorrect value", 65533, isr5.read());
    }
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.