Package java.nio.charset

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


            try
            {
                bbuf = ByteBuffer.wrap( out.toByteArray() );

                CharBuffer cbuf = l1decoder.decode( bbuf );

                return cbuf.toString();
            }
            catch( CharacterCodingException ex )
            {
View Full Code Here


            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();
        } catch (Exception e) {
            log.debug("Cannot decode as string", e);
            return null;
        }
View Full Code Here

     */
    protected void collectIncomingData(ByteBuffer data) {
        Charset charset=Charset.forName("ISO-8859-1");
        CharsetDecoder decoder = charset.newDecoder();
        try {
            CharBuffer charBuffer = decoder.decode(data);
            System.out.print(charBuffer.array());
        } catch (CharacterCodingException cce) {
            System.out.println("Exception collection data");
            cce.printStackTrace();
        }
View Full Code Here

     */
    protected void collectIncomingData(ByteBuffer data) {
        Charset charset=Charset.forName("ISO-8859-1");
        CharsetDecoder decoder = charset.newDecoder();
        try {
            CharBuffer charBuffer = decoder.decode(data);
            System.out.print(charBuffer.array());
        } catch (CharacterCodingException cce) {
            System.out.println("Exception collection data");
            cce.printStackTrace();
        }
View Full Code Here

            return safeTrim(ca, clen, cs, isTrusted);
        } else {
            ByteBuffer bb = ByteBuffer.wrap(ba, off, len);
            CharBuffer cb = CharBuffer.wrap(ca);
            try {
                CoderResult cr = cd.decode(bb, cb, true);
                if (!cr.isUnderflow())
                    cr.throwException();
                cr = cd.flush(cb);
                if (!cr.isUnderflow())
                    cr.throwException();
View Full Code Here

        char[] ca = new char[len];
        if (len == 0)
            return new String(ca);
        ByteBuffer bb = ByteBuffer.wrap(ba, 0, length);
        CharBuffer cb = CharBuffer.wrap(ca);
        CoderResult cr = cd.decode(bb, cb, true);
        if (!cr.isUnderflow())
            throw new IllegalArgumentException(cr.toString());
        cr = cd.flush(cb);
        if (!cr.isUnderflow())
            throw new IllegalArgumentException(cr.toString());
View Full Code Here

        }

        CharsetDecoder decoder = charSet.newDecoder();
        CharBuffer charBuffer = null;
        try {
            charBuffer = decoder.decode(byteBuffer);
        } catch(CharacterCodingException cce) {
            throw cce;
        } catch(Throwable t) {
            CharacterCodingException e = new CharacterCodingException();
            e.initCause(t);
View Full Code Here

                throw new IllegalArgumentException("MALFORMED");
            return new String(ca, 0, clen);
        }
        ByteBuffer bb = ByteBuffer.wrap(ba, 0, length);
        CharBuffer cb = CharBuffer.wrap(ca);
        CoderResult cr = cd.decode(bb, cb, true);
        if (!cr.isUnderflow())
            throw new IllegalArgumentException(cr.toString());
        cr = cd.flush(cb);
        if (!cr.isUnderflow())
            throw new IllegalArgumentException(cr.toString());
View Full Code Here

  private static String decode(final ByteBuffer b, final Charset charset)
      throws CharacterCodingException {
    final CharsetDecoder d = charset.newDecoder();
    d.onMalformedInput(CodingErrorAction.REPORT);
    d.onUnmappableCharacter(CodingErrorAction.REPORT);
    return d.decode(b).toString();
  }

  /**
   * Locate the position of the commit message body.
   *
 
View Full Code Here

    int numEvents = 0;
    while (fileReader.hasNext()) {
      fileReader.next(record);
      ByteBuffer body = (ByteBuffer) record.get("body");
      CharsetDecoder decoder = Charsets.UTF_8.newDecoder();
      String bodyStr = decoder.decode(body).toString();
      System.out.println(bodyStr);
      numEvents++;
    }
    fileReader.close();
    Assert.assertEquals("Should have found a total of 3 events", 3, numEvents);
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.