Java File Read via ByteBuffer read(Path file, int pos, int length)

Here you can find the source of read(Path file, int pos, int length)

Description

read

License

Open Source License

Declaration

public static MappedByteBuffer read(Path file, int pos, int length) throws IOException 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.RandomAccessFile;

import java.nio.MappedByteBuffer;
import java.nio.channels.FileChannel;

import java.nio.file.Path;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public class Main {
    private static Map<String, FileChannel> FILES = new ConcurrentHashMap<String, FileChannel>();

    public static MappedByteBuffer read(Path file, int pos, int length) throws IOException {
        return getFileChannel(file, "r").map(FileChannel.MapMode.READ_ONLY, pos, length);
    }// w w w . j  a va2s  . co m

    public static FileChannel getFileChannel(Path file, String mode) throws FileNotFoundException {
        if (!FILES.containsKey(file.toString())) {
            FILES.put(file.toString(), new RandomAccessFile(file.toString(), mode).getChannel());
        }
        return FILES.get(file.toString());
    }
}

Related

  1. read(final File source)
  2. read(final FileChannel channel)
  3. read(final Reader input, final char[] buffer, final int offset, final int length)
  4. read(InputStream stream)
  5. read(Path file)
  6. read(Reader reader)
  7. read24BitInteger(byte[] threeBytes, ByteOrder order)
  8. read_file(File input)
  9. readAiffHeader(DataInputStream inStrm, FileChannel fc)