Package java.nio

Examples of java.nio.MappedByteBuffer


    try{
      if(USE_MMAP)
      {
        long remainingInFile = fc.size()-offset;
        long remainingInTargetBuffer = buffer.remaining(DirectByteBuffer.SS_FILE);
        MappedByteBuffer buf = fc.map(MapMode.READ_ONLY, offset, Math.min(remainingInFile,remainingInTargetBuffer));
        buffer.put(DirectByteBuffer.SS_FILE, buf);
      } else {
        fc.position(offset);
        while (fc.position() < fc.size() && buffer.hasRemaining(DirectByteBuffer.SS_FILE))
          buffer.read(DirectByteBuffer.SS_FILE,fc);       
View Full Code Here


          size += buffers[i].remaining(DirectByteBuffer.SS_FILE);
          original_positions[i] = buffers[i].position(DirectByteBuffer.SS_FILE);
        }
         
        size = Math.min(size, fc.size()-offset);
        MappedByteBuffer buf = fc.map(MapMode.READ_ONLY, offset, size);
        for(DirectByteBuffer b : buffers)
        {
          buf.limit(buf.position()+b.remaining(DirectByteBuffer.SS_FILE));
          b.put(DirectByteBuffer.SS_FILE, buf);
        }
         
       
      } else {
View Full Code Here

          fc.position(position+size-1);
          fc.write(ByteBuffer.allocate(1));
          fc.force(true);
        }
         
        MappedByteBuffer buf = fc.map(MapMode.READ_WRITE, position, size);
        for(DirectByteBuffer b : buffers)
          buf.put(b.getBuffer(DirectByteBuffer.SS_FILE));
        buf.force();
      } else {
        long  expected_write   = 0;
        long  actual_write  = 0;
        boolean  partial_write  = false;
       
View Full Code Here

        final Map<MutableLongPair, CloseableMappedByteBuffer> pool = _pool;
        CloseableMappedByteBuffer buf;
        synchronized(pool) {
            buf = pool.get(pair);
            if(buf == null || !AtomicUtils.tryIncrementIfGreaterThan(buf.referenceCount(), 0)) {
                MappedByteBuffer bufimpl = map(pageOffset);
                buf = new CloseableMappedByteBuffer(bufimpl);
                pool.put(pair, buf);
            }
        }
        return buf;
View Full Code Here

     */
    private MappedByteBuffer map(final long page) {
        if(_channel == null) {
            ensureOpen();
        }
        MappedByteBuffer buf;
        try {
            buf = _channel.map(_readOnly ? MapMode.READ_ONLY : MapMode.READ_WRITE, page, _pageSize);
        } catch (IOException e) {// silly workaround for JDK bug #4724038
            System.gc();
            System.runFinalization();
            try {
                buf = _channel.map(_readOnly ? MapMode.READ_ONLY : MapMode.READ_WRITE, page, _pageSize);
            } catch (IOException ioe) {
                throw new IllegalStateException("map failed for page#" + page + " of file: "
                        + _filepath, ioe);
            }
        }
        if(_setAsLittleEndian) {// BIG_ENDIAN by the default
            buf.order(ByteOrder.LITTLE_ENDIAN);
        }
        return buf;
    }
View Full Code Here

      while (chFrom.charAt(start++)!=(char) 10) ;

      log.debug("  skip = " + String.valueOf(start));
      log.debug("  start = " + String.valueOf(begin+start));

      MappedByteBuffer byBuffer = getChannel().map(FileChannel.MapMode.READ_ONLY, begin+start, size);
      byte[] byArray = new byte[size];
      byBuffer.get(byArray);

      ByteArrayInputStream byStrm = new ByteArrayInputStream(byArray);

      return byStrm;
    }
View Full Code Here

      start += offset;

      log.debug("  skip = " + String.valueOf(start));
      log.debug("  start = " + String.valueOf(start));

      MappedByteBuffer byBuffer = getChannel().map(FileChannel.MapMode.READ_ONLY, begin+start, size);
      byte[] byArray = new byte[size];
      byBuffer.get(byArray);

      ByteArrayInputStream byStrm = new ByteArrayInputStream(byArray);

      return byStrm;
    }
View Full Code Here

      while (chFrom.charAt(start++)!=(char) 10) ;

      log.debug("  skip = " + String.valueOf(start));
      log.debug("  start = " + String.valueOf(position+start));

      MappedByteBuffer byBuffer = getChannel().map(FileChannel.MapMode.READ_ONLY, position+start, size-start);
      byte[] byArray = new byte[size-start];
      byBuffer.get(byArray);

      ByteArrayInputStream byStrm = new ByteArrayInputStream(byArray);

      return byStrm;
    }
View Full Code Here

        try {
            in = new FileInputStream(source).getChannel();
            out = new FileOutputStream(dest).getChannel();

            long size = in.size();
            MappedByteBuffer buf = in.map(FileChannel.MapMode.READ_ONLY, 0, size);

            out.write(buf);

            if (in != null) {
                in.close();
View Full Code Here

    RandomAccessFile raf =
        new RandomAccessFile(file, mode == MapMode.READ_ONLY ? "r" : "rw");

    boolean threw = true;
    try {
      MappedByteBuffer mbb = map(raf, mode, size);
      threw = false;
      return mbb;
    } finally {
      Closeables.close(raf, threw);
    }
View Full Code Here

TOP

Related Classes of java.nio.MappedByteBuffer

Copyright © 2018 www.massapicom. 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.