@Override public void open(GenericInputSplit split) throws IOException { super.open(split); // compute readBufferSize if(recordLength > this.targetReadBufferSize) { // read buffer is at least as big as record this.readBuffer = new byte[recordLength]; } else if (this.targetReadBufferSize % recordLength == 0) { // target read buffer size is a multiple of record length, so it's ok this.readBuffer = new byte[this.targetReadBufferSize]; } else { // extent default read buffer size such that records are not split this.readBuffer = new byte[(recordLength - (this.targetReadBufferSize % recordLength)) + this.targetReadBufferSize]; } // initialize read buffer positions this.readBufferReadPos = 0; this.readBufferFillPos = 0; this.readBufferRemainSpace = readBuffer.length; // initialize end flags this.noMoreStreamInput = false; this.noMoreRecordBuffers = false; }
@Override public void configure(Configuration parameters) { // configure parent super.configure(parameters); // read own parameters this.recordLength = parameters.getInteger(RECORDLENGTH_PARAMETER_KEY, 0); if (recordLength < 1) { throw new IllegalArgumentException("The record length parameter must be set and larger than 0."); } }
@Override public void close() throws IOException { try { // get exit code int exitCode = this.extProc.exitValue(); // check whether exit code is allowed boolean exitCodeOk = false; for(int i=0; i<this.allowedExitCodes.length; i++) { if(this.allowedExitCodes[i] == exitCode) { exitCodeOk = true; break; } } if(!exitCodeOk) { // external process did not finish with an allowed exit code throw new RuntimeException("External process did not finish with an allowed exit code: "+exitCode); } } catch(IllegalThreadStateException itse) { // process did not terminate yet, shut it down! this.extProc.destroy(); if(!this.reachedEnd()) { throw new RuntimeException("External process was destroyed although stream was not fully read."); } } finally { this.extProcErrStream.close(); this.extProcOutStream.close(); } }