List of usage examples for org.apache.hadoop.io DataInputBuffer reset
public void reset(byte[] input, int start, int length)
From source file:org.goldenorb.io.input.VertexInput.java
License:Apache License
/** * *///from w ww. j av a2s. c o m @SuppressWarnings("unchecked") public void initialize() { // rebuild the input split org.apache.hadoop.mapreduce.InputSplit split = null; DataInputBuffer splitBuffer = new DataInputBuffer(); splitBuffer.reset(rawSplit.getBytes(), 0, rawSplit.getLength()); SerializationFactory factory = new SerializationFactory(orbConf); Deserializer<? extends org.apache.hadoop.mapreduce.InputSplit> deserializer; try { deserializer = (Deserializer<? extends org.apache.hadoop.mapreduce.InputSplit>) factory .getDeserializer(orbConf.getClassByName(splitClass)); deserializer.open(splitBuffer); split = deserializer.deserialize(null); JobConf job = new JobConf(orbConf); JobContext jobContext = new JobContext(job, new JobID(getOrbConf().getJobNumber(), 0)); InputFormat<INPUT_KEY, INPUT_VALUE> inputFormat; inputFormat = (InputFormat<INPUT_KEY, INPUT_VALUE>) ReflectionUtils .newInstance(jobContext.getInputFormatClass(), orbConf); TaskAttemptContext tao = new TaskAttemptContext(job, new TaskAttemptID(new TaskID(jobContext.getJobID(), true, partitionID), 0)); recordReader = inputFormat.createRecordReader(split, tao); recordReader.initialize(split, tao); } catch (ClassNotFoundException e) { throw new RuntimeException(e); } catch (IOException e) { throw new RuntimeException(e); } catch (InterruptedException e) { throw new RuntimeException(e); } }
From source file:skewtune.mapreduce.lib.input.MapOutputInputStreamReader.java
License:Apache License
public boolean nextRawKey(DataInputBuffer key) throws IOException { try {//w ww. ja va 2 s. c o m while (!positionToNextRecord(dataInput)) { // Okay, we hit the one end of map-output. check whether // this is really true eof = !this.inputStream.hasMore(); // if zero, that is we have completed if (eof) { return false; } // if we have more, then the following call will place the pointer to next map output if (LOG.isDebugEnabled()) { LOG.debug("reading output of " + inputStream.getCurrentTask() + " from " + inputStream.getCurrentHost()); } } // if ( LOG.isDebugEnabled() ) { // LOG.debug(String.format("current key length = %d; current value length = %d", currentKeyLength, currentValueLength) ); // } // Setup the key keyBuf = keyBuf.length < currentKeyLength ? new byte[currentKeyLength << 1] : keyBuf; dataInput.readFully(keyBuf, 0, currentKeyLength); key.reset(keyBuf, 0, currentKeyLength); // if ( LOG.isDebugEnabled() ) { // LOG.debug("key = "+Utils.toHex(keyBuf,0,currentKeyLength)); // } bytesRead += currentKeyLength; return true; } catch (EOFException eofex) { if (this.inputStream.hasMore()) { // double check throw eofex; // SOMETHING IS WRONG? } else { return false; } } catch (IOException ioe) { throw ioe; } }
From source file:skewtune.mapreduce.lib.input.MapOutputInputStreamReader.java
License:Apache License
public void nextRawValue(DataInputBuffer value) throws IOException { try {/*from w w w . j av a 2 s . c o m*/ valBuf = valBuf.length < currentValueLength ? new byte[currentValueLength << 1] : valBuf; dataInput.readFully(valBuf, 0, currentValueLength); value.reset(valBuf, 0, currentValueLength); // if ( LOG.isDebugEnabled() ) { // LOG.debug("value = "+Utils.toHex(valBuf,0,currentValueLength)); // } bytesRead += currentValueLength; ++recNo; } catch (IOException ioe) { throw ioe; } }