Package java.nio

Examples of java.nio.CharBuffer.array()


                //             is longer in length than the number of characters
                //             decoded. Hence, the check below to ensure the
                //             char[] returned contains all the chars that have
                //             been decoded and no more.
                if (charBuf.limit() == charBuf.capacity()) {
                    buffer = charBuf.array();
                } else {
                    buffer = new char[charBuf.limit()];
                    charBuf.get(buffer, 0, charBuf.limit()).position(0);
                }
View Full Code Here


                        charBuffer = decoder.decode(buf);
                    } catch (CharacterCodingException e) {
                        throw Utils.asRuntime(e);
                    }
                    buf.limit(buf.capacity());
                    String s = new String(charBuffer.array(), charBuffer.arrayOffset(), charBuffer.limit());
                    buf.position(0);
                    return s;
                } else {
                    return "";
                }
View Full Code Here

        // new String(byte[], int, int, Charset) takes a defensive copy of the
        // entire byte array. This is expensive if only a small subset of the
        // bytes will be used. The code below is from Apache Harmony.
        CharBuffer cb;
        cb = charset.decode(ByteBuffer.wrap(buff, start, end-start));
        return new String(cb.array(), cb.arrayOffset(), cb.length());
    }

    /**
     * @deprecated Unused. Will be removed in Tomcat 8.0.x onwards.
     */
 
View Full Code Here

          logger.debug("read {} characters", buffer.remaining());

          counterGroup.addAndGet("characters.received",
              Long.valueOf(buffer.limit()));

          builder.append(buffer.array(), buffer.position(), buffer.length());
        }

        if (builder.charAt(builder.length() - 1) == '\n') {
          builder.deleteCharAt(builder.length() - 1);
        }
View Full Code Here

    ByteBuffer in = ByteBuffer.wrap(getUnibytes());
    out = decoder.decode(in);
    assertEquals(out.position(), 0);
    assertEquals(out.limit(), unistr.length());
    assertEquals(out.remaining(), unistr.length());
    assertEquals(new String(out.array(), 0, out.limit()), unistr);
  }

  public void testDecodeByteBufferException()
      throws CharacterCodingException, UnsupportedEncodingException {
    CharBuffer out;
View Full Code Here

    decoder.reset();
    in = ByteBuffer.wrap(getUnibytes());
    out.rewind();
    assertSame(CoderResult.OVERFLOW, decoder.decode(in, out, false));

    assertEquals(new String(out.array()), unistr.substring(0, 4));
    out = CharBuffer.allocate(100);
    assertSame(CoderResult.UNDERFLOW, decoder.decode(in, out, false));
    assertCharBufferValue(out, unistr.substring(4));
    in.rewind();
    out = CharBuffer.allocate(100);
View Full Code Here

            Charset charset = defaultCharset();
            int result;
            CharBuffer cb = charset
                    .decode(ByteBuffer.wrap(data, start, length));
            if ((result = cb.length()) > 0) {
                value = cb.array();
                count = result;
            } else {
                count = 0;
                value = new char[0];
            }
View Full Code Here

              // do nothing. according to spec:
              // behavior is unspecified for invalid array
              cb = CharBuffer.wrap("\u003f".toCharArray()); //$NON-NLS-1$
            }
            if ((result = cb.length()) > 0) {
                value = cb.array();
                count = result;
            } else {
                count = 0;
                value = new char[0];
            }
View Full Code Here

            CharsetDecoder decoder = charset.newDecoder();
            CharBuffer decodedBuffer = decoder.decode(
                    ByteBuffer.wrap(_byteArrayOutputStream.getInnerArray(),
                            0,_byteArrayOutputStream.getInnerCount()));
            if (decodedBuffer.hasArray()){
                out.write(decodedBuffer.array());
            }
        }

        public void reset()
        {
View Full Code Here

            this(bytes, Charset.forName(charset));
        }

        public ByteArrayCodepointIterator(byte[] bytes, Charset charset) {
            CharBuffer cb = charset.decode(ByteBuffer.wrap(bytes));
            buffer = cb.array();
            position = cb.position();
            limit = cb.limit();
        }
    }
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.