Package java.nio

Examples of java.nio.CharBuffer.rewind()


    while ((read = reader.read(buffer)) > 0) {
      buffer.rewind();
      for (; read > 0; read--) {
        sb.append(buffer.get());
      }
      buffer.rewind();
    }

    Message msg = createCommandMessage(sessionProvider.getSession(request.getSession(),
        request.getHeader(REMOTE_QUEUE_ID_HEADER)), request, sb.toString());
    if (msg != null) {
View Full Code Here


    public static void copy(Reader reader, boolean closeIn, Appendable out) throws IOException {
        try {
            CharBuffer buffer = CharBuffer.allocate(4096);
            while (reader.read(buffer) > 0) {
                buffer.flip();
                buffer.rewind();
                out.append(buffer);
            }
        } finally {
            if (closeIn) IOUtils.closeQuietly(reader);
        }
View Full Code Here

            int size = reader.read(cbuf);
            if (size <= 0) {
                break;
            }
            cbuf.limit(cbuf.position());
            cbuf.rewind();
            boolean eof = false;
            while (!eof) {
                CoderResult cr = encoder.encode(cbuf, bbuf, eof);
                if (cr.isError()) {
                    cr.throwException();
View Full Code Here

     * Give an RTF hex string of a character in a given character set.
     */
     private String getHexString(char c, Charset charset) {
         CharBuffer cb = CharBuffer.allocate(1);
         cb.put(c);
         cb.rewind();
         ByteBuffer bb = charset.encode(cb);
         byte b = bb.get();       
      int byteInt = new Byte(b).intValue();
      if (byteInt<0) byteInt += 256;
      String hexString = "\\'"+ Integer.toHexString(byteInt);
View Full Code Here

     */
    protected static String[] parseImportDeclarations(Reader r) throws IOException {
        final CharBuffer cb = CharBuffer.allocate(10000);
        r.mark(cb.limit());
        r.read(cb);
        cb.rewind();

        List<String> imports = new ArrayList<String>();
        int afterLastImport = 0;
        for (Matcher matcher = IMPORT_STATEMENT_PATTERN.matcher(cb); matcher.find();) {
            imports.add(matcher.group(1));
View Full Code Here

      while (cb.hasRemaining()) {
        tmpcb.put (cb.get());
      }

      tmpcb.rewind();

      baseEncoder.reset();

      for (int pos = tmpcb.position(); pos < tmpcb.limit(); pos++) {
        char c = tmpcb.get (pos);
View Full Code Here

        CharBuffer charBuffer = CharBuffer.allocate(CHARBUFFER_SIZE);
        charBuffer.append('A');
        final int CHARBUFFER_REMAINING = charBuffer.remaining();
        int result = mockReader.read(charBuffer);
        assertEquals(CHARBUFFER_REMAINING, result);
        charBuffer.rewind();
        assertEquals(s.substring(0, CHARBUFFER_REMAINING), charBuffer
                .subSequence(CHARBUFFER_SIZE - CHARBUFFER_REMAINING,
                        CHARBUFFER_SIZE).toString());
        char[] destBuffer = new char[srcBuffer.length - CHARBUFFER_REMAINING];
        mockReader.read(destBuffer);
View Full Code Here

    }

    // normal case, one complete operation
    decoder.reset();
    in.rewind();
    out.rewind();
    assertSame(CoderResult.UNDERFLOW, decoder.decode(in, out, true));
    assertEquals(out.limit(), 100);
    assertEquals(out.position(), unistr.length());
    assertEquals(out.remaining(), 100 - unistr.length());
    assertEquals(out.capacity(), 100);
View Full Code Here

    // overflow
    out = CharBuffer.allocate(4);
    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));
View Full Code Here

    ByteBuffer in = ByteBuffer.wrap(new byte[] { 12, 12 });
    decoder.decode(in, out, true);
    assertSame(CoderResult.UNDERFLOW, decoder.flush(out));

    decoder.reset();
    decoder.decode((ByteBuffer) in.rewind(), (CharBuffer) out.rewind(),
        true);
    assertSame(CoderResult.UNDERFLOW, decoder
        .flush(CharBuffer.allocate(10)));
  }
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.