Package java.nio

Examples of java.nio.ByteBuffer.capacity()


        write2.get();

        // Getting the data from the first target multithreaded
        final Future<Void> read1 = initiator.multiThreadedRead(target1, readData1, address, readData1.capacity());
        // Getting the data from the second target multithreaded
        final Future<Void> read2 = initiator.multiThreadedRead(target2, readData2, address, readData2.capacity());

        // Blocking until reads are concluded
        read1.get();
        read2.get();
View Full Code Here


        // writing the data single threaded
        initiator.write(target, writeData, address, writeData.capacity());

        // reading the data single threaded
        initiator.read(target, readData, address, readData.capacity());

        // closing the session
        initiator.closeSession(target);

        // correctness check
View Full Code Here

    public static void toBytes(byte key[], int fileId, int valuePos) {
        ByteBuffer out = ByteBuffer.wrap(key).order(ByteOrder.nativeOrder());
        out.position(20);
        out.putInt(fileId);
        out.putInt(valuePos);
        assert(out.position() == out.capacity());
    }
}
View Full Code Here

            while (true) {
                entryBuffer.clear();
                int read = 0;

                while (read < ENTRY_WITH_CHECKSUM_SIZE) {
                    final int readThisTime = pis.read(entryBuffer.array(), read, entryBuffer.capacity() - read);
                    if (readThisTime == -1) break;
                    read += readThisTime;
                }

                if (read == 0 || read < ENTRY_WITH_CHECKSUM_SIZE) {
View Full Code Here

                    }
                    return true;
                }
                final int expectedCRC = entryBuffer.getInt();
                final CRC32 crc = new CRC32();
                crc.update(entryBuffer.array(), 4, entryBuffer.capacity() - 4);
                final int actualCRC = (int)crc.getValue();

                if (expectedCRC != actualCRC) {
                    m_channel.close();
                    return false;
View Full Code Here

        finalBuf.position(4);
        finalBuf.putInt(compressedBytes.length);
        finalBuf.put(compressedBytes);

        final CRC32 crc = new CRC32();
        crc.update(finalBuf.array(), 8, finalBuf.capacity() - 8);
        finalBuf.putInt(0, (int)crc.getValue());

        return new Object[] { finalBuf.array(), keyHash };
    }
View Full Code Here

        entryBuf.putInt(-1);
        entryBuf.put(keyHash);
        entryBuf.putLong(timestamp);

        final CRC32 crc = new CRC32();
        crc.update(entryBuf.array(), 4, entryBuf.capacity() - 4);
        entryBuf.putInt(0, (int)crc.getValue());

        return entryBuf.array();
    }
View Full Code Here

                    } else {
                        remaining = size + 4;
                    }
                    bb.putInt(size);
                    // for large objects send one at a time.
                    if (size > bb.capacity() / 2) {
                        while (remaining > 0) {
                            int size2 = Math.min(remaining, bb.capacity());
                            bb.limit(size2);
                            excerpt.read(bb);
                            bb.flip();
View Full Code Here

                    }
                    bb.putInt(size);
                    // for large objects send one at a time.
                    if (size > bb.capacity() / 2) {
                        while (remaining > 0) {
                            int size2 = Math.min(remaining, bb.capacity());
                            bb.limit(size2);
                            excerpt.read(bb);
                            bb.flip();
//                        System.out.println("w " + ChronicleTools.asString(bb));
                            remaining -= bb.remaining();
View Full Code Here

                    } else {
                        bb.limit(remaining);
                        excerpt.read(bb);
                        int count = 1;
                        while (excerpt.index(index + 1) && count++ < MAX_MESSAGE) {
                            if (excerpt.remaining() + 4 >= bb.capacity() - bb.position())
                                break;
                            // if there is free space, copy another one.
                            int size2 = excerpt.capacity();
//                            System.out.println("W+ "+size);
                            bb.limit(bb.position() + size2 + 4);
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.