Package java.nio.charset

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


      // This test is turning random bytes into a string,
      // this is asking for trouble.
      CharsetDecoder decoder = IOUtils.CHARSET_UTF_8.newDecoder()
          .onUnmappableCharacter(CodingErrorAction.REPLACE)
          .onMalformedInput(CodingErrorAction.REPLACE);
      String s = decoder.decode(ByteBuffer.wrap(buffer, 0, size)).toString();
      for (int j = 0; j < s.length(); j++) {
        array.append(s.charAt(j));
      }
      builder.append(s);
    }
View Full Code Here


      // This test is turning random bytes into a string,
      // this is asking for trouble.
      CharsetDecoder decoder = IOUtils.CHARSET_UTF_8.newDecoder()
          .onUnmappableCharacter(CodingErrorAction.REPLACE)
          .onMalformedInput(CodingErrorAction.REPLACE);
      uniqueValues[i] = decoder.decode(ByteBuffer.wrap(buffer, 0, size)).toString();
      // we cannot have empty path components, so eliminate all prefix as well
      // as middle consecutive delimiter chars.
      uniqueValues[i] = uniqueValues[i].replaceAll("/+", "/");
      if (uniqueValues[i].startsWith("/")) {
        uniqueValues[i] = uniqueValues[i].substring(1);
View Full Code Here

    }
    ByteBuffer partToDecode = in.slice();
    partToDecode.limit(length);
    CharBuffer cb;
    try {
      cb = decoder.decode(partToDecode);
      in.position(in.position() + length);
    } catch (CharacterCodingException e) {
      // should never happen
      throw new RuntimeException(e);
    }
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

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

    static String decodeString(ByteBuffer src, Charset charset) {
        final CharsetDecoder decoder = CharsetUtil.getDecoder(charset);
        final CharBuffer dst = CharBuffer.allocate(
                (int) ((double) src.remaining() * decoder.maxCharsPerByte()));
        try {
            CoderResult cr = decoder.decode(src, dst, true);
            if (!cr.isUnderflow()) {
                cr.throwException();
            }
            cr = decoder.flush(dst);
            if (!cr.isUnderflow()) {
View Full Code Here

                           if (sindex > 0 && eindex > sindex)
                               vector.add("Issue "  +  ssc.getCommentData().substring(sindex + 2,eindex));
                           else {
                               if (decoder != null) {
                                    try {
                                        vector.add(decoder.decode(ByteBuffer.wrap(ssc.getCommentData().getBytes())).toString());
                                    } catch (CharacterCodingException ex) {
                                        // let's not give up insert the comment data as is
                                        vector.add(ssc.getCommentData());
                                    }
                               } else {
View Full Code Here

                               }
                           }
                       } else {
                           if (decoder != null) {
                                try {
                                    vector.add(decoder.decode(ByteBuffer.wrap(ssc.getCommentData().getBytes())).toString());
                                } catch (CharacterCodingException ex) {
                                    // let's not give up insert the comment data as is
                                    vector.add(ssc.getCommentData());
                                }
                           } else {
View Full Code Here

                       if (sindex > 0 && eindex > sindex)
                           vector.add("Issue "  +  shc.getCommentData().substring(sindex + 2,eindex));
                       else {
                           if (decoder != null) {
                               try {
                                   vector.add(decoder.decode(ByteBuffer.wrap(shc.getCommentData().getBytes())).toString());
                               } catch (CharacterCodingException ex) {
                                   // let's not give up insert the comment data as is
                                   vector.add(shc.getCommentData());
                               }
                           } else {
View Full Code Here

                           }
                       }
                   } else {
                        if (decoder != null) {
                                try {
                                    vector.add(decoder.decode(ByteBuffer.wrap(shc.getCommentData().getBytes())).toString());
                                } catch (CharacterCodingException ex) {
                                    // let's not give up insert the comment data as is
                                    vector.add(shc.getCommentData());
                                }
                           } else {
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.