Package java.nio

Examples of java.nio.MappedByteBuffer.limit()


     */
    public void test_map_Private() throws IOException {
        this.writeDataToFile(fileOfReadWriteFileChannel);
        MappedByteBuffer mapped = readWriteFileChannel.map(MapMode.PRIVATE, 0,
                CONTENT_LENGTH);
        assertEquals(CONTENT_LENGTH, mapped.limit());
        // test copy on write if private
        ByteBuffer returnByPut = mapped.put(TEST_BYTES);
        assertSame(returnByPut, mapped);
        ByteBuffer checkBuffer = ByteBuffer.allocate(CONTENT_LENGTH);
        mapped.force();
View Full Code Here


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

    /**
 
View Full Code Here

    public void test_map_ReadWrite_NonZeroPosition() throws IOException {
        // test position non-zero
        writeDataToFile(fileOfReadWriteFileChannel);
        MappedByteBuffer mapped = readWriteFileChannel.map(MapMode.READ_WRITE,
                10, CONTENT_LENGTH - 10);
        assertEquals(CONTENT_LENGTH - 10, mapped.limit());
        assertEquals(CONTENT.length() - 10, mapped.capacity());
        assertEquals(0, mapped.position());
        mapped.put(TEST_BYTES);
        ByteBuffer checkBuffer = ByteBuffer.allocate(CONTENT_LENGTH);
        readWriteFileChannel.read(checkBuffer);
View Full Code Here

            MappedByteBuffer mapped = readOnlyFileChannel.map(MapMode.READ_ONLY,
                    sizes[i], CONTENT_LEN);
            assertEquals("Incorrectly mapped file channel for " + sizes[i]
                    + " position (capacity)", CONTENT_LEN, mapped.capacity());
            assertEquals("Incorrectly mapped file channel for " + sizes[i]
                    + " position (limit)", CONTENT_LEN, mapped.limit());
            assertEquals("Incorrectly mapped file channel for " + sizes[i]
                    + " position (position)", 0, mapped.position());

            // map not change channel's position
            assertEquals(0, readOnlyFileChannel.position());
View Full Code Here

        }
      }

      int offset = (int) i + 1;

      if (offset >= bb.limit()) throw new NoSuchElementException();
      ByteArrayOutputStream sb = new ByteArrayOutputStream();
      while (offset < bb.limit()) {
        for (; offset < bb.limit(); offset++) {
          sb.write(bb.get(offset));
        }
View Full Code Here

      int offset = (int) i + 1;

      if (offset >= bb.limit()) throw new NoSuchElementException();
      ByteArrayOutputStream sb = new ByteArrayOutputStream();
      while (offset < bb.limit()) {
        for (; offset < bb.limit(); offset++) {
          sb.write(bb.get(offset));
        }
      }
View Full Code Here

      int offset = (int) i + 1;

      if (offset >= bb.limit()) throw new NoSuchElementException();
      ByteArrayOutputStream sb = new ByteArrayOutputStream();
      while (offset < bb.limit()) {
        for (; offset < bb.limit(); offset++) {
          sb.write(bb.get(offset));
        }
      }

      // Decode the file into a char buffer
View Full Code Here

                            }
                            synchronized (lock) {
                                bb.load();
                                System.out.println(msg + " loaded");
                            }
                            for (int k = 0, n = bb.limit(); k < n; k++) {
                                bb.put(k, (byte)(bb.get(k) + 65));
                            }
                            synchronized (lock) {
                                globalBuffer.rewind();
                                globalBuffer.put(bb); // modification of the synchronized memory
View Full Code Here

       
        while(totalRead < len){
            if (mapN > mappedBuffers.length) // we have run out of data to read from
                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;
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.