Example usage for org.apache.commons.io.input NullInputStream read

List of usage examples for org.apache.commons.io.input NullInputStream read

Introduction

In this page you can find the example usage for org.apache.commons.io.input NullInputStream read.

Prototype

public int read(byte[] bytes, int offset, int length) throws IOException 

Source Link

Document

Read the specified number bytes into an array.

Usage

From source file:ch.cyberduck.core.io.FileBuffer.java

@Override
public synchronized int read(final byte[] chunk, final Long offset) throws IOException {
    final RandomAccessFile file = random();
    if (offset < file.length()) {
        file.seek(offset);// w  w w  .jav  a 2 s.co m
        if (chunk.length + offset > file.length()) {
            return file.read(chunk, 0, (int) (file.length() - offset));
        } else {
            return file.read(chunk, 0, chunk.length);
        }
    } else {
        final NullInputStream nullStream = new NullInputStream(length);
        if (nullStream.available() > 0) {
            nullStream.skip(offset);
            return nullStream.read(chunk, 0, chunk.length);
        } else {
            return IOUtils.EOF;
        }
    }
}