List of usage examples for java.io DataInputStream readInt
public final int readInt() throws IOException
readInt
method of DataInput
. From source file:org.apache.jackrabbit.core.persistence.bundle.util.BundleBinding.java
/** * Deserializes a <code>NodePropBundle</code> from a data input stream. * * @param in the input stream//from www.ja va2s . c o m * @param id the node id for the new bundle * @return the bundle * @throws IOException if an I/O error occurs. */ public NodePropBundle readBundle(DataInputStream in, NodeId id) throws IOException { NodePropBundle bundle = new NodePropBundle(this, id); // read version and primary type...special handling int index = in.readInt(); // get version int version = (index >> 24) & 0xff; index &= 0x00ffffff; String uri = nsIndex.indexToString(index); String local = nameIndex.indexToString(in.readInt()); Name nodeTypeName = NameFactoryImpl.getInstance().create(uri, local); // primaryType bundle.setNodeTypeName(nodeTypeName); // parentUUID bundle.setParentId(readID(in)); // definitionId in.readUTF(); // mixin types Set mixinTypeNames = new HashSet(); Name name = readIndexedQName(in); while (name != null) { mixinTypeNames.add(name); name = readIndexedQName(in); } bundle.setMixinTypeNames(mixinTypeNames); // properties name = readIndexedQName(in); while (name != null) { PropertyId pId = new PropertyId(bundle.getId(), name); // skip redundant primaryType, mixinTypes and uuid properties if (name.equals(NameConstants.JCR_PRIMARYTYPE) || name.equals(NameConstants.JCR_MIXINTYPES) || name.equals(NameConstants.JCR_UUID)) { readPropertyEntry(in, pId); name = readIndexedQName(in); continue; } NodePropBundle.PropertyEntry pState = readPropertyEntry(in, pId); bundle.addProperty(pState); name = readIndexedQName(in); } // set referenceable flag bundle.setReferenceable(in.readBoolean()); // child nodes (list of uuid/name pairs) NodeId childId = readID(in); while (childId != null) { bundle.addChildNodeEntry(readQName(in), childId); childId = readID(in); } // read modcount, since version 1.0 if (version >= VERSION_1) { bundle.setModCount(readModCount(in)); } // read shared set, since version 2.0 Set sharedSet = new HashSet(); if (version >= VERSION_2) { // shared set (list of parent uuids) NodeId parentId = readID(in); while (parentId != null) { sharedSet.add(parentId); parentId = readID(in); } } bundle.setSharedSet(sharedSet); return bundle; }
From source file:org.apache.carbondata.core.util.CarbonUtil.java
/** * Read level metadata file and return cardinality * * @param levelPath/* w w w . j a v a 2s . c om*/ * @return * @throws IOException */ public static int[] getCardinalityFromLevelMetadataFile(String levelPath) throws IOException { DataInputStream dataInputStream = null; int[] cardinality = null; try { if (FileFactory.isFileExist(levelPath, FileFactory.getFileType(levelPath))) { dataInputStream = FileFactory.getDataInputStream(levelPath, FileFactory.getFileType(levelPath)); cardinality = new int[dataInputStream.readInt()]; for (int i = 0; i < cardinality.length; i++) { cardinality[i] = dataInputStream.readInt(); } } } finally { closeStreams(dataInputStream); } return cardinality; }
From source file:org.apache.mele.embedded.HadoopQueueEmbedded.java
private boolean ackCheck() throws IOException { LOG.info("Starting ack check"); BitSet bitSet = new BitSet(); FileSystem fileSystem = null; try {// w w w.ja va 2 s. c o m _ackLock.lock(); _ackOutputStream.close(); fileSystem = newFileSystem(_file); FileStatus fileStatus = fileSystem.getFileStatus(_file); long dataLength = fileStatus.getLen(); long totalAckLength = getTotalAckLength(fileSystem); if (!couldContainAllAcks(totalAckLength)) { LOG.info("Existing early [" + totalAckLength + "] because [" + totalAckLength % 12 + "]"); return false; } for (Path ackFile : _ackFiles) { LOG.info("Starting ack check for file [" + ackFile + "]"); DFSInputStream inputStream = null; try { inputStream = getDFS(fileSystem.open(ackFile)); long length = inputStream.getFileLength(); DataInputStream dataInputStream = new DataInputStream(inputStream); while (length > 0) { int pos = (int) dataInputStream.readLong(); // @TODO check position // 4 bytes for storing the length of the message int len = dataInputStream.readInt() + 4; bitSet.set(pos, pos + len); length -= 12; } if (bitSet.cardinality() == dataLength) { return true; } } finally { if (inputStream != null) { inputStream.close(); } } } return false; } finally { reopenAckFile(fileSystem); _ackLock.unlock(); if (fileSystem != null) { fileSystem.close(); } } }
From source file:org.apache.jackrabbit.core.persistence.bundle.util.BundleBinding.java
/** * Checks a <code>NodePropBundle</code> from a data input stream. * * @param in the input stream/*from w w w. j ava 2s. c om*/ * @return <code>true</code> if the data is valid; * <code>false</code> otherwise. */ public boolean checkBundle(DataInputStream in) { int version; // primaryType & version try { // read version and primary type...special handling int index = in.readInt(); // get version version = (index >> 24) & 0xff; index &= 0x00ffffff; String uri = nsIndex.indexToString(index); String local = nameIndex.indexToString(in.readInt()); Name nodeTypeName = NameFactoryImpl.getInstance().create(uri, local); log.debug("Serialzation Version: " + version); log.debug("NodeTypeName: " + nodeTypeName); } catch (IOException e) { log.error("Error while reading NodeTypeName: " + e); return false; } try { NodeId parentId = readID(in); log.debug("ParentUUID: " + parentId); } catch (IOException e) { log.error("Error while reading ParentUUID: " + e); return false; } try { String definitionId = in.readUTF(); log.debug("DefinitionId: " + definitionId); } catch (IOException e) { log.error("Error while reading DefinitionId: " + e); return false; } try { Name mixinName = readIndexedQName(in); while (mixinName != null) { log.debug("MixinTypeName: " + mixinName); mixinName = readIndexedQName(in); } } catch (IOException e) { log.error("Error while reading MixinTypes: " + e); return false; } try { Name propName = readIndexedQName(in); while (propName != null) { log.debug("PropertyName: " + propName); if (!checkPropertyState(in)) { return false; } propName = readIndexedQName(in); } } catch (IOException e) { log.error("Error while reading property names: " + e); return false; } try { boolean hasUUID = in.readBoolean(); log.debug("hasUUID: " + hasUUID); } catch (IOException e) { log.error("Error while reading 'hasUUID': " + e); return false; } try { NodeId cneId = readID(in); while (cneId != null) { Name cneName = readQName(in); log.debug("ChildNodentry: " + cneId + ":" + cneName); cneId = readID(in); } } catch (IOException e) { log.error("Error while reading child node entry: " + e); return false; } if (version >= VERSION_1) { try { short modCount = readModCount(in); log.debug("modCount: " + modCount); } catch (IOException e) { log.error("Error while reading mod cout: " + e); return false; } } return true; }
From source file:org.apache.jackrabbit.core.persistence.bundle.util.BundleBinding.java
/** * Checks a <code>NodePropBundle</code> from a data input stream. * * @param in the input stream//from w ww .j a v a2 s . c om * @return <code>true</code> if the data is valid; * <code>false</code> otherwise. */ public boolean checkBundle(DataInputStream in) { int version; // primaryType & version try { // read version and primary type...special handling int index = in.readInt(); // get version version = (index >> 24) & 0xff; index &= 0x00ffffff; String uri = nsIndex.indexToString(index); String local = nameIndex.indexToString(in.readInt()); Name nodeTypeName = NameFactoryImpl.getInstance().create(uri, local); log.debug("Serialzation Version: " + version); log.debug("NodeTypeName: " + nodeTypeName); } catch (IOException e) { log.error("Error while reading NodeTypeName: " + e); return false; } try { UUID parentUuid = readUUID(in); log.debug("ParentUUID: " + parentUuid); } catch (IOException e) { log.error("Error while reading ParentUUID: " + e); return false; } try { String definitionId = in.readUTF(); log.debug("DefinitionId: " + definitionId); } catch (IOException e) { log.error("Error while reading DefinitionId: " + e); return false; } try { Name mixinName = readIndexedQName(in); while (mixinName != null) { log.debug("MixinTypeName: " + mixinName); mixinName = readIndexedQName(in); } } catch (IOException e) { log.error("Error while reading MixinTypes: " + e); return false; } try { Name propName = readIndexedQName(in); while (propName != null) { log.debug("PropertyName: " + propName); if (!checkPropertyState(in)) { return false; } propName = readIndexedQName(in); } } catch (IOException e) { log.error("Error while reading property names: " + e); return false; } try { boolean hasUUID = in.readBoolean(); log.debug("hasUUID: " + hasUUID); } catch (IOException e) { log.error("Error while reading 'hasUUID': " + e); return false; } try { UUID cneUUID = readUUID(in); while (cneUUID != null) { Name cneName = readQName(in); log.debug("ChildNodentry: " + cneUUID + ":" + cneName); cneUUID = readUUID(in); } } catch (IOException e) { log.error("Error while reading child node entry: " + e); return false; } if (version >= VERSION_1) { try { short modCount = readModCount(in); log.debug("modCount: " + modCount); } catch (IOException e) { log.error("Error while reading mod cout: " + e); return false; } } return true; }
From source file:org.apache.jackrabbit.core.persistence.bundle.util.BundleBinding.java
/** * Deserializes a <code>PropertyState</code> from the data input stream. * * @param in the input stream/* w w w . j a va2 s . c o m*/ * @param id the property id for the new property entry * @return the property entry * @throws IOException if an I/O error occurs. */ public NodePropBundle.PropertyEntry readPropertyEntry(DataInputStream in, PropertyId id) throws IOException { NodePropBundle.PropertyEntry entry = new NodePropBundle.PropertyEntry(id); // type and modcount int type = in.readInt(); entry.setModCount((short) ((type >> 16) & 0x0ffff)); type &= 0x0ffff; entry.setType(type); // multiValued entry.setMultiValued(in.readBoolean()); // definitionId entry.setPropDefId(PropDefId.valueOf(in.readUTF())); // values int count = in.readInt(); // count InternalValue[] values = new InternalValue[count]; String[] blobIds = new String[count]; for (int i = 0; i < count; i++) { InternalValue val; switch (type) { case PropertyType.BINARY: int size = in.readInt(); if (size == BINARY_IN_DATA_STORE) { val = InternalValue.create(dataStore, in.readUTF()); } else if (size == BINARY_IN_BLOB_STORE) { blobIds[i] = in.readUTF(); try { if (blobStore instanceof ResourceBasedBLOBStore) { val = InternalValue .create(((ResourceBasedBLOBStore) blobStore).getResource(blobIds[i])); } else { val = InternalValue.create(blobStore.get(blobIds[i])); } } catch (IOException e) { if (errorHandling.ignoreMissingBlobs()) { log.warn("Ignoring error while reading blob-resource: " + e); val = InternalValue.create(new byte[0]); } else { throw e; } } catch (Exception e) { throw new IOException("Unable to create property value: " + e.toString()); } } else { // short values into memory byte[] data = new byte[size]; in.readFully(data); val = InternalValue.create(data); } break; case PropertyType.DOUBLE: val = InternalValue.create(in.readDouble()); break; case PropertyType.DECIMAL: val = InternalValue.create(readDecimal(in)); break; case PropertyType.LONG: val = InternalValue.create(in.readLong()); break; case PropertyType.BOOLEAN: val = InternalValue.create(in.readBoolean()); break; case PropertyType.NAME: val = InternalValue.create(readQName(in)); break; case PropertyType.WEAKREFERENCE: case PropertyType.REFERENCE: val = InternalValue.create(readID(in)); break; default: // because writeUTF(String) has a size limit of 64k, // Strings are serialized as <length><byte[]> int len = in.readInt(); byte[] bytes = new byte[len]; in.readFully(bytes); val = InternalValue.valueOf(new String(bytes, "UTF-8"), type); } values[i] = val; } entry.setValues(values); entry.setBlobIds(blobIds); return entry; }
From source file:org.apache.jackrabbit.core.persistence.bundle.util.BundleBinding.java
/** * Deserializes a <code>PropertyState</code> from the data input stream. * * @param in the input stream//from ww w. j av a2 s . c o m * @param id the property id for the new property entry * @return the property entry * @throws IOException if an I/O error occurs. */ public NodePropBundle.PropertyEntry readPropertyEntry(DataInputStream in, PropertyId id) throws IOException { NodePropBundle.PropertyEntry entry = new NodePropBundle.PropertyEntry(id); // type and modcount int type = in.readInt(); entry.setModCount((short) ((type >> 16) & 0x0ffff)); type &= 0x0ffff; entry.setType(type); // multiValued entry.setMultiValued(in.readBoolean()); // definitionId entry.setPropDefId(PropDefId.valueOf(in.readUTF())); // values int count = in.readInt(); // count InternalValue[] values = new InternalValue[count]; String[] blobIds = new String[count]; for (int i = 0; i < count; i++) { InternalValue val; switch (type) { case PropertyType.BINARY: int size = in.readInt(); if (size == BINARY_IN_DATA_STORE) { val = InternalValue.create(dataStore, in.readUTF()); } else if (size == BINARY_IN_BLOB_STORE) { blobIds[i] = in.readUTF(); try { if (blobStore instanceof ResourceBasedBLOBStore) { val = InternalValue .create(((ResourceBasedBLOBStore) blobStore).getResource(blobIds[i])); } else { val = InternalValue.create(blobStore.get(blobIds[i])); } } catch (IOException e) { if (errorHandling.ignoreMissingBlobs()) { log.warn("Ignoring error while reading blob-resource: " + e); val = InternalValue.create(new byte[0]); } else { throw e; } } catch (Exception e) { throw new IOException("Unable to create property value: " + e.toString()); } } else { // short values into memory byte[] data = new byte[size]; in.readFully(data); val = InternalValue.create(data); } break; case PropertyType.DOUBLE: val = InternalValue.create(in.readDouble()); break; case PropertyType.DECIMAL: val = InternalValue.create(readDecimal(in)); break; case PropertyType.LONG: val = InternalValue.create(in.readLong()); break; case PropertyType.BOOLEAN: val = InternalValue.create(in.readBoolean()); break; case PropertyType.NAME: val = InternalValue.create(readQName(in)); break; case PropertyType.WEAKREFERENCE: case PropertyType.REFERENCE: val = InternalValue.create(readUUID(in)); break; default: // because writeUTF(String) has a size limit of 64k, // Strings are serialized as <length><byte[]> int len = in.readInt(); byte[] bytes = new byte[len]; in.readFully(bytes); val = InternalValue.valueOf(new String(bytes, "UTF-8"), type); } values[i] = val; } entry.setValues(values); entry.setBlobIds(blobIds); return entry; }
From source file:org.apache.jackrabbit.core.persistence.bundle.util.BundleBinding.java
/** * Deserializes a <code>NodePropBundle</code> from a data input stream. * * @param in the input stream//from ww w. ja va 2 s . c o m * @param id the node id for the new bundle * @return the bundle * @throws IOException if an I/O error occurs. */ public NodePropBundle readBundle(DataInputStream in, NodeId id) throws IOException { NodePropBundle bundle = new NodePropBundle(this, id); // read version and primary type...special handling int index = in.readInt(); // get version int version = (index >> 24) & 0xff; index &= 0x00ffffff; String uri = nsIndex.indexToString(index); String local = nameIndex.indexToString(in.readInt()); Name nodeTypeName = NameFactoryImpl.getInstance().create(uri, local); // primaryType bundle.setNodeTypeName(nodeTypeName); // parentUUID bundle.setParentId(readID(in)); // definitionId bundle.setNodeDefId(NodeDefId.valueOf(in.readUTF())); // mixin types Set<Name> mixinTypeNames = new HashSet<Name>(); Name name = readIndexedQName(in); while (name != null) { mixinTypeNames.add(name); name = readIndexedQName(in); } bundle.setMixinTypeNames(mixinTypeNames); // properties name = readIndexedQName(in); while (name != null) { PropertyId pId = new PropertyId(bundle.getId(), name); // skip redundant primaryType, mixinTypes and uuid properties if (name.equals(NameConstants.JCR_PRIMARYTYPE) || name.equals(NameConstants.JCR_MIXINTYPES) || name.equals(NameConstants.JCR_UUID)) { readPropertyEntry(in, pId); name = readIndexedQName(in); continue; } NodePropBundle.PropertyEntry pState = readPropertyEntry(in, pId); bundle.addProperty(pState); name = readIndexedQName(in); } // set referenceable flag bundle.setReferenceable(in.readBoolean()); // child nodes (list of uuid/name pairs) NodeId childId = readID(in); while (childId != null) { bundle.addChildNodeEntry(readQName(in), childId); childId = readID(in); } // read modcount, since version 1.0 if (version >= VERSION_1) { bundle.setModCount(readModCount(in)); } // read shared set, since version 2.0 Set<NodeId> sharedSet = new HashSet<NodeId>(); if (version >= VERSION_2) { // shared set (list of parent uuids) NodeId parentId = readID(in); while (parentId != null) { sharedSet.add(parentId); parentId = readID(in); } } bundle.setSharedSet(sharedSet); return bundle; }
From source file:org.apache.hadoop.yarn.server.resourcemanager.recovery.ZKRMStateStore.java
private void loadRMSequentialNumberState(RMState rmState) throws Exception { byte[] seqData = getData(dtSequenceNumberPath); if (seqData != null) { ByteArrayInputStream seqIs = new ByteArrayInputStream(seqData); DataInputStream seqIn = new DataInputStream(seqIs); try {//from ww w .ja v a 2 s . c o m rmState.rmSecretManagerState.dtSequenceNumber = seqIn.readInt(); } finally { seqIn.close(); } } }
From source file:PersistentRankingMIDlet.java
public BookInfo getBookInfo(int id) throws RecordStoreException, IOException { byte[] bytes = store.getRecord(id); DataInputStream is = new DataInputStream(new ByteArrayInputStream(bytes)); String isbn = is.readUTF();//from www. java2s .c o m BookInfo info = new BookInfo(isbn); info.id = id; info.title = is.readUTF(); info.ranking = is.readInt(); info.reviews = is.readInt(); info.lastRanking = is.readInt(); info.lastReviews = is.readInt(); return info; }