Package java.nio

Examples of java.nio.ByteBuffer.rewind()


      int length = (int) file.length();
      // int segment_size = 1024 * 4096;
      // ByteBuffer buf = ByteBuffer.allocate(segment_size);
      ByteBuffer buf = getByteBuffer(nio_segment_size);
      // byte bytes[] = new byte[segment_size];
      buf.rewind();

      int numRead = 0;
      int total = 0;
      while ((numRead >= 0) && (total < length))
      {
View Full Code Here


        }
        total += numRead;
        // System.out.println("numRead: " + numRead + " total: " +
        // total);

        buf.rewind();
      }

      // return buf.array();
      return result;
    } catch (Exception e)
View Full Code Here

      ByteBuffer buf = getByteBuffer(nio_segment_size);

      int index = 0;
      while (index < src.length)
      {
        buf.rewind();
        int remaining = src.length - index;
        int size = Math.min(nio_segment_size, remaining);
        if (size != buf.capacity())
        {
          // System.out.println("reallocating segment_size: " +
View Full Code Here

              actualBuffer.position(2);
              actualBuffer = actualBuffer.slice();
            }

            ByteBuffer expectedBuffer = encodedBlocks.get(blockId);
            expectedBuffer.rewind();

            // test if content matches, produce nice message
            assertBuffersEqual(expectedBuffer, actualBuffer, algo, encoding,
                pread);
          }
View Full Code Here

    final int rawBlockSize = writeTestKeyValues(doubleOutputStream,
        blockId, includesMemstoreTS);

    ByteBuffer rawBuf = ByteBuffer.wrap(baos.toByteArray());
    rawBuf.rewind();

    final int encodedSize;
    final ByteBuffer encodedBuf;
    if (encoding == DataBlockEncoding.NONE) {
      encodedSize = rawBlockSize;
View Full Code Here

              actualBuffer.position(2);
              actualBuffer = actualBuffer.slice();
            }

            ByteBuffer expectedBuffer = encodedBlocks.get(blockId);
            expectedBuffer.rewind();

            // test if content matches, produce nice message
            TestHFileBlock.assertBuffersEqual(expectedBuffer, actualBuffer, algo, encoding,
                pread);
          }
View Full Code Here

        this.delimiter = delimiter;

        // Convert delimiter to ByteBuffer if not done yet.
        if (delimBuf == null) {
            ByteBuffer tmp = charset.encode(CharBuffer.wrap(delimiter.getValue()));
            tmp.rewind();
            delimBuf = tmp;
        }
    }

    /**
 
View Full Code Here

        for (T object : getObjects()) {
            int size = encoder.getEncodedSize(object);
            ByteBuffer out = ByteBuffer.allocate(size);
            encoder.writeTo(object, out);           
            assertEquals(size, out.position());
            out.rewind();
            assertEquals(object, decoder.decode(IoBuffer.wrap(out)));
        }
    }
}
View Full Code Here

    public void verifyThatHeaderWithoutLeadingSpaceIsSupported() throws UnsupportedEncodingException,
            ProtocolDecoderException {
        String reqStr = "GET / HTTP/1.0\r\nHost:localhost\r\n\r\n";
        ByteBuffer buffer = ByteBuffer.allocate(reqStr.length());
        buffer.put(reqStr.getBytes("US-ASCII"));
        buffer.rewind();
        HttpServerDecoder decoder = new HttpServerDecoder();
        HttpDecoderState state = decoder.createDecoderState();
        HttpPdu pdus = decoder.decode(buffer, state);
        assertNotNull(pdus);
View Full Code Here

    public void verifyThatLeadingSpacesAreRemovedFromHeader() throws UnsupportedEncodingException,
            ProtocolDecoderException {
        String reqStr = "GET / HTTP/1.0\r\nHost:  localhost\r\n\r\n";
        ByteBuffer buffer = ByteBuffer.allocate(reqStr.length());
        buffer.put(reqStr.getBytes("US-ASCII"));
        buffer.rewind();
        HttpServerDecoder decoder = new HttpServerDecoder();
        HttpDecoderState state = decoder.createDecoderState();
        HttpPdu pdus = decoder.decode(buffer, state);
        assertNotNull(pdus);
        assertEquals("localhost", ((HttpRequestImpl) pdus).getHeader("host"));
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.