List of usage examples for java.io DataInputStream readLong
public final long readLong() throws IOException
readLong
method of DataInput
. From source file:mitm.common.security.password.PBEncryptionParameters.java
private void fromByteArray(byte[] encoded) throws IOException { ByteArrayInputStream bis = new ByteArrayInputStream(encoded); DataInputStream in = new DataInputStream(bis); long version = in.readLong(); if (version != serialVersionUID) { throw new SerializationException("Version expected '" + serialVersionUID + "' but got '" + version); }/*from w ww. j av a2 s . c om*/ int saltSize = in.readInt(); this.salt = new byte[saltSize]; in.readFully(salt); this.iterationCount = in.readInt(); int encryptedSize = in.readInt(); this.encryptedData = new byte[encryptedSize]; in.readFully(encryptedData); }
From source file:org.calrissian.accumulorecipes.commons.support.qfd.KeyToAttributeStoreWholeColFXform.java
@Override public V apply(Map.Entry<Key, Value> keyValueEntry) { try {//from w w w.ja v a 2 s . c o m B entry = null; List<Map.Entry<Key, Value>> groupedKVs = decodeRow(keyValueEntry.getKey(), keyValueEntry.getValue()); for (Map.Entry<Key, Value> groupedEvent : groupedKVs) { String[] colQParts = splitPreserveAllTokens(groupedEvent.getKey().getColumnQualifier().toString(), NULL_BYTE); String[] aliasValue = splitPreserveAllTokens(colQParts[1], ONE_BYTE); String visibility = groupedEvent.getKey().getColumnVisibility().toString(); try { ByteArrayInputStream bais = new ByteArrayInputStream(groupedEvent.getValue().get()); DataInputStream dis = new DataInputStream(bais); dis.readLong(); // minimum expiration of keys and values long timestamp = dis.readLong(); if (entry == null) entry = buildEntryFromKey( new Key(keyValueEntry.getKey().getRow(), keyValueEntry.getKey().getColumnFamily(), keyValueEntry.getKey().getColumnQualifier(), timestamp)); int length = dis.readInt(); byte[] metaBytes = new byte[length]; dis.readFully(metaBytes); Map<String, String> meta = metadataSerDe.deserialize(metaBytes); Map<String, String> metadata = (length == 0 ? new HashMap<String, String>() : new HashMap<String, String>(meta)); setVisibility(metadata, visibility); Attribute attribute = new Attribute(colQParts[0], typeRegistry.decode(aliasValue[0], aliasValue[1]), metadata); entry.attr(attribute); } catch (Exception e) { log.error("There was an error deserializing the metadata for a attribute", e); } } return entry.build(); } catch (IOException e) { throw new RuntimeException(e); } }
From source file:org.nuxeo.apidoc.introspection.BundleIdReader.java
public synchronized void load(File file) { DataInputStream in = null; try {//from w w w. ja v a 2s .c o m in = new DataInputStream(new BufferedInputStream(new FileInputStream(file))); count = in.readLong(); int size = in.readInt(); for (int i = 0; i < size; i++) { String key = in.readUTF(); long id = in.readLong(); ids.put(key, Long.valueOf(id)); } } catch (FileNotFoundException e) { // do nothing - this is the first time the runtime is started } catch (IOException e) { log.error("The bundle.ids file is corrupted. Resetting bundle ids."); } finally { if (in != null) { try { in.close(); } catch (IOException e) { } } } }
From source file:org.jenkinsci.plugins.workflow.support.pickles.serialization.RiverReader.java
private int parseHeader(DataInputStream din) throws IOException { if (din.readLong() != RiverWriter.HEADER) throw new IOException("Invalid stream header"); short v = din.readShort(); if (v != 1)//from w w w .j a va 2 s . co m throw new IOException("Unexpected stream version: " + v); return din.readInt(); }
From source file:de.iritgo.aktario.jdbc.JDBCIDGenerator.java
/** * Read the object attributes from an input stream. * * @param stream The input stream.//w w w .j a v a 2 s. c o m */ public void readObject(InputStream stream) throws IOException, ClassNotFoundException { DataInputStream dataStream = new DataInputStream(stream); id = dataStream.readLong(); }
From source file:org.nuxeo.osgi.BundleIdGenerator.java
public synchronized void load(File file) { DataInputStream in = null; try {//w w w . j a v a 2s. c o m in = new DataInputStream(new BufferedInputStream(new FileInputStream(file))); count = in.readLong(); int size = in.readInt(); for (int i = 0; i < size; i++) { String key = in.readUTF(); long id = in.readLong(); ids.put(key, id); } } catch (FileNotFoundException e) { // do nothing - this is the first time the runtime is started } catch (IOException e) { // may be the file is corrupted file.delete(); log.error("The bundle.ids file is corrupted. reseting bundle ids."); } finally { if (in != null) { try { in.close(); } catch (IOException e) { } } } }
From source file:org.hydracache.server.data.versioning.IncrementVersionFactory.java
@Override public Version readObject(final DataInputStream dataIn) throws IOException { Validate.notNull(dataIn, "dataIn can not be null"); final Identity nodeId = getIdentityMarshaller().readObject(dataIn); final long value = dataIn.readLong(); return new Increment(nodeId, value); }
From source file:com.csipsimple.backup.SipProfilesHelper.java
@Override public void performBackup(ParcelFileDescriptor oldState, BackupDataOutput data, ParcelFileDescriptor newState) { boolean forceBackup = (oldState == null); long fileModified = databaseFile.lastModified(); try {/*from w w w . j a v a 2 s .c o m*/ if (!forceBackup) { FileInputStream instream = new FileInputStream(oldState.getFileDescriptor()); DataInputStream in = new DataInputStream(instream); long lastModified = in.readLong(); in.close(); if (lastModified < fileModified) { forceBackup = true; } } } catch (IOException e) { Log.e(THIS_FILE, "Cannot manage previous local backup state", e); forceBackup = true; } Log.d(THIS_FILE, "Will backup profiles ? " + forceBackup); if (forceBackup) { JSONArray accountsSaved = SipProfileJson.serializeSipProfiles(mContext); try { writeData(data, accountsSaved.toString()); } catch (IOException e) { Log.e(THIS_FILE, "Cannot manage remote backup", e); } } try { FileOutputStream outstream = new FileOutputStream(newState.getFileDescriptor()); DataOutputStream out = new DataOutputStream(outstream); out.writeLong(fileModified); out.close(); } catch (IOException e) { Log.e(THIS_FILE, "Cannot manage final local backup state", e); } }
From source file:com.csipsimple.backup.SipSharedPreferencesHelper.java
@Override public void performBackup(ParcelFileDescriptor oldState, BackupDataOutput data, ParcelFileDescriptor newState) { boolean forceBackup = (oldState == null); long fileModified = 1; if (prefsFiles != null) { fileModified = prefsFiles.lastModified(); }/*w w w. jav a 2 s . co m*/ try { if (!forceBackup) { FileInputStream instream = new FileInputStream(oldState.getFileDescriptor()); DataInputStream in = new DataInputStream(instream); long lastModified = in.readLong(); in.close(); if (lastModified < fileModified) { forceBackup = true; } } } catch (IOException e) { Log.e(THIS_FILE, "Cannot manage previous local backup state", e); forceBackup = true; } Log.d(THIS_FILE, "Will backup profiles ? " + forceBackup); if (forceBackup) { JSONObject settings = SipProfileJson.serializeSipSettings(mContext); try { writeData(data, settings.toString()); } catch (IOException e) { Log.e(THIS_FILE, "Cannot manage remote backup", e); } } try { FileOutputStream outstream = new FileOutputStream(newState.getFileDescriptor()); DataOutputStream out = new DataOutputStream(outstream); out.writeLong(fileModified); out.close(); } catch (IOException e) { Log.e(THIS_FILE, "Cannot manage final local backup state", e); } }
From source file:org.apache.hadoop.hdfs.server.namenode.AvatarNodeNew.java
/** * Reads the timestamp of the last checkpoint from the remote fstime file. *//*from w w w . ja va 2 s .c om*/ static long readRemoteFstime(Configuration conf) throws IOException { String edit = null; if (instance == InstanceId.NODEZERO) { edit = conf.get("dfs.name.edits.dir.shared1"); } else if (instance == InstanceId.NODEONE) { edit = conf.get("dfs.name.edits.dir.shared0"); } else { LOG.info("Instance is invalid. " + instance); throw new IOException("Instance is invalid. " + instance); } File timeFile = new File(edit + TIMEFILE); long timeStamp = 0L; DataInputStream in = null; try { in = new DataInputStream(new FileInputStream(timeFile)); timeStamp = in.readLong(); } catch (IOException e) { if (!timeFile.exists()) { String msg = "Error reading checkpoint time file " + timeFile + " file does not exist."; LOG.error(msg); throw new IOException(msg + e); } else if (!timeFile.canRead()) { String msg = "Error reading checkpoint time file " + timeFile + " cannot read file of size " + timeFile.length() + " last modified " + dateForm.format(new Date(timeFile.lastModified())); LOG.error(msg); throw new IOException(msg + e); } else { String msg = "Error reading checkpoint time file " + timeFile; LOG.error(msg); throw new IOException(msg + e); } } finally { if (in != null) { in.close(); } } return timeStamp; }