List of usage examples for org.apache.hadoop.io WritableUtils readVInt
public static int readVInt(DataInput stream) throws IOException
From source file:org.apache.gora.util.IOUtils.java
License:Apache License
/** * Reads a boolean[] from input/* www . j av a2 s .c o m*/ * @throws IOException */ public static boolean[] readBoolArray(DataInput in) throws IOException { int length = WritableUtils.readVInt(in); boolean[] arr = new boolean[length]; byte b = 0; for (int i = 0; i < length; i++) { if (i % 8 == 0) { b = in.readByte(); } arr[i] = (b & 0x01) > 0; b >>= 1; } return arr; }
From source file:org.apache.gora.util.IOUtils.java
License:Apache License
/** * Reads and returns a String array that is written by * {@link #writeStringArray(DataOutput, String[])}. * @param in the data input to read from * @return read String[]/*from ww w . j a va2 s. c om*/ */ public static String[] readStringArray(DataInput in) throws IOException { int len = WritableUtils.readVInt(in); String[] arr = new String[len]; for (int i = 0; i < len; i++) { arr[i] = Text.readString(in); } return arr; }
From source file:org.apache.hama.bsp.BSPJobClient.java
License:Apache License
/** * Read a splits file into a list of raw splits * /*from ww w . java2 s .c o m*/ * @param in the stream to read from * @return the complete list of splits * @throws IOException */ static RawSplit[] readSplitFile(DataInput in) throws IOException { byte[] header = new byte[SPLIT_FILE_HEADER.length]; in.readFully(header); if (!Arrays.equals(SPLIT_FILE_HEADER, header)) { throw new IOException("Invalid header on split file"); } int vers = WritableUtils.readVInt(in); if (vers != CURRENT_SPLIT_FILE_VERSION) { throw new IOException("Unsupported split version " + vers); } int len = WritableUtils.readVInt(in); RawSplit[] result = new RawSplit[len]; for (int i = 0; i < len; ++i) { RawSplit split = new RawSplit(); split.readFields(in); if (split.getPartitionID() != Integer.MIN_VALUE) result[split.getPartitionID()] = split; else result[i] = split; } return result; }
From source file:org.apache.hama.bsp.DispatchTasksDirective.java
License:Apache License
@Override public void readFields(DataInput in) throws IOException { super.readFields(in); int length = WritableUtils.readVInt(in); if (length > 0) { this.actions = new GroomServerAction[length]; for (int i = 0; i < length; ++i) { GroomServerAction.ActionType actionType = WritableUtils.readEnum(in, GroomServerAction.ActionType.class); actions[i] = GroomServerAction.createAction(actionType); actions[i].readFields(in);//w w w . j ava 2 s. c o m } } else { this.actions = null; } }
From source file:org.apache.hama.bsp.join.CompositeInputSplit.java
License:Apache License
/** * {@inheritDoc}/*from w ww . ja v a2s . c om*/ * * @throws IOException If the child InputSplit cannot be read, typically for * faliing access checks. */ @SuppressWarnings("unchecked") // Generic array assignment public void readFields(DataInput in) throws IOException { int card = WritableUtils.readVInt(in); if (splits == null || splits.length != card) { splits = new InputSplit[card]; } Class<? extends InputSplit>[] cls = new Class[card]; try { for (int i = 0; i < card; ++i) { cls[i] = Class.forName(Text.readString(in)).asSubclass(InputSplit.class); } for (int i = 0; i < card; ++i) { splits[i] = ReflectionUtils.newInstance(cls[i], null); splits[i].readFields(in); } } catch (ClassNotFoundException e) { throw (IOException) new IOException("Failed split init").initCause(e); } }
From source file:org.apache.hama.bsp.join.TupleWritable.java
License:Apache License
/** * {@inheritDoc}/*from w w w .ja v a 2 s .c o m*/ */ @SuppressWarnings("unchecked") // No static typeinfo on Tuples public void readFields(DataInput in) throws IOException { int card = WritableUtils.readVInt(in); values = new Writable[card]; written = WritableUtils.readVLong(in); Class<? extends Writable>[] cls = new Class[card]; try { for (int i = 0; i < card; ++i) { cls[i] = Class.forName(Text.readString(in)).asSubclass(Writable.class); } for (int i = 0; i < card; ++i) { values[i] = cls[i].newInstance(); if (has(i)) { values[i].readFields(in); } } } catch (ClassNotFoundException e) { throw (IOException) new IOException("Failed tuple init").initCause(e); } catch (IllegalAccessException e) { throw (IOException) new IOException("Failed tuple init").initCause(e); } catch (InstantiationException e) { throw (IOException) new IOException("Failed tuple init").initCause(e); } }
From source file:org.apache.hama.bsp.TaskCompletionEvent.java
License:Apache License
@Override public void readFields(DataInput in) throws IOException { taskId.readFields(in);/*from w w w .j a v a 2s . co m*/ idWithinJob = WritableUtils.readVInt(in); status = WritableUtils.readEnum(in, Status.class); groomServerInfo = WritableUtils.readString(in); taskRunTime = WritableUtils.readVInt(in); eventId = WritableUtils.readVInt(in); }
From source file:org.apache.hama.pipes.protocol.UplinkReader.java
License:Apache License
protected int readCommand() throws IOException { return WritableUtils.readVInt(this.inStream); }
From source file:org.apache.hama.pipes.protocol.UplinkReader.java
License:Apache License
public void getPeerName() throws IOException { int id = WritableUtils.readVInt(this.inStream); LOG.debug("Got MessageType.GET_PEERNAME id: " + id); WritableUtils.writeVInt(this.outStream, MessageType.GET_PEERNAME.code); if (id == -1) { // -1 indicates get own PeerName Text.writeString(this.outStream, peer.getPeerName()); LOG.debug("Responded MessageType.GET_PEERNAME - Get Own PeerName: " + peer.getPeerName()); } else if ((id < -1) || (id >= peer.getNumPeers())) { // if no PeerName for this index is found write emptyString Text.writeString(this.outStream, ""); LOG.debug("Responded MessageType.GET_PEERNAME - Empty PeerName!"); } else {// w w w . j av a 2 s . c o m Text.writeString(this.outStream, peer.getPeerName(id)); LOG.debug("Responded MessageType.GET_PEERNAME - PeerName: " + peer.getPeerName(id)); } binProtocol.flush(); }
From source file:org.apache.hama.pipes.protocol.UplinkReader.java
License:Apache License
public void seqFileReadNext() throws IOException { int fileID = WritableUtils.readVInt(this.inStream); LOG.debug("GOT MessageType.SEQFILE_READNEXT - FileID: " + fileID); // check if fileID is available in sequenceFileReader if (this.sequenceFileReaders.containsKey(fileID)) { Writable sequenceKeyWritable = sequenceFileReaders.get(fileID).getValue().getKey(); Writable sequenceValueWritable = sequenceFileReaders.get(fileID).getValue().getValue(); // try to read next key/value pair from SequenceFile.Reader if (this.sequenceFileReaders.get(fileID).getKey().next(sequenceKeyWritable, sequenceValueWritable)) { WritableUtils.writeVInt(this.outStream, MessageType.SEQFILE_READNEXT.code); binProtocol.writeObject(sequenceKeyWritable); binProtocol.writeObject(sequenceValueWritable); LOG.debug("Responded MessageType.SEQFILE_READNEXT -" + " Key: " + ((sequenceKeyWritable.toString().length() < 10) ? sequenceKeyWritable.toString() : sequenceKeyWritable.toString().substring(0, 9) + "...") + " Value: " + ((sequenceValueWritable.toString().length() < 10) ? sequenceValueWritable.toString() : sequenceValueWritable.toString().substring(0, 9) + "...")); } else { // false when at end of file WritableUtils.writeVInt(this.outStream, MessageType.END_OF_DATA.code); LOG.debug("Responded MessageType.SEQFILE_READNEXT - END_OF_DATA"); }//from w w w . ja va 2 s . co m binProtocol.flush(); } else { // no fileID stored LOG.error("MessageType.SEQFILE_READNEXT: FileID " + fileID + " not found!"); WritableUtils.writeVInt(this.outStream, MessageType.END_OF_DATA.code); LOG.debug("Responded MessageType.SEQFILE_READNEXT - END_OF_DATA"); binProtocol.flush(); } }