Example usage for java.nio ByteBuffer limit

List of usage examples for java.nio ByteBuffer limit

Introduction

In this page you can find the example usage for java.nio ByteBuffer limit.

Prototype

public final int limit() 

Source Link

Document

Returns the limit of this buffer.

Usage

From source file:org.apache.solr.handler.TestBlobHandler.java

private void compareInputAndOutput(String url, byte[] bytarr) throws IOException {

    HttpClient httpClient = cloudClient.getLbClient().getHttpClient();

    HttpGet httpGet = new HttpGet(url);
    HttpResponse entity = httpClient.execute(httpGet);
    ByteBuffer b = SimplePostTool.inputStreamToByteArray(entity.getEntity().getContent());
    try {/*ww w  .ja va  2s .  co  m*/
        assertEquals(b.limit(), bytarr.length);
        for (int i = 0; i < bytarr.length; i++) {
            assertEquals(b.get(i), bytarr[i]);
        }
    } finally {
        httpGet.releaseConnection();
    }

}

From source file:org.docx4j.openpackaging.parts.WordprocessingML.BinaryPart.java

public byte[] getBytes() {

    ByteBuffer bb = this.getBuffer();
    bb.rewind();//  ww w  .  jav  a2 s.  co  m

    byte[] bytes = new byte[bb.limit()];
    bb.get(bytes, 0, bytes.length);
    bb.rewind();

    return bytes;
}

From source file:net.phoenix.thrift.hello.SpringHelloService.java

@Override
public ByteBuffer hello(ByteBuffer hello_request) throws TException {
    HelloRequest request;//  w ww.  j a va2 s  .com
    try {
        request = HelloRequest.parseFrom(
                ArrayUtils.subarray(hello_request.array(), hello_request.position(), hello_request.limit()));
    } catch (InvalidProtocolBufferException e) {
        throw new TException(e);
    }
    HelloResponse.Builder response = HelloResponse.newBuilder();
    response.setMessage("Hello " + request.getName());
    return ByteBuffer.wrap(response.build().toByteArray());
}

From source file:jnative.io.AIO.java

private ByteBuffer getDirect(ByteBuffer buf) {
    if (buf instanceof DirectBuffer)
        return buf;

    int pos = buf.position();
    int lim = buf.limit();
    assert (pos <= lim);
    int rem = (pos <= lim ? lim - pos : 0);
    ByteBuffer bb = ByteBuffer.allocate(rem);
    bb.put(buf);/* w w  w  . j  a v a  2s  .  c o  m*/
    bb.flip();
    return bb;
}

From source file:net.phoenix.thrift.hello.ThreadPoolTest.java

@Test
public void testByteBuffer() throws TException, IOException, InterruptedException {
    LOG.info("Client starting....");
    String name = "Hello ";
    // TTransport transport = new TNonblockingSocket("localhost", 9804);
    TTransport transport = new TSocket("localhost", 9804);
    transport.open();//from  w  w w  .  j  a  v a2 s .c  o m
    // TTransport transport = new TTransport(socket);
    TProtocol protocol = new TBinaryProtocol(transport);
    HelloService.Client client = new HelloService.Client(protocol);
    try {

        // System.out.println("start request. ");
        Hello.HelloRequest.Builder request = Hello.HelloRequest.newBuilder();
        request.setName(name);
        Hello.User.Builder user = Hello.User.newBuilder();
        user.setName("hello");
        user.setPassword("hello");
        request.setUser(user.build());
        ByteBuffer requestBuffer = ByteBuffer.wrap(request.build().toByteArray());
        ByteBuffer buffer = client.hello(requestBuffer);
        Hello.HelloResponse response = Hello.HelloResponse
                .parseFrom(ArrayUtils.subarray(buffer.array(), buffer.position(), buffer.limit()));
        String message = response.getMessage();
        assertEquals(message, "Hello " + name);
        // System.out.println(message);
    } finally {
        transport.close();
    }
}

From source file:org.apache.hadoop.hive.serde2.compression.TestSnappyCompDe.java

@Test
public void testBinaryCol() {
    ColumnBuffer[] inputCols = new ColumnBuffer[] { columnBinary };

    ByteBuffer compressed = compDe.compress(inputCols);
    ColumnBuffer[] outputCols = compDe.decompress(compressed, compressed.limit());

    assertArrayEquals(inputCols[0].toTColumn().getBinaryVal().getValues().toArray(),
            outputCols[0].toTColumn().getBinaryVal().getValues().toArray());
}

From source file:org.apache.hadoop.hive.serde2.compression.TestSnappyCompDe.java

@Test
public void testBoolCol() {
    ColumnBuffer[] inputCols = new ColumnBuffer[] { columnBool };

    ByteBuffer compressed = compDe.compress(inputCols);
    ColumnBuffer[] outputCols = compDe.decompress(compressed, compressed.limit());

    assertArrayEquals(inputCols[0].toTColumn().getBoolVal().getValues().toArray(),
            outputCols[0].toTColumn().getBoolVal().getValues().toArray());
}

From source file:org.apache.hadoop.hive.serde2.compression.TestSnappyCompDe.java

@Test
public void testByteCol() {
    ColumnBuffer[] inputCols = new ColumnBuffer[] { columnByte };

    ByteBuffer compressed = compDe.compress(inputCols);
    ColumnBuffer[] outputCols = compDe.decompress(compressed, compressed.limit());

    assertArrayEquals(inputCols[0].toTColumn().getByteVal().getValues().toArray(),
            outputCols[0].toTColumn().getByteVal().getValues().toArray());
}

From source file:org.apache.hadoop.hive.serde2.compression.TestSnappyCompDe.java

@Test
public void testIntCol() {
    ColumnBuffer[] inputCols = new ColumnBuffer[] { columnInt };

    ByteBuffer compressed = compDe.compress(inputCols);
    ColumnBuffer[] outputCols = compDe.decompress(compressed, compressed.limit());

    assertArrayEquals(inputCols[0].toTColumn().getI32Val().getValues().toArray(),
            outputCols[0].toTColumn().getI32Val().getValues().toArray());
}

From source file:org.apache.hadoop.hive.serde2.compression.TestSnappyCompDe.java

@Test
public void testLongCol() {
    ColumnBuffer[] inputCols = new ColumnBuffer[] { columnLong };

    ByteBuffer compressed = compDe.compress(inputCols);
    ColumnBuffer[] outputCols = compDe.decompress(compressed, compressed.limit());

    assertArrayEquals(inputCols[0].toTColumn().getI64Val().getValues().toArray(),
            outputCols[0].toTColumn().getI64Val().getValues().toArray());
}