Package java.nio.channels

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


            if (file.length() != totalData + c.position()) {
                c.close();
                throw new BadImageFileException(file);
            }

            ByteBuffer bb = c.map(FileChannel.MapMode.READ_ONLY, c.position(), totalData);

            if (dataType == DataBuffer.TYPE_USHORT) {
                bb.order(ByteOrder.BIG_ENDIAN);
                bb.asShortBuffer().get((short[]) imageData.data);
            } else
View Full Code Here


        os.write(src);
        os.close();

        @SuppressWarnings("resource")
        FileChannel channel = new RandomAccessFile(tmp, "r").getChannel();
        MappedByteBuffer buf = channel.map(MapMode.READ_ONLY, 0L, tmp.length());
        return buf;
      } catch (IOException e) {
        throw new AssertionError(e);
      }
    }
View Full Code Here

 
  private static String readFile(String path) throws IOException {
    FileInputStream stream = new FileInputStream(new File(path));
    try {
      FileChannel fc = stream.getChannel();
      MappedByteBuffer bb = fc.map(FileChannel.MapMode.READ_ONLY, 0, fc.size());
      /* Instead of using default, pass in a decoder. */
      return Charset.forName("UTF-8").decode(bb).toString();
    } finally {
      stream.close();
    }
View Full Code Here

  private String readFile(String path) throws IOException {
    FileInputStream stream = new FileInputStream(new File(path));
    try {
      FileChannel fc = stream.getChannel();
      MappedByteBuffer bb = fc.map(FileChannel.MapMode.READ_ONLY, 0,
          fc.size());
      /* Instead of using default, pass in a decoder. */
      return Charset.defaultCharset().decode(bb).toString();
    } finally {
      stream.close();
View Full Code Here

          for (int bufNr = 0; bufNr < nrBuffers; bufNr++) {
            int bufSize = (int) ( (length > (bufferStart + chunkSize))
              ? chunkSize
              : (length - bufferStart)
            );
            this.buffers[bufNr] = rafc.map(MapMode.READ_ONLY, bufferStart, bufSize);
            bufferStart += bufSize;
          }
          seek(0L);
        }
     
View Full Code Here

    RandomAccessFile raf = new RandomAccessFile(file, "rw");
    FileChannel channel = null;
    try {
      raf.setLength(length / 8);
      channel = raf.getChannel();
      filter = channel.map(MapMode.READ_WRITE, 0, length / 8).load();
    } finally {
      Closer.close(raf);
      Closer.close(channel);
    }
  }
View Full Code Here

    RandomAccessFile raf = new RandomAccessFile(file, "rw");
    FileChannel channel = null;
    try {
      raf.setLength(fileLength);
      channel = raf.getChannel();
      filter = channel.map(MapMode.READ_WRITE, 0, fileLength).load();
    } finally {
      Closer.close(raf);
      Closer.close(channel);
    }
  }
View Full Code Here

        this.filter = filter;
        data = new LinkedHashMap<String, MLArray>();
       
        //Create a read-only memory-mapped file
        FileChannel roChannel = new RandomAccessFile(file, "r").getChannel();
        ByteBuffer buf = roChannel.map(FileChannel.MapMode.READ_ONLY, 0, (int)roChannel.size());       
       
        //read in file header
        readHeader(buf);
       
        while ( buf.remaining() > 0 )
View Full Code Here

      for (int bufNr = 0; bufNr < nrBuffers; bufNr++) {
        int bufSize = (int) ( (length > (bufferStart + chunkSize))
          ? chunkSize
          : (length - bufferStart)
        );
        this.buffers[bufNr] = rafc.map(MapMode.READ_ONLY, bufferStart, bufSize);
        bufferStart += bufSize;
      }
      seek(0L);
    }
 
View Full Code Here

    private int position;

    public MappedFileDataInput(FileInputStream stream, String filename, int position) throws IOException
    {
        FileChannel channel = stream.getChannel();
        buffer = channel.map(FileChannel.MapMode.READ_ONLY, position, channel.size());
        this.filename = filename;
        this.position = position;
    }

    public MappedFileDataInput(MappedByteBuffer buffer, String filename, int position)
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.