Search in sources :

Example 1 with InputStreamFSInputWrapper

use of org.apache.flink.api.common.io.InputStreamFSInputWrapper in project flink by apache.

the class StreamFormatAdapter method openStream.

private static TrackingFsDataInputStream openStream(final Path file, final Configuration config, final long seekPosition) throws IOException {
    final FileSystem fs = file.getFileSystem();
    final long fileLength = fs.getFileStatus(file).getLen();
    final int fetchSize = MathUtils.checkedDownCast(config.get(StreamFormat.FETCH_IO_SIZE).getBytes());
    if (fetchSize <= 0) {
        throw new IllegalConfigurationException(String.format("The fetch size (%s) must be > 0, but is %d", StreamFormat.FETCH_IO_SIZE.key(), fetchSize));
    }
    final InflaterInputStreamFactory<?> deCompressor = StandardDeCompressors.getDecompressorForFileName(file.getPath());
    final FSDataInputStream inStream = fs.open(file);
    return doWithCleanupOnException(inStream, () -> {
        final FSDataInputStream in = deCompressor == null ? inStream : new InputStreamFSInputWrapper(deCompressor.create(inStream));
        in.seek(seekPosition);
        return new TrackingFsDataInputStream(in, fileLength, fetchSize);
    });
}
Also used : FileSystem(org.apache.flink.core.fs.FileSystem) IllegalConfigurationException(org.apache.flink.configuration.IllegalConfigurationException) FSDataInputStream(org.apache.flink.core.fs.FSDataInputStream) InputStreamFSInputWrapper(org.apache.flink.api.common.io.InputStreamFSInputWrapper)

Aggregations

InputStreamFSInputWrapper (org.apache.flink.api.common.io.InputStreamFSInputWrapper)1 IllegalConfigurationException (org.apache.flink.configuration.IllegalConfigurationException)1 FSDataInputStream (org.apache.flink.core.fs.FSDataInputStream)1 FileSystem (org.apache.flink.core.fs.FileSystem)1