@Override protected final boolean startImpl() throws IOException { FileBasedSource<T> source = getCurrentSource(); this.channel = FileSystems.open(source.getSingleFileMetadata().resourceId()); if (channel instanceof SeekableByteChannel) { SeekableByteChannel seekChannel = (SeekableByteChannel) channel; seekChannel.position(source.getStartOffset()); } else { // Channel is not seekable. Must not be a subrange. checkArgument( source.mode != Mode.SINGLE_FILE_OR_SUBRANGE, "Subrange-based sources must only be defined for file types that support seekable " + " read channels"); checkArgument( source.getStartOffset() == 0, "Start offset %s is not zero but channel for reading the file is not seekable.", source.getStartOffset()); } startReading(channel); // Advance once to load the first record. return advanceImpl(); }
/** * Creates a decompressing channel from the input channel and passes it to its delegate reader's * {@link FileBasedReader#startReading(ReadableByteChannel)}. */ @Override protected final void startReading(ReadableByteChannel channel) throws IOException { synchronized (progressLock) { this.channel = new CountingChannel(channel, getCurrentSource().getStartOffset()); channel = this.channel; } if (channelFactory == CompressionMode.AUTO) { readerDelegate.startReading( Compression.detect(getCurrentSource().getFileOrPatternSpec()) .readDecompressed(channel)); } else { readerDelegate.startReading(channelFactory.createDecompressingChannel(channel)); } }