Package java.nio.channels

Examples of java.nio.channels.FileChannel.map()


 

  private MappedByteBuffer createMappedBuffer( long file_offset, int length ) throws IOException {
    if ( channel == null ) {
      FileChannel fc = new RandomAccessFile( file, "rw" ).getChannel();
      MappedByteBuffer mbb = fc.map( FileChannel.MapMode.READ_WRITE, file_offset, length );
      if ( access_mode == MODE_READ_ONLY ) fc.close();
      else channel = fc;
      return mbb;
    }
   
View Full Code Here


    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);
        }
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;
View Full Code Here

                PDFFile pdffile;
                try {
                   
                    raf = new RandomAccessFile(file, "r");
                    FileChannel channel = raf.getChannel();
                    ByteBuffer buf = channel.map(FileChannel.MapMode.READ_ONLY, 0, channel.size());
                    pdffile = new PDFFile(buf);
                    pdffile.stop(1);
   
                    try {
                        book.setValue(Book._T_NROFPAGES, Long.valueOf(pdffile.getNumPages()));
View Full Code Here

    private int hslots;

    public ReadOnlyCDB(String filename) throws IOException {
        file = new RandomAccessFile(filename, "r");
        FileChannel channel = file.getChannel();
        map = channel.map(MapMode.READ_ONLY, 0, file.length());
        map.order(ByteOrder.LITTLE_ENDIAN);
    }

    public void close() {
        try {
View Full Code Here

   * @throws IOException
   */
  public void read(File f) throws IOException {
    FileInputStream fis = new FileInputStream(f);
    FileChannel fc=fis.getChannel();
    buffer=fc.map(FileChannel.MapMode.READ_ONLY, 0, f.length());
    int o=0;
    do{
      int l=buffer.getInt(o);
      if(l<=STRING_OFFSET){
        throw new IOException("Corrupted file : invalid packet length");
View Full Code Here

          long offset = 0;
          FileChannel chnnl = getChannel();

          // read mbox file to determine the message positions..
          ByteBuffer buffer = chnnl.map(FileChannel.MapMode.READ_ONLY, 0l, size);
          CharBuffer cb = decoder.decode(buffer);

          // check that first message is correct..
          if (Pattern.compile(INITIAL_FROM__PATTERN, Pattern.DOTALL).matcher(cb).matches()) {
            // debugging..
View Full Code Here

            if (size<FRAME) break;

            offset  += FRAME-STEPBACK;
            size = (offset+FRAME<length) ? FRAME : length-(offset+1);

            buffer = chnnl.map(FileChannel.MapMode.READ_ONLY, offset, size);
            cb = decoder.decode(buffer);
          } while (true);

          log.debug("found " + String.valueOf(posList.size()) + " matches");
View Full Code Here

    * @throws java.io.IOException on error
    */
  MMapRandomAccessFile(String location, String mode ) throws IOException {
    super(location, mode, 1);
    FileChannel channel = file.getChannel();
    source = channel.map( readonly ? FileChannel.MapMode.READ_ONLY : FileChannel.MapMode.READ_WRITE, (long) 0, channel.size());
    channel.close();

    bufferStart = 0;
    dataSize = (int) channel.size();
    dataEnd = channel.size();
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.