@Override public Record nextRecord(Record reuse) throws IOException { // check if read buffer contains another full record if (this.readBufferLimit - this.readBufferPos <= 0) { // get another buffer fillReadBuffer(); // check if source is exhausted if (this.exhausted) { return null; } } else if (this.readBufferLimit - this.readBufferPos < this.recordLength) { throw new IOException("Unable to read full record"); } boolean val = readBytes(reuse, this.readBuffer, this.readBufferPos); this.readBufferPos += this.recordLength; if (this.readBufferPos >= this.readBufferLimit) { fillReadBuffer(); } return val ? reuse : null; }
@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(); }