List of usage examples for java.io DataInput readInt
int readInt() throws IOException;
From source file:org.apache.tez.mapreduce.hadoop.MRTaskStatus.java
@Override public void readFields(DataInput in) throws IOException { taskAttemptId = TezTaskAttemptID.read(in); state = WritableUtils.readEnum(in, State.class); progress = in.readFloat();//from w w w . j a v a2 s .co m diagnostics = WritableUtils.readString(in); userStatusInfo = WritableUtils.readString(in); phase = WritableUtils.readEnum(in, Phase.class); counters = new TezCounters(); counters.readFields(in); localOutputSize = in.readLong(); startTime = in.readLong(); finishTime = in.readLong(); sortFinishTime = in.readLong(); mapFinishTime = in.readLong(); shuffleFinishTime = in.readLong(); int numFailedDependencies = in.readInt(); for (int i = 0; i < numFailedDependencies; i++) { TezTaskAttemptID taskAttemptId = TezTaskAttemptID.read(in); failedTaskDependencies.add(taskAttemptId); } }
From source file:org.apache.pig.data.DefaultTuple.java
@Override public void readFields(DataInput in) throws IOException { // Clear our fields, in case we're being reused. mFields.clear();//from ww w . j a v a 2s. c o m // Make sure it's a tuple. byte b = in.readByte(); if (b != DataType.TUPLE) { int errCode = 2112; String msg = "Unexpected data while reading tuple " + "from binary file."; throw new ExecException(msg, errCode, PigException.BUG); } // Read the number of fields int sz = in.readInt(); for (int i = 0; i < sz; i++) { try { append(DataReaderWriter.readDatum(in)); } catch (ExecException ee) { throw ee; } } }
From source file:edu.msu.cme.rdp.readseq.readers.core.SFFCore.java
public ReadBlock readReadBlock() throws IOException { try {/*from w w w. j a v a 2s . c o m*/ DataInput seqFile = super.getDataInput(); ReadBlock ret = new ReadBlock(); /* * READ BLOCK HEADER */ ret.headerLength = seqFile.readShort(); ret.nameLength = seqFile.readShort(); int tmp = (ret.headerLength << 16) | ret.nameLength; if (tmp == mftMagicNumber) { //We ended up in the index...certainly possible return null; } ret.numBases = seqFile.readInt(); ret.clipQualLeft = seqFile.readUnsignedShort(); ret.clipQualRight = seqFile.readUnsignedShort(); ret.clipAdapterLeft = seqFile.readUnsignedShort(); ret.clipAdapterRight = seqFile.readUnsignedShort(); byte[] readName = new byte[ret.nameLength]; super.read(readName); int dataOffset = ret.headerLength - (ret.nameLength + READ_BLOCK_STATIC_SIZE); if (dataOffset < 0) { throw new IOException("Illegal ReadBlock header length (" + ret.headerLength + "), it would have me seek back in to the readblock"); } seqFile.skipBytes(dataOffset); /* * READ BLOCK DATA */ byte[] flowgramIndex = new byte[ret.numBases]; byte[] bases = new byte[ret.numBases]; byte[] quality = new byte[ret.numBases]; byte[] homopolymerStretchEstimates = new byte[(commonHeader.flowLength) * 2]; super.read(homopolymerStretchEstimates); super.read(flowgramIndex); super.read(bases); super.read(quality); DataInputStream flowgramStream = new DataInputStream( new ByteArrayInputStream(homopolymerStretchEstimates)); short[] flowgrams = new short[commonHeader.flowLength]; for (int index = 0; index < commonHeader.flowLength; index++) { flowgrams[index] = flowgramStream.readShort(); } flowgramStream.close(); ret.name = new String(readName); ret.flowgrams = flowgrams; ret.flowIndex = flowgramIndex; ret.seq = new String(bases); ret.qual = quality; int bytesRead = homopolymerStretchEstimates.length + flowgramIndex.length + bases.length + quality.length; alignToBoundary(bytesRead); return ret; } catch (EOFException e) { return null; } }
From source file:com.ricemap.spateDB.core.RTree.java
/** * Reads and skips the header of the tree returning the total number of * bytes skipped from the stream. This is used as a preparatory function to * read all elements in the tree without the index part. * // w ww. j a va 2 s .co m * @param in * @return - Total number of bytes read and skipped * @throws IOException */ public static int skipHeader(InputStream in) throws IOException { DataInput dataIn = in instanceof DataInput ? (DataInput) in : new DataInputStream(in); int skippedBytes = 0; /* int treeSize = */dataIn.readInt(); skippedBytes += 4; int height = dataIn.readInt(); skippedBytes += 4; if (height == 0) { // Empty tree. No results return skippedBytes; } int degree = dataIn.readInt(); skippedBytes += 4; int nodeCount = (int) ((powInt(degree, height) - 1) / (degree - 1)); /* int elementCount = */dataIn.readInt(); skippedBytes += 4; // Skip all nodes dataIn.skipBytes(nodeCount * NodeSize); skippedBytes += nodeCount * NodeSize; return skippedBytes; }
From source file:org.cloudata.core.common.io.CObjectWritable.java
/** Read a {@link CWritable}, {@link String}, primitive type, or an array of * the preceding. *//*from w w w .java 2s. c om*/ @SuppressWarnings("unchecked") public static Object readObject(DataInput in, CObjectWritable objectWritable, CloudataConf conf, boolean arrayComponent, Class componentClass) throws IOException { String className; if (arrayComponent) { className = componentClass.getName(); } else { className = CUTF8.readString(in); //SANGCHUL // System.out.println("SANGCHUL] className:" + className); } Class<?> declaredClass = PRIMITIVE_NAMES.get(className); if (declaredClass == null) { try { declaredClass = conf.getClassByName(className); } catch (ClassNotFoundException e) { //SANGCHUL e.printStackTrace(); throw new RuntimeException("readObject can't find class[className=" + className + "]", e); } } Object instance; if (declaredClass.isPrimitive()) { // primitive types if (declaredClass == Boolean.TYPE) { // boolean instance = Boolean.valueOf(in.readBoolean()); } else if (declaredClass == Character.TYPE) { // char instance = Character.valueOf(in.readChar()); } else if (declaredClass == Byte.TYPE) { // byte instance = Byte.valueOf(in.readByte()); } else if (declaredClass == Short.TYPE) { // short instance = Short.valueOf(in.readShort()); } else if (declaredClass == Integer.TYPE) { // int instance = Integer.valueOf(in.readInt()); } else if (declaredClass == Long.TYPE) { // long instance = Long.valueOf(in.readLong()); } else if (declaredClass == Float.TYPE) { // float instance = Float.valueOf(in.readFloat()); } else if (declaredClass == Double.TYPE) { // double instance = Double.valueOf(in.readDouble()); } else if (declaredClass == Void.TYPE) { // void instance = null; } else { throw new IllegalArgumentException("Not a primitive: " + declaredClass); } } else if (declaredClass.isArray()) { // array //System.out.println("SANGCHUL] is array"); int length = in.readInt(); //System.out.println("SANGCHUL] array length : " + length); //System.out.println("Read:in.readInt():" + length); if (declaredClass.getComponentType() == Byte.TYPE) { byte[] bytes = new byte[length]; in.readFully(bytes); instance = bytes; } else if (declaredClass.getComponentType() == ColumnValue.class) { instance = readColumnValue(in, conf, declaredClass, length); } else { Class componentType = declaredClass.getComponentType(); // SANGCHUL //System.out.println("SANGCHUL] componentType : " + componentType.getName()); instance = Array.newInstance(componentType, length); for (int i = 0; i < length; i++) { Object arrayComponentInstance = readObject(in, null, conf, !componentType.isArray(), componentType); Array.set(instance, i, arrayComponentInstance); //Array.set(instance, i, readObject(in, conf)); } } } else if (declaredClass == String.class) { // String instance = CUTF8.readString(in); } else if (declaredClass.isEnum()) { // enum instance = Enum.valueOf((Class<? extends Enum>) declaredClass, CUTF8.readString(in)); } else if (declaredClass == ColumnValue.class) { //ColumnValue? ?? ?? ? ? ?. //? ? ? ? ? ? . Class instanceClass = null; try { short typeDiff = in.readShort(); if (typeDiff == TYPE_DIFF) { instanceClass = conf.getClassByName(CUTF8.readString(in)); } else { instanceClass = declaredClass; } } catch (ClassNotFoundException e) { throw new RuntimeException("readObject can't find class", e); } ColumnValue columnValue = new ColumnValue(); columnValue.readFields(in); instance = columnValue; } else { // Writable Class instanceClass = null; try { short typeDiff = in.readShort(); // SANGCHUL //System.out.println("SANGCHUL] typeDiff : " + typeDiff); //System.out.println("Read:in.readShort():" + typeDiff); if (typeDiff == TYPE_DIFF) { // SANGCHUL String classNameTemp = CUTF8.readString(in); //System.out.println("SANGCHUL] typeDiff : " + classNameTemp); instanceClass = conf.getClassByName(classNameTemp); //System.out.println("Read:UTF8.readString(in):" + instanceClass.getClass()); } else { instanceClass = declaredClass; } } catch (ClassNotFoundException e) { // SANGCHUL e.printStackTrace(); throw new RuntimeException("readObject can't find class", e); } CWritable writable = CWritableFactories.newInstance(instanceClass, conf); writable.readFields(in); //System.out.println("Read:writable.readFields(in)"); instance = writable; if (instanceClass == NullInstance.class) { // null declaredClass = ((NullInstance) instance).declaredClass; instance = null; } } if (objectWritable != null) { // store values objectWritable.declaredClass = declaredClass; objectWritable.instance = instance; } return instance; }
From source file:com.fiorano.openesb.application.aps.OutPortInst.java
/** * This is called to read this object <code>OutPortInst</code> from the * specified object of input stream./*from ww w . j a va2 s . co m*/ * * @param is DataInput object * @param versionNo Description of the Parameter * @exception IOException if an error occurs while reading bytes or while * converting them into specified Java primitive type. * @since Tifosi2.0 */ public void fromStream(DataInput is, int versionNo) throws IOException { super.fromStream(is, versionNo); m_strPortName = readUTF(is); m_strDscription = readUTF(is); m_strXSD = readUTF(is); m_strContextXSL = readUTF(is); m_strContextInfo = readUTF(is); m_transformerType = readUTF(is); m_strJavaClass = readUTF(is); m_bIsSyncRequestType = is.readBoolean(); m_bisDisabled = is.readBoolean(); int size = is.readInt(); for (int i = 0; i < size; ++i) { Param param = new Param(); param.fromStream(is, versionNo); m_params.addElement(param); } }
From source file:com.marklogic.mapreduce.test.FCheck.java
private int computeTreeChecksum(int key, DataInput in, int words) throws IOException { // System.out.println(String.format("key:%08x", key)); int cksum = CHECKSUM_SEED; // System.out.println(String.format("seed:%08x", cksum)); cksum = ((cksum + key) * CHECKSUM_STEP) & 0xffffffff; // System.out.println(String.format("start:%08x", cksum)); while (0 < words--) { int w = in.readInt(); cksum = ((cksum + w) * CHECKSUM_STEP) & 0xffffffff; // System.out.println(String.format("%08x : %08x", cksum, w)); }//from w ww . j ava 2 s. c om return cksum & 0xfffffff0; }
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 {/*w ww.ja v a 2 s . co m*/ 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:com.marklogic.mapreduce.test.FCheck.java
private int computeListChecksum(long key, DataInput in, int words) throws IOException { // System.out.println(String.format("key %08x", key)); int cksum = CHECKSUM_SEED; // System.out.println(String.format("seed %08x", cksum)); cksum = (cksum + (int) (key >> 32)) * CHECKSUM_STEP; // System.out.println(String.format("start 1 %08x", cksum)); cksum = (cksum + (int) (key)) * CHECKSUM_STEP; // System.out.println(String.format("start 2 %08x", cksum)); while (0 < words--) { cksum = (cksum + in.readInt()) * CHECKSUM_STEP; // System.out.println(String.format("step %08x", cksum)); }//from www . ja v a 2 s .c o m // System.out.println(String.format("final %08x", (cksum & // 0xfffffff0))); return cksum & 0xfffffff0; }
From source file:com.mapr.hbase.support.objects.MHRegionInfo090x.java
@Override public void readFields(DataInput in) throws IOException { super.readFields(in); this.endKey = Bytes.readByteArray(in); this.offLine = in.readBoolean(); this.regionId = in.readLong(); this.regionName = Bytes.readByteArray(in); this.regionNameStr = Bytes.toStringBinary(this.regionName); this.split = in.readBoolean(); this.startKey = Bytes.readByteArray(in); try {/*from w w w . j a va2 s. c o m*/ this.tableDesc.readFields(in); } catch (EOFException eofe) { throw new IOException("HTD not found in input buffer"); } this.hashCode = in.readInt(); }