Code example for FileInputStream

Methods: getChannel

0
	private FileChannel channel; 
	private MappedByteBuffer byteBuffer;
	private int offset;
	 
	public MemoryMappedBitStream(FileInputStream inputStream) throws IOException {
		super(inputStream);
		this.channel = inputStream.getChannel();
		byteBuffer = channel.map(FileChannel.MapMode.READ_ONLY, 0, channel.size());
		offset = 0;
	} 
	 
    protected int readByte() throws IOException { 
    	return byteBuffer.get() & 0xFF; 
    } 
     
    public String readString() throws IOException {
        final int l = readInt();
        byte[] b = new byte[l];
        //byteBuffer.position(offset); 
        byteBuffer.get(b);
        offset += l;