@Override public int read() throws IOException { if (this.getMaxBytesToRead(1) == -1) { return -1; } final int b = this.wrappedInputStream.read(); if (b != -1) { this.numReadBytes++; } return b; }
try (LimitedInputStream lis = new LimitedInputStream(fileSystem.get().open(TextFileSource.this.inputUrl), 1 * MiB)) { final BufferedReader bufferedReader = new BufferedReader( new InputStreamReader(lis, TextFileSource.this.encoding) return OptionalDouble.empty(); return OptionalDouble.of((double) lis.getNumReadBytes() / numLineFeeds); } catch (IOException e) { TextFileSource.this.logger.error("Could not estimate bytes per line of an input file.", e);
@Override public int read(byte[] b, int off, int len) throws IOException { int trimmedLen = this.getMaxBytesToRead(len); if (trimmedLen == -1) { return -1; } int numReadBytes = this.wrappedInputStream.read(b, off, trimmedLen); if (numReadBytes != -1) { this.numReadBytes += numReadBytes; } return numReadBytes; }
@Override public long skip(long n) throws IOException { if (n < 0) return 0; int trimmedN = this.getMaxBytesToRead((int) Math.min(Integer.MAX_VALUE, n)); return this.wrappedInputStream.skip(trimmedN); }
@Override public int available() throws IOException { return Math.max(0, this.getMaxBytesToRead(this.wrappedInputStream.available())); }