Package java.nio

Examples of java.nio.ByteBuffer.rewind()


    public final void testEquals () {

        final ByteBuffer testBuffer = ByteBuffer.allocate(TEST_CASE_1_ARRAY.length);
        assertNotNull(testBuffer);
        testBuffer.put(TEST_CASE_1_ARRAY);
        testBuffer.rewind();

        final BinaryDataSegment dataSegment = new BinaryDataSegment(CHUNK_SIZE);
        dataSegment.append(testBuffer, testBuffer.limit());
        assertNotNull(dataSegment);
        assertEquals(5, dataSegment.getLength());
View Full Code Here


        dataSegment.append(testBuffer, testBuffer.limit());
        assertNotNull(dataSegment);
        assertEquals(5, dataSegment.getLength());

        final BinaryDataSegment anotherDataSegment = new BinaryDataSegment(CHUNK_SIZE);
        testBuffer.rewind();
        anotherDataSegment.append(testBuffer, testBuffer.limit());
        assertNotNull(anotherDataSegment);
        assertEquals(5, anotherDataSegment.getLength());

        assertTrue(dataSegment.equals(anotherDataSegment));
View Full Code Here

        assertEquals(TEST_CASE_1_ARRAY.length, dataSegment.getLength());

        final int totalSize = AbstractDataSegment.getTotalLength(TEST_CASE_1_ARRAY.length);
        final ByteBuffer serialized = ByteBuffer.allocate(totalSize);
        assertEquals(totalSize, dataSegment.serialize(serialized, 0));
        serialized.rewind();

        final BinaryDataSegment anotherDataSegment = new BinaryDataSegment(CHUNK_SIZE);
        assertNotNull(anotherDataSegment);
        assertEquals(0, anotherDataSegment.getLength());
View Full Code Here

        dataSegment.add(OperationalTextKey.MAX_CONNECTIONS, "50");

        final int totalSize = AbstractDataSegment.getTotalLength(dataSegment.getLength());
        final ByteBuffer serialized = ByteBuffer.allocate(totalSize);
        assertEquals(totalSize, dataSegment.serialize(serialized, 0));
        serialized.rewind();

        final TextParameterDataSegment anotherDataSegment = new TextParameterDataSegment(dataSegment.getLength());
        assertEquals(AbstractDataSegment.getTotalLength(dataSegment.getLength()), anotherDataSegment.deserialize(serialized, serialized.remaining()));
        assertNotNull(anotherDataSegment);
        assertEquals(AbstractDataSegment.getTotalLength(dataSegment.getLength()), anotherDataSegment.getLength());
View Full Code Here

        for (int i = 0; i < n; i++) {
            val = Short.parseShort(tokens[i], HEX_RADIX);
            numbers.put((byte) val);
        }

        numbers.rewind();

        return numbers;
    }

    // --------------------------------------------------------------------------
View Full Code Here

        ByteBuffer resultBuffer = ByteBuffer.allocate(result.length * Constants.BYTES_PER_INT);

        for (int n : result) {
            resultBuffer.putInt(n);
        }
        resultBuffer.rewind();

        ByteBuffer test = WiresharkMessageParser.parseToByteBuffer(str);
        assertTrue(resultBuffer.equals(test));
    }
}
View Full Code Here

            throw new IllegalArgumentException("Number of bytes is not a multiple of the blocksize!");
        }

        final ByteBuffer dst = ByteBuffer.allocate(data.length);
        initiator.read(target, dst, (int)address, data.length);
        dst.rewind();
        dst.get(data);
    }

    /** {@inheritDoc} */
    public void write(final long address, final byte[] data) throws Exception {
View Full Code Here

        cdb.putInt(logicalBlockAddress);

        // set transfer length
        cdb.position(TRANSFER_LENGTH_OFFSET);
        cdb.putShort(transferLength);
        cdb.rewind();

        return cdb;

    }
View Full Code Here

        ByteBuffer cdb = ByteBuffer.allocate(DEFAULT_CDB_LENGTH);
        // operation code
        cdb.put(READ_CAPACITY_OP_CODE);

        cdb.rewind();

        return cdb;
    }

}
View Full Code Here

    }
    catch (KeyTypeNotImplementedException e1)
    {
      throw new RuntimeException(e1);
    }
    serBuf.rewind();
    DbusEventInternalReadable e = _eventFactory.createReadOnlyDbusEventFromBuffer(serBuf, serBuf.position());
    return e;
  }

  public static int randomPositiveInt() {
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.