List of usage examples for java.io DataInput readBoolean
boolean readBoolean() throws IOException;
From source file:org.apache.hadoop.mapred.TaskStatus.java
static TaskStatus createTaskStatus(DataInput in, TaskAttemptID taskId, float progress, int numSlots, State runState, String diagnosticInfo, String stateString, String taskTracker, Phase phase, Counters counters) throws IOException { boolean isMap = in.readBoolean(); return createTaskStatus(isMap, taskId, progress, numSlots, runState, diagnosticInfo, stateString, taskTracker, phase, counters); }
From source file:org.apache.hadoop.mapred.TaskStatus.java
static TaskStatus readTaskStatus(DataInput in) throws IOException { boolean isMap = in.readBoolean(); TaskStatus taskStatus = createTaskStatus(isMap); taskStatus.readFields(in);// w ww. j a v a 2 s. c o m return taskStatus; }
From source file:org.apache.hadoop.tools.DistTool.java
protected static String readString(DataInput in) throws IOException { if (in.readBoolean()) { return Text.readString(in); }/* w ww . ja v a 2 s. c om*/ return null; }
From source file:org.apache.hama.bsp.BSPTask.java
@Override public final void readFields(DataInput in) throws IOException { super.readFields(in); if (in.readBoolean()) { splitClass = Text.readString(in); if (split == null) { split = new BytesWritable(); }//from w w w . jav a 2 s .c om split.readFields(in); } }
From source file:org.apache.hama.graph.GraphJobMessage.java
@Override public void readFields(DataInput in) throws IOException { flag = in.readByte();// w w w . j a va 2 s. co m if (isVertexMessage()) { vertexId = ReflectionUtils.newInstance(VERTEX_ID_CLASS, null); vertexId.readFields(in); vertexValue = ReflectionUtils.newInstance(VERTEX_VALUE_CLASS, null); vertexValue.readFields(in); } else if (isMapMessage()) { map = new MapWritable(); map.readFields(in); } else if (isPartitioningMessage()) { //LOG.info("??? vertex"); Vertex<Writable, Writable, Writable> vertex = GraphJobRunner.newVertexInstance(VERTEX_CLASS, null); Writable vertexId = ReflectionUtils.newInstance(VERTEX_ID_CLASS, null); vertexId.readFields(in); //LOG.info(" " + vertexId.toString()); vertex.setVertexID(vertexId); if (in.readBoolean()) { Writable vertexValue = ReflectionUtils.newInstance(VERTEX_VALUE_CLASS, null); vertexValue.readFields(in); //LOG.info("" + vertexValue); vertex.setValue(vertexValue); } int size = in.readInt(); //LOG.info("?: " + size); vertex.setEdges(new ArrayList<Edge<Writable, Writable>>(size)); for (int i = 0; i < size; i++) { Writable edgeVertexID = ReflectionUtils.newInstance(VERTEX_ID_CLASS, null); edgeVertexID.readFields(in); //LOG.info(" " + edgeVertexID); Writable edgeValue = null; if (in.readBoolean()) { edgeValue = ReflectionUtils.newInstance(EDGE_VALUE_CLASS, null); edgeValue.readFields(in); } //LOG.info(": " + edgeValue); vertex.getEdges().add(new Edge<Writable, Writable>(edgeVertexID, edgeValue)); } this.vertex = vertex; //LOG.info("Vertex" + vertex); } else if (isVerticesSizeMessage()) { vertices_size = new IntWritable(); vertices_size.readFields(in); } else if (isBoundaryVertexSizeMessage()) { boundaryVertex_size = new IntWritable(); boundaryVertex_size.readFields(in); } else { vertexId = ReflectionUtils.newInstance(VERTEX_ID_CLASS, null); vertexId.readFields(in); } }
From source file:org.apache.hama.graph.Vertex.java
@Override public void readFields(DataInput in) throws IOException { if (in.readBoolean()) { if (this.vertexID == null) { this.vertexID = GraphJobRunner.createVertexIDObject(); }// w w w . j a v a2 s . com this.vertexID.readFields(in); } if (in.readBoolean()) { if (this.value == null) { this.value = GraphJobRunner.createVertexValue(); } this.value.readFields(in); } this.edges = new ArrayList<Edge<V, E>>(); if (in.readBoolean()) { int num = in.readInt(); if (num > 0) { for (int i = 0; i < num; ++i) { V vertex = GraphJobRunner.createVertexIDObject(); vertex.readFields(in); E edgeCost = null; if (in.readBoolean()) { edgeCost = GraphJobRunner.createEdgeCostObject(); edgeCost.readFields(in); } Edge<V, E> edge = new Edge<V, E>(vertex, edgeCost); this.edges.add(edge); } } } votedToHalt = in.readBoolean(); readState(in); }
From source file:org.apache.hawq.pxf.service.io.GPDBWritable.java
@Override public void readFields(DataInput in) throws IOException { /*//from w ww.j a v a 2s . c o m * extract pkt len. * * GPSQL-1107: * The DataInput might already be empty (EOF), but we can't check it beforehand. * If that's the case, pktlen is updated to -1, to mark that the object is still empty. * (can be checked with isEmpty()). */ pktlen = readPktLen(in); if (isEmpty()) { return; } /* extract the version and col cnt */ int version = in.readShort(); int curOffset = 4 + 2; int colCnt; /* !!! Check VERSION !!! */ if (version != GPDBWritable.VERSION && version != GPDBWritable.PREV_VERSION) { throw new IOException("Current GPDBWritable version(" + GPDBWritable.VERSION + ") does not match input version(" + version + ")"); } if (version == GPDBWritable.VERSION) { errorFlag = in.readByte(); curOffset += 1; } colCnt = in.readShort(); curOffset += 2; /* Extract Column Type */ colType = new int[colCnt]; DBType[] coldbtype = new DBType[colCnt]; for (int i = 0; i < colCnt; i++) { int enumType = (in.readByte()); curOffset += 1; if (enumType == DBType.BIGINT.ordinal()) { colType[i] = BIGINT.getOID(); coldbtype[i] = DBType.BIGINT; } else if (enumType == DBType.BOOLEAN.ordinal()) { colType[i] = BOOLEAN.getOID(); coldbtype[i] = DBType.BOOLEAN; } else if (enumType == DBType.FLOAT8.ordinal()) { colType[i] = FLOAT8.getOID(); coldbtype[i] = DBType.FLOAT8; } else if (enumType == DBType.INTEGER.ordinal()) { colType[i] = INTEGER.getOID(); coldbtype[i] = DBType.INTEGER; } else if (enumType == DBType.REAL.ordinal()) { colType[i] = REAL.getOID(); coldbtype[i] = DBType.REAL; } else if (enumType == DBType.SMALLINT.ordinal()) { colType[i] = SMALLINT.getOID(); coldbtype[i] = DBType.SMALLINT; } else if (enumType == DBType.BYTEA.ordinal()) { colType[i] = BYTEA.getOID(); coldbtype[i] = DBType.BYTEA; } else if (enumType == DBType.TEXT.ordinal()) { colType[i] = TEXT.getOID(); coldbtype[i] = DBType.TEXT; } else { throw new IOException("Unknown GPDBWritable.DBType ordinal value"); } } /* Extract null bit array */ byte[] nullbytes = new byte[getNullByteArraySize(colCnt)]; in.readFully(nullbytes); curOffset += nullbytes.length; boolean[] colIsNull = byteArrayToBooleanArray(nullbytes, colCnt); /* extract column value */ colValue = new Object[colCnt]; for (int i = 0; i < colCnt; i++) { if (!colIsNull[i]) { /* Skip the alignment padding */ int skipbytes = roundUpAlignment(curOffset, coldbtype[i].getAlignment()) - curOffset; for (int j = 0; j < skipbytes; j++) { in.readByte(); } curOffset += skipbytes; /* For fixed length type, increment the offset according to type type length here. * For var length type (BYTEA, TEXT), we'll read 4 byte length header and the * actual payload. */ int varcollen = -1; if (coldbtype[i].isVarLength()) { varcollen = in.readInt(); curOffset += 4 + varcollen; } else { curOffset += coldbtype[i].getTypeLength(); } switch (DataType.get(colType[i])) { case BIGINT: { colValue[i] = in.readLong(); break; } case BOOLEAN: { colValue[i] = in.readBoolean(); break; } case FLOAT8: { colValue[i] = in.readDouble(); break; } case INTEGER: { colValue[i] = in.readInt(); break; } case REAL: { colValue[i] = in.readFloat(); break; } case SMALLINT: { colValue[i] = in.readShort(); break; } /* For BYTEA column, it has a 4 byte var length header. */ case BYTEA: { colValue[i] = new byte[varcollen]; in.readFully((byte[]) colValue[i]); break; } /* For text formatted column, it has a 4 byte var length header * and it's always null terminated string. * So, we can remove the last "\0" when constructing the string. */ case TEXT: { byte[] data = new byte[varcollen]; in.readFully(data, 0, varcollen); colValue[i] = new String(data, 0, varcollen - 1, CHARSET); break; } default: throw new IOException("Unknown GPDBWritable ColType"); } } } /* Skip the ending alignment padding */ int skipbytes = roundUpAlignment(curOffset, 8) - curOffset; for (int j = 0; j < skipbytes; j++) { in.readByte(); } curOffset += skipbytes; if (errorFlag != 0) { throw new IOException("Received error value " + errorFlag + " from format"); } }
From source file:org.apache.horn.core.RecurrentLayeredNeuralNetwork.java
@Override public void readFields(DataInput input) throws IOException { super.readFields(input); this.finalLayerIdx = input.readInt(); this.dropRate = input.readFloat(); // read neuron classes int neuronClasses = input.readInt(); this.neuronClassList = Lists.newArrayList(); for (int i = 0; i < neuronClasses; ++i) { try {/*from ww w .ja va 2 s .com*/ Class<? extends Neuron> clazz = (Class<? extends Neuron>) Class.forName(input.readUTF()); neuronClassList.add(clazz); } catch (ClassNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } } // read squash functions int squashingFunctionSize = input.readInt(); this.squashingFunctionList = Lists.newArrayList(); for (int i = 0; i < squashingFunctionSize; ++i) { this.squashingFunctionList.add(FunctionFactory.createFloatFunction(WritableUtils.readString(input))); } this.recurrentStepSize = input.readInt(); this.numOutCells = input.readInt(); int recurrentLayerListSize = input.readInt(); this.recurrentLayerList = Lists.newArrayList(); for (int i = 0; i < recurrentLayerListSize; i++) { this.recurrentLayerList.add(input.readBoolean()); } // read weights and construct matrices of previous updates int numOfMatrices = input.readInt(); this.weightMatrixLists = Lists.newArrayListWithExpectedSize(this.recurrentStepSize); this.prevWeightUpdatesLists = Lists.newArrayList(); for (int step = 0; step < this.recurrentStepSize; step++) { this.weightMatrixList = Lists.newArrayList(); this.prevWeightUpdatesList = Lists.newArrayList(); for (int j = 0; j < this.layerSizeList.size() - 2; j++) { FloatMatrix matrix = FloatMatrixWritable.read(input); this.weightMatrixList.add(matrix); this.prevWeightUpdatesList.add(new DenseFloatMatrix(matrix.getRowCount(), matrix.getColumnCount())); } // if the cell has output layer, read from input if (step >= this.recurrentStepSize - this.numOutCells) { FloatMatrix matrix = FloatMatrixWritable.read(input); this.weightMatrixList.add(matrix); this.prevWeightUpdatesList.add(new DenseFloatMatrix(matrix.getRowCount(), matrix.getColumnCount())); } this.weightMatrixLists.add(this.weightMatrixList); this.prevWeightUpdatesLists.add(this.prevWeightUpdatesList); } }
From source file:org.apache.jxtadoop.ipc.ConnectionHeader.java
public void readFields(DataInput in) throws IOException { protocol = Text.readString(in); if (protocol.isEmpty()) { protocol = null;//from w ww.j a v a2s . c o m } boolean ugiPresent = in.readBoolean(); if (ugiPresent) { ugi.readFields(in); } else { ugi = null; } }
From source file:org.apache.marmotta.kiwi.io.KiWiIO.java
/** * Read a KiWiBooleanLiteral serialized with writeBooleanLiteral from a DataInput source * * @param input the source//from w ww. j a v a 2 s .c o m * @return the de-serialized KiWiBooleanLiteral * @throws IOException */ public static KiWiBooleanLiteral readBooleanLiteral(DataInput input) throws IOException { long id = input.readLong(); if (id == -1) { return null; } else { boolean content = input.readBoolean(); KiWiUriResource dtype = readURI(input); Date created = new Date(input.readLong()); KiWiBooleanLiteral r = new KiWiBooleanLiteral(content, dtype, created); r.setId(id); return r; } }