List of usage examples for java.io DataInput readByte
byte readByte() throws IOException;
From source file:com.mapr.hbase.support.objects.MHRegionInfo.java
@Override public void readFields(DataInput in) throws IOException { // Read the single version byte. We don't ask the super class do it // because freaks out if its not the current classes' version. This method // can deserialize version 0 and version 1 of HRI. byte version = in.readByte(); if (version == 0) { // This is the old HRI that carried an HTD. Migrate it. The below // was copied from the old 0.90 HRI readFields. 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 {/*ww w. ja v a 2 s . c o m*/ tableDesc = new HTableDescriptor(); tableDesc.readFields(in); this.tableName = tableDesc.getName(); } catch (EOFException eofe) { throw new IOException("HTD not found in input buffer", eofe); } this.hashCode = in.readInt(); } else if (getVersion() == version) { 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); this.tableName = Bytes.readByteArray(in); this.hashCode = in.readInt(); } else { throw new IOException("Non-migratable/unknown version=" + getVersion()); } }
From source file:edu.msu.cme.rdp.readseq.readers.core.SFFCore.java
private void parseCommonHeader() throws IOException { if (commonHeader != null) { throw new IOException("Common header already initialized"); }/*ww w . j a va 2 s.co m*/ commonHeader = new CommonHeader(); DataInput seqFile = super.getDataInput(); commonHeader.magicNumber = seqFile.readInt(); if (commonHeader.magicNumber != SeqUtils.SFF_MAGIC_NUMBER) { throw new IOException("Not an SFF File"); } commonHeader.version = seqFile.readInt(); if (commonHeader.version != 1) { throw new IOException("Cannot parse v" + commonHeader.version + " sff files"); } commonHeader.indexOffset = seqFile.readLong(); commonHeader.indexLength = seqFile.readInt(); commonHeader.numReads = seqFile.readInt(); commonHeader.headerLength = seqFile.readShort(); commonHeader.keyLength = seqFile.readShort(); commonHeader.flowLength = seqFile.readShort(); commonHeader.flowgramFormat = seqFile.readByte(); byte[] flow = new byte[commonHeader.flowLength]; super.read(flow); commonHeader.flow = new String(flow); byte[] key = new byte[commonHeader.keyLength]; super.read(key); commonHeader.key = new String(key); int readBytes = COMMON_HEADER_STATIC_SIZE + flow.length + key.length; alignToBoundary(readBytes); if (super.isSeekable() && commonHeader.indexOffset > commonHeader.headerLength) { readIndex(); } }
From source file:com.marklogic.tree.ExpandedTree.java
@Override public void readFields(DataInput in) throws IOException { uriKey = in.readLong();//from ww w.j av a 2 s . c om uniqKey = in.readLong(); linkKey = in.readLong(); numKeys = in.readInt(); if (numKeys > 0) { keys = new long[numKeys]; for (int i = 0; i < numKeys; i++) { keys[i] = in.readLong(); } } int atomDataLen = in.readInt(); if (atomDataLen > 0) { atomData = new byte[atomDataLen]; for (int i = 0; i < atomDataLen; i++) { atomData[i] = in.readByte(); } } atomLimit = in.readInt(); if (atomLimit > 0) { atomIndex = new int[atomLimit + 1]; for (int i = 0; i < atomLimit + 1; i++) { atomIndex[i] = in.readInt(); } } int nodeNameNameAtomLen = in.readInt(); if (nodeNameNameAtomLen > 0) { nodeNameNameAtom = new int[nodeNameNameAtomLen]; nodeNameNamespaceAtom = new int[nodeNameNameAtomLen]; for (int i = 0; i < nodeNameNameAtomLen; i++) { nodeNameNameAtom[i] = in.readInt(); nodeNameNamespaceAtom[i] = in.readInt(); } } numNodeReps = in.readInt(); if (numNodeReps > 0) { nodes = new NodeImpl[numNodeReps]; nodeOrdinal = new long[numNodeReps]; nodeKind = new byte[numNodeReps]; nodeRepID = new int[numNodeReps]; nodeParentNodeRepID = new int[numNodeReps]; for (int i = 0; i < numNodeReps; i++) { nodeOrdinal[i] = in.readLong(); nodeKind[i] = in.readByte(); nodeRepID[i] = in.readInt(); nodeParentNodeRepID[i] = in.readInt(); } } int numElemNodeReps = in.readInt(); if (numElemNodeReps > 0) { elemNodeNodeNameRepID = new int[numElemNodeReps]; elemNodeAttrNodeRepID = new int[numElemNodeReps]; elemNodeChildNodeRepID = new int[numElemNodeReps]; elemNodeElemDeclRepID = new int[numElemNodeReps]; elemNodeNumAttributes = new int[numElemNodeReps]; elemNodeNumDefaultAttrs = new int[numElemNodeReps]; elemNodeNumChildren = new int[numElemNodeReps]; elemNodeFlags = new int[numElemNodeReps]; for (int i = 0; i < numElemNodeReps; i++) { elemNodeNodeNameRepID[i] = in.readInt(); elemNodeAttrNodeRepID[i] = in.readInt(); elemNodeChildNodeRepID[i] = in.readInt(); elemNodeElemDeclRepID[i] = in.readInt(); elemNodeNumAttributes[i] = in.readInt(); elemNodeNumDefaultAttrs[i] = in.readInt(); elemNodeNumChildren[i] = in.readInt(); elemNodeFlags[i] = in.readInt(); } } int numAttrNodeReps = in.readInt(); if (numAttrNodeReps > 0) { attrNodeNodeNameRepID = new int[numAttrNodeReps]; attrNodeTextRepID = new int[numAttrNodeReps]; attrNodeAttrDeclRepID = new int[numAttrNodeReps]; for (int i = 0; i < numAttrNodeReps; i++) { attrNodeNodeNameRepID[i] = in.readInt(); attrNodeTextRepID[i] = in.readInt(); attrNodeAttrDeclRepID[i] = in.readInt(); } } numLinkNodeReps = in.readInt(); if (numLinkNodeReps > 0) { linkNodeKey = new long[numLinkNodeReps]; linkNodeNodeCount = new long[numLinkNodeReps]; linkNodeNodeNameRepID = new int[numLinkNodeReps]; linkNodeNodeRepID = new int[numLinkNodeReps]; for (int i = 0; i < numLinkNodeReps; i++) { linkNodeKey[i] = in.readLong(); linkNodeNodeCount[i] = in.readLong(); linkNodeNodeNameRepID[i] = in.readInt(); linkNodeNodeRepID[i] = in.readInt(); } } int numDocNodeReps = in.readInt(); if (numDocNodeReps > 0) { docNodeTextRepID = new int[numDocNodeReps]; docNodeChildNodeRepID = new int[numDocNodeReps]; docNodeNumChildren = new int[numDocNodeReps]; for (int i = 0; i < numDocNodeReps; i++) { docNodeTextRepID[i] = in.readInt(); docNodeChildNodeRepID[i] = in.readInt(); docNodeNumChildren[i] = in.readInt(); } } int numPINodeReps = in.readInt(); if (numPINodeReps > 0) { piNodeTargetAtom = new int[numPINodeReps]; piNodeTextRepID = new int[numPINodeReps]; for (int i = 0; i < numPINodeReps; i++) { piNodeTargetAtom[i] = in.readInt(); piNodeTextRepID[i] = in.readInt(); } } numNSNodeReps = in.readInt(); if (numNSNodeReps > 0) { nsNodeOrdinal = new long[numNSNodeReps]; nsNodePrevNSNodeRepID = new int[numNSNodeReps]; nsNodePrefixAtom = new int[numNSNodeReps]; nsNodeUriAtom = new int[numNSNodeReps]; for (int i = 0; i < numNSNodeReps; i++) { nsNodeOrdinal[i] = in.readLong(); nsNodePrevNSNodeRepID[i] = in.readInt(); nsNodePrefixAtom[i] = in.readInt(); nsNodeUriAtom[i] = in.readInt(); } } // skip permission node since it's not exposed to the API uriTextRepID = in.readInt(); colsTextRepID = in.readInt(); numTextReps = in.readInt(); if (numTextReps > 0) { textReps = new int[numTextReps]; for (int i = 0; i < numTextReps; i++) { textReps[i] = in.readInt(); } } int numArrayNodeReps = in.readInt(); if (numArrayNodeReps > 0) { arrayNodeTextRepID = new int[numArrayNodeReps]; arrayNodeChildNodeRepID = new int[numArrayNodeReps]; arrayNodeNumChildren = new int[numArrayNodeReps]; for (int i = 0; i < numArrayNodeReps; i++) { arrayNodeTextRepID[i] = in.readInt(); arrayNodeChildNodeRepID[i] = in.readInt(); arrayNodeNumChildren[i] = in.readInt(); } } int numDoubles = in.readInt(); if (numDoubles > 0) { doubles = new double[numDoubles]; for (int i = 0; i < numDoubles; i++) { doubles[i] = in.readDouble(); } } }
From source file:dk.statsbiblioteket.util.LineReaderTest.java
public void testSample(String type, DataInput in) throws Exception { assertEquals("Int 1 should work for " + type, 12345, in.readInt()); assertEquals("Int 2 should work for " + type, -87, in.readInt()); assertEquals("Long should work for " + type, 123456789L, in.readLong()); assertEquals("String 1 should work for " + type, "Hello World!", in.readLine()); assertEquals("String 2 should work for " + type, "Another world", in.readLine()); assertEquals("Float should work for " + type, 0.5f, in.readFloat()); assertEquals("Boolean 1 should work for " + type, true, in.readBoolean()); assertEquals("Boolean 2 should work for " + type, false, in.readBoolean()); assertEquals("Byte 1 should work for " + type, (byte) 12, in.readByte()); assertEquals("Byte 2 should work for " + type, (byte) -12, in.readByte()); assertEquals("Unsigned byte should work for " + type, 129, in.readUnsignedByte()); assertEquals("Short should work for " + type, -4567, in.readShort()); byte[] loaded = new byte[5]; byte[] expected = new byte[] { (byte) 'A', (byte) 'S', (byte) 'C', (byte) 'I', (byte) 'I' }; in.readFully(loaded);/*w w w . j av a 2 s . c o m*/ for (int i = 0; i < loaded.length; i++) { assertEquals("Byte-stored string should be equal at byte " + i + " for " + type, expected[i], loaded[i]); } }
From source file:com.ebay.erl.mobius.core.model.Tuple.java
/** * Deserialize the tuple from the input/*from w w w. j a va2 s. co m*/ * <code>in</code>. */ @Override public void readFields(DataInput in) throws IOException { if (this.values == null) { this.values = new ArrayList<Object>(); } else this.values.clear(); int columns_nbrs = in.readInt(); ReadFieldImpl read_impl = new ReadFieldImpl(this.values, in, this.conf); for (int i = 0; i < columns_nbrs; i++) { byte type = in.readByte(); read_impl.handle(type); } }
From source file:com.ibm.bi.dml.runtime.matrix.data.MatrixBlock.java
@Override public void readFields(DataInput in) throws IOException { //read basic header (int rlen, int clen, byte type) rlen = in.readInt();/*from ww w. j av a 2 s . c om*/ clen = in.readInt(); byte bformat = in.readByte(); //check type information if (bformat < 0 || bformat >= BlockType.values().length) throw new IOException( "invalid format: '" + bformat + "' (need to be 0-" + BlockType.values().length + ")."); BlockType format = BlockType.values()[bformat]; try { switch (format) { case ULTRA_SPARSE_BLOCK: nonZeros = readNnzInfo(in, true); sparse = evalSparseFormatInMemory(rlen, clen, nonZeros); cleanupBlock(true, true); //clean all if (sparse) readUltraSparseBlock(in); else readUltraSparseToDense(in); break; case SPARSE_BLOCK: nonZeros = readNnzInfo(in, false); sparse = evalSparseFormatInMemory(rlen, clen, nonZeros); cleanupBlock(sparse, !sparse); if (sparse) readSparseBlock(in); else readSparseToDense(in); break; case DENSE_BLOCK: sparse = false; cleanupBlock(false, true); //reuse dense readDenseBlock(in); //always dense in-mem if dense on disk break; case EMPTY_BLOCK: sparse = true; cleanupBlock(true, true); //clean all nonZeros = 0; break; } } catch (DMLRuntimeException ex) { throw new IOException("Error reading block of type '" + format.toString() + "'.", ex); } }
From source file:org.ambud.marauder.source.ids.pcap.layer3.ARP.java
@Override public void decode(DataInput di, EtherFrame parent) throws IOException { this.parent = parent; this.hardType = di.readShort(); this.protoType = di.readShort(); this.hardSize = di.readByte(); this.protoAddrSize = di.readByte(); this.opCode = di.readShort(); di.readFully(senderEthAddr);/* www. j av a2 s . co m*/ this.senderIP = di.readInt(); di.readFully(targetEthAddr); this.targetIP = di.readInt(); }
From source file:org.ambud.marauder.source.ids.pcap.layer3.IPv6.java
@Override public void decode(DataInput di, EtherFrame parent) throws IOException { this.parent = parent; byte[] tempBytes = new byte[4]; di.readFully(tempBytes);/*from w w w . j av a 2 s.c o m*/ this.version = (byte) ((tempBytes[0] >> 4) & 0xff); this.trafficClass = (byte) ((tempBytes[0] << 4) | ((tempBytes[1] >> 4) & 0xff)); this.flowLbl = (byte) ((((int) (tempBytes[1] << 4) & 0xffff) << 16) | (((short) tempBytes[2] << 8) & 0xff) | (tempBytes[3] & 0xff)); this.payloadLength = EtherFrame.readShort(di); this.nextHdr = di.readByte(); this.hopLimit = di.readByte(); di.readFully(this.srcIP); di.readFully(this.dstIP); decodeNextLayer(di); }
From source file:org.apache.cassandra.utils.ByteBufferUtil.java
private static int readShortLength(DataInput in) throws IOException { int length = (in.readByte() & 0xFF) << 8; return length | (in.readByte() & 0xFF); }
From source file:org.apache.geode.internal.cache.DiskInitFile.java
static long readDiskRegionID(DataInput dis) throws IOException { int bytesToRead = dis.readUnsignedByte(); if (bytesToRead <= DiskStoreImpl.MAX_RESERVED_DRID && bytesToRead >= DiskStoreImpl.MIN_RESERVED_DRID) { long result = dis.readByte(); // we want to sign extend this first byte bytesToRead--;/*from ww w . ja v a 2 s .co m*/ while (bytesToRead > 0) { result <<= 8; result |= dis.readUnsignedByte(); // no sign extension bytesToRead--; } return result; } else { return bytesToRead; } }