Package java.nio

Examples of java.nio.MappedByteBuffer.remaining()


    FileInputStream fis = new FileInputStream(infile);
    try{
      FileChannel fc = fis.getChannel(); // Get the file's size and then map it into memory
      int sz = (int)fc.size();
      MappedByteBuffer bb = fc.map(FileChannel.MapMode.READ_ONLY, 0, sz);
      byte[] data2 = new byte[bb.remaining()];
      bb.get(data2);
      return data2;
    }
    finally{//Ensures resources are closed regardless of whether the action suceeded
      fis.close();
View Full Code Here


                break;
            MappedByteBuffer currentBuffer = mappedBuffers[mapN];
            if (offN > currentBuffer.limit())
                break;
            currentBuffer.position(offN);
            int bytesFromThisBuffer = Math.min(len, currentBuffer.remaining());
            currentBuffer.get(bytes, off, bytesFromThisBuffer);
            off += bytesFromThisBuffer;
            pos += bytesFromThisBuffer;
            totalRead += bytesFromThisBuffer;
View Full Code Here

                break;
            MappedByteBuffer currentBuffer = mappedBuffers[mapN];
            if (offN > currentBuffer.limit())
                break;
            currentBuffer.position(offN);
            int bytesFromThisBuffer = Math.min(len - totalRead, currentBuffer.remaining());
            currentBuffer.get(bytes, off, bytesFromThisBuffer);
            off += bytesFromThisBuffer;
            pos += bytesFromThisBuffer;
            totalRead += bytesFromThisBuffer;
View Full Code Here

                break;
            MappedByteBuffer currentBuffer = mappedBuffers[mapN];
            if (offN > currentBuffer.limit())
                break;
            currentBuffer.position(offN);
            int bytesFromThisBuffer = Math.min(len, currentBuffer.remaining());
            currentBuffer.get(bytes, off, bytesFromThisBuffer);
            off += bytesFromThisBuffer;
            pos += bytesFromThisBuffer;
            totalRead += bytesFromThisBuffer;
View Full Code Here

        if (!files.isEmpty()) {
            MappedByteBuffer last = files.getLast();

            // Check if there's still enough room in the last open file
            int segments = (size + SEGMENT_SIZE - 1) / SEGMENT_SIZE;
            if ((1 + segments + 2) * SEGMENT_SIZE <= last.remaining()) {
                return last;
            }

            // No more room, so finish the last file with padding as needed
            if (last.remaining() >= 3 * SEGMENT_SIZE) {
View Full Code Here

            if ((1 + segments + 2) * SEGMENT_SIZE <= last.remaining()) {
                return last;
            }

            // No more room, so finish the last file with padding as needed
            if (last.remaining() >= 3 * SEGMENT_SIZE) {
                // Add a padding entry to avoid problems during reopening
                last.put(createTarHeader(
                        PADDING_UUID,
                        last.remaining() - 3 * SEGMENT_SIZE));
                if (last.remaining() > 2 * SEGMENT_SIZE) {
View Full Code Here

            // No more room, so finish the last file with padding as needed
            if (last.remaining() >= 3 * SEGMENT_SIZE) {
                // Add a padding entry to avoid problems during reopening
                last.put(createTarHeader(
                        PADDING_UUID,
                        last.remaining() - 3 * SEGMENT_SIZE));
                if (last.remaining() > 2 * SEGMENT_SIZE) {
                    last.putLong(PADDING_MAGIC);
                    last.put(PADDING_BYTES, 0, SEGMENT_SIZE - 8);
                }
            }
View Full Code Here

            if (last.remaining() >= 3 * SEGMENT_SIZE) {
                // Add a padding entry to avoid problems during reopening
                last.put(createTarHeader(
                        PADDING_UUID,
                        last.remaining() - 3 * SEGMENT_SIZE));
                if (last.remaining() > 2 * SEGMENT_SIZE) {
                    last.putLong(PADDING_MAGIC);
                    last.put(PADDING_BYTES, 0, SEGMENT_SIZE - 8);
                }
            }
            while (last.remaining() > 0) {
View Full Code Here

                if (last.remaining() > 2 * SEGMENT_SIZE) {
                    last.putLong(PADDING_MAGIC);
                    last.put(PADDING_BYTES, 0, SEGMENT_SIZE - 8);
                }
            }
            while (last.remaining() > 0) {
                last.put(PADDING_BYTES);
            }
            last.force();
        }

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.