Package java.nio

Examples of java.nio.MappedByteBuffer.position()


        if(b.limit()<=offsetInFile){
                //file is smaller, return empty data
                return ByteBuffer.wrap(PageFile.CLEAN_DATA).asReadOnlyBuffer();
            }

        b.position(offsetInFile);
        ByteBuffer ret = b.slice();
        ret.limit(PAGE_SIZE);
        if(!transactionsDisabled||readonly){
            // changes written into buffer will be directly written into file
            // so we need to protect buffer from modifications
View Full Code Here


        else
        {
            segBuffer = segments.get(seg);
        }
       
        segBuffer.position(segOff);
        segBuffer.limit(segOff + blockSize);
       
        ByteBuffer toReturn = segBuffer.slice();
       
        segBuffer.limit(segBuffer.capacity());
View Full Code Here

        try (RandomAccessFile raf = new RandomAccessFile(new File(filename), "rw")) {
          FileChannel channel = raf.getChannel();
          MappedByteBuffer buffer = channel.map(FileChannel.MapMode.READ_WRITE, 0, raf.length());
          int numRecords = buffer.getInt();
          int capacity = (int) (raf.length() - DmaIdList.META_DATA_SIZE) / DmaIdList.SIZE_OF_DATA;
          buffer.position(DmaIdList.META_DATA_SIZE + numRecords * DmaIdList.SIZE_OF_DATA);
          return new DmaIdList(filename, buffer, numRecords, capacity);
        }
      } catch (IOException e) {
        throw new RuntimeException(e);
      }
View Full Code Here

        MappedByteBuffer bb = fc.map(FileChannel.MapMode.READ_WRITE, 0, len);
        int pos = magic.length + version_info.length + option.length +
                size_hi.length;
        byte value = bb.get(pos);
        value--;
        bb.position(pos);
        bb.put(value);
        bb.force();
        fc.truncate(len);
        fc.close();
        return value & 0xFF;
View Full Code Here

        byte value = bb.get(pos);
        if (increment)
            value++;
        else
            value--;
        bb.position(pos);
        bb.put(value);
        bb.force();
        fc.truncate(len);
        fc.close();
        return value & 0xFF;
View Full Code Here

                    }
                });
                FileChannel fc = raf.getChannel();
                fileSize = (int)fc.size();
                mapBuf = fc.map(FileChannel.MapMode.READ_ONLY, 0, fileSize);
                mapBuf.position(0);
                bufferRef = new WeakReference(mapBuf);
                fc.close();
            } catch (NullPointerException e) {
                throw new FontFormatException(e.toString());
            } catch (ClosedChannelException e) {
View Full Code Here

        MappedByteBuffer mapped = readWriteFileChannel.map(MapMode.PRIVATE, 0,
                CONTENT_LENGTH);
        readWriteFileChannel.close();
        mapped.put(TEST_BYTES);
        assertEquals(CONTENT_LENGTH, mapped.limit());
        assertEquals("test".length(), mapped.position());
    }

    /**
     * @tests java.nio.channels.FileChannel#map(MapMode,long,long)
     */
 
View Full Code Here

        } catch (ReadOnlyBufferException ex) {
            // expected;
        }
        assertEquals(CONTENT_LENGTH, mapped.limit());
        assertEquals(CONTENT_LENGTH, mapped.capacity());
        assertEquals(0, mapped.position());

        // try to get a readonly map from read/write channel
        writeDataToFile(fileOfReadWriteFileChannel);
        mapped = readWriteFileChannel.map(MapMode.READ_ONLY, 0, CONTENT
                .length());
View Full Code Here

        this.writeDataToFile(fileOfReadOnlyFileChannel);
        MappedByteBuffer mapped = readOnlyFileChannel.map(MapMode.READ_ONLY,
                10, CONTENT_LENGTH - 10);
        assertEquals(CONTENT_LENGTH - 10, mapped.limit());
        assertEquals(CONTENT_LENGTH - 10, mapped.capacity());
        assertEquals(0, mapped.position());
    }

    /**
     * @tests java.nio.channels.FileChannel#map(MapMode,long,long)
     */
 
View Full Code Here

    public void test_map_Private_NonZeroPosition() throws IOException {
        MappedByteBuffer mapped = readWriteFileChannel.map(MapMode.PRIVATE, 10,
                CONTENT_LENGTH - 10);
        assertEquals(CONTENT_LENGTH - 10, mapped.limit());
        assertEquals(CONTENT_LENGTH - 10, mapped.capacity());
        assertEquals(0, mapped.position());
    }

    /**
     * @tests java.nio.channels.FileChannel#map(MapMode,long,long)
     */
 
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.