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; } }
public void seek(long p) throws IOException { stream.seek(p); pos = p; }
@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; }
/** * Closes the file input stream of the input format. */ @Override public void close() throws IOException { if (this.stream != null) { // close input stream this.stream.close(); stream = null; } }
public int read(byte[] b, int off, int len) throws IOException { int read; read = stream.read(b, off, len); pos += read; return read; }
@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; }
/** * Closes the file input stream of the input format. */ @Override public void close() throws IOException { if (this.stream != null) { // close input stream this.stream.close(); stream = null; } }
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; } }
public LineReader(final FSDataInputStream strm, final long start, final long length, final int buffersize) throws IOException { this.stream = strm; this.readBuffer = new byte[buffersize]; this.wrapBuffer = new byte[256]; this.lengthLeft = length; this.readPos = 0; this.overLimit = false; if (start != 0) { strm.seek(start); readLine(); } else { fillBuffer(); } }
public void close() throws IOException { this.wrapBuffer = null; this.readBuffer = null; if (this.stream != null) { this.stream.close(); } }
private final boolean fillBuffer() throws IOException { int read = this.stream.read(this.readBuffer, 0, readBuffer.length); if (read == -1) { this.stream.close(); this.stream = null; return false; int read = this.stream.read(this.readBuffer, 0, toRead); this.stream.close(); this.stream = null; return false;
public LineReader(final FSDataInputStream strm, final long start, final long length, final int buffersize) throws IOException { this.stream = strm; this.readBuffer = new byte[buffersize]; this.wrapBuffer = new byte[256]; this.lengthLeft = length; this.readPos = 0; this.overLimit = false; if (start != 0) { strm.seek(start); readLine(); } else { fillBuffer(); } }
public void close() throws IOException { this.wrapBuffer = null; this.readBuffer = null; if (this.stream != null) { this.stream.close(); } }
private final boolean fillBuffer() throws IOException { int read = this.stream.read(this.readBuffer, 0, readBuffer.length); if (read == -1) { this.stream.close(); this.stream = null; return false; int read = this.stream.read(this.readBuffer, 0, toRead); this.stream.close(); this.stream = null; return false;
@Override public void open(FileInputSplit split) throws IOException { // open input split using FileInputFormat super.open(split); // adjust the stream positions for boundary splits int recordOffset = (int) (this.splitStart % this.recordLength); if(recordOffset != 0) { // move start to next boundary super.stream.seek(this.splitStart + recordOffset); } this.streamPos = this.splitStart + recordOffset; this.streamEnd = this.splitStart + this.splitLength; this.streamEnd += this.streamEnd % this.recordLength; // adjust readBufferSize this.readBufferSize += this.recordLength - (this.readBufferSize % this.recordLength); if (this.readBuffer == null || this.readBuffer.length != this.readBufferSize) { this.readBuffer = new byte[this.readBufferSize]; } this.readBufferLimit = 0; this.readBufferPos = 0; this.exhausted = false; fillReadBuffer(); }
public void close() throws IOException { stream.close(); } }