public int read(byte[] b, int off, int len) throws IOException { int read; read = stream.read(b, off, len); pos += read; return read; }
private final boolean fillBuffer() throws IOException { int toRead = this.lengthLeft > this.readBuffer.length ? this.readBuffer.length : (int) this.lengthLeft; if (this.lengthLeft <= 0) { toRead = this.readBuffer.length; this.overLimit = true; } int read = this.stream.read(this.readBuffer, 0, toRead); if (read == -1) { this.stream.close(); this.stream = null; return false; } else { this.lengthLeft -= read; this.readPos = 0; this.limit = read; return true; } }
private final boolean fillBuffer() throws IOException { int toRead = this.lengthLeft > this.readBuffer.length ? this.readBuffer.length : (int) this.lengthLeft; if (this.lengthLeft <= 0) { toRead = this.readBuffer.length; this.overLimit = true; } int read = this.stream.read(this.readBuffer, 0, toRead); if (read == -1) { this.stream.close(); this.stream = null; return false; } else { this.lengthLeft -= read; this.readPos = 0; this.limit = read; return true; } }
@Override public int read(final ByteBuffer dst, final long position) throws IOException { final int length = Math.min(this.buf.length, dst.remaining()); final FSDataInputStream inputStream = getInputStream(); if (position != this.nextExpectedReadPosition) { System.out.println("Next expected position is " + this.nextExpectedReadPosition + ", seeking to " + position); inputStream.seek(position); this.nextExpectedReadPosition = position; } final int bytesRead = inputStream.read(this.buf, 0, length); if (bytesRead == -1) { return -1; } dst.put(this.buf, 0, length); this.nextExpectedReadPosition += bytesRead; return bytesRead; }
@Override public int read(final ByteBuffer dst, final long position) throws IOException { final int length = Math.min(this.buf.length, dst.remaining()); final FSDataInputStream inputStream = getInputStream(); if (position != this.nextExpectedReadPosition) { System.out.println("Next expected position is " + this.nextExpectedReadPosition + ", seeking to " + position); inputStream.seek(position); this.nextExpectedReadPosition = position; } final int bytesRead = inputStream.read(this.buf, 0, length); if (bytesRead == -1) { return -1; } dst.put(this.buf, 0, length); this.nextExpectedReadPosition += bytesRead; return bytesRead; }
assertEquals(lfsinput2.read(testbytestest), 5); lfsinput2.close(); assertTrue(Arrays.equals(testbytes, testbytestest));