List of usage examples for java.io DataInputStream readLong
public final long readLong() throws IOException
readLong
method of DataInput
. From source file:net.timewalker.ffmq4.storage.data.impl.journal.JournalRecovery.java
private static DataBlockWriteOperation readDataBlockWriteOperation(DataInputStream in) throws IOException { long transactionId = in.readLong(); long blockOffset = in.readLong(); int len = in.readInt(); byte[] dataBlock = new byte[len]; in.readFully(dataBlock);/*from ww w . jav a2s . c o m*/ return new DataBlockWriteOperation(transactionId, -1, blockOffset, dataBlock); }
From source file:net.timewalker.ffmq4.storage.data.impl.journal.JournalRecovery.java
private static MetaDataBlockWriteOperation readMetaDataBlockWriteOperation(DataInputStream in) throws IOException { long transactionId = in.readLong(); long metaDataOffset = in.readLong(); int len = in.readInt(); byte[] metaData = new byte[len]; in.readFully(metaData);/*from w ww . j a v a 2 s.c om*/ return new MetaDataBlockWriteOperation(transactionId, metaDataOffset, metaData); }
From source file:com.opensoc.json.serialization.JSONDecoderHelper.java
public static Number getNumber(DataInputStream data) throws IOException { // Treating all ints,shorts, long as long. // Everything else as Double int flag = data.readByte(); if (flag == 0) return data.readDouble(); return data.readLong(); }
From source file:tudarmstadt.lt.ABSentiment.featureExtractor.util.GloVeSpace.java
/** * Read a Vector - Array from binary file * @param ds input data stream/*from w w w . j a v a 2 s. c o m*/ * @param vectorSize length of each word vector * @return an array of float containing the word vector representation */ private static float[] readFloatVector(DataInputStream ds, int vectorSize) throws IOException { float[] vector = new float[vectorSize]; for (int j = 0; j < vectorSize; j++) { long l = ds.readLong(); float d = (float) (Long.reverseBytes(l)); vector[j] = d; } return vector; }
From source file:org.tranche.server.logs.LogUtil.java
/** * Convert bytes to longs and return long representation. * @param longVal/*from w w w.ja va2s . c o m*/ * @return * @throws java.lang.Exception */ public static long convertBytesToLong(byte[] longVal) throws Exception { ByteArrayInputStream bais = new ByteArrayInputStream(longVal); DataInputStream dis = new DataInputStream(bais); try { return dis.readLong(); } finally { dis.close(); } }
From source file:org.apache.hadoop.hdfs.server.namenode.FSImagePreTransactionalStorageInspector.java
/** * Determine the checkpoint time of the specified StorageDirectory * * @param sd StorageDirectory to check//from ww w . j a v a 2s . c o m * @return If file exists and can be read, last checkpoint time. If not, 0L. * @throws IOException On errors processing file pointed to by sd */ static long readCheckpointTime(StorageDirectory sd) throws IOException { File timeFile = NNStorage.getStorageFile(sd, NameNodeFile.TIME); long timeStamp = 0L; if (timeFile.exists() && FileUtil.canRead(timeFile)) { DataInputStream in = new DataInputStream(new FileInputStream(timeFile)); try { timeStamp = in.readLong(); in.close(); in = null; } finally { IOUtils.cleanup(LOG, in); } } return timeStamp; }
From source file:net.sf.keystore_explorer.crypto.x509.X509ExtensionSet.java
/** * Load X.509 extension set./*from ww w . j a v a2s. co m*/ * * @param is * Stream to load from * @return X.509 extension set * @throws X509ExtensionSetLoadException * If stream contents are not a valid X.509 extension set * @throws IOException * If an I/O problem occurred */ public static X509ExtensionSet load(InputStream is) throws X509ExtensionSetLoadException, IOException { DataInputStream dis = null; try { dis = new DataInputStream(is); long magicNumber = dis.readLong(); if (magicNumber != FILE_MAGIC_NUMBER) { throw new X509ExtensionSetLoadException( res.getString("NoLoadX509ExtensionSet.BadMagicNumber.exception.message")); } int version = dis.readInt(); if (version != FILE_VERSION) { throw new X509ExtensionSetLoadException( res.getString("NoLoadX509ExtensionSet.WrongVersion.exception.message")); } X509ExtensionSet x509ExtensionSet = new X509ExtensionSet(); x509ExtensionSet.criticalExtensions = loadExtensions(dis); x509ExtensionSet.nonCriticalExtensions = loadExtensions(dis); return x509ExtensionSet; } catch (EOFException ex) { throw new X509ExtensionSetLoadException( res.getString("NoLoadX509ExtensionSet.NotEnoughBytes.exception.message")); } finally { IOUtils.closeQuietly(dis); } }
From source file:org.apache.flink.runtime.metrics.dump.MetricDumpSerialization.java
private static MetricDump.HistogramDump deserializeHistogram(DataInputStream dis) throws IOException { QueryScopeInfo info = deserializeMetricInfo(dis); String name = deserializeString(dis); long min = dis.readLong(); long max = dis.readLong(); double mean = dis.readDouble(); double median = dis.readDouble(); double stddev = dis.readDouble(); double p75 = dis.readDouble(); double p90 = dis.readDouble(); double p95 = dis.readDouble(); double p98 = dis.readDouble(); double p99 = dis.readDouble(); double p999 = dis.readDouble(); return new MetricDump.HistogramDump(info, name, min, max, mean, median, stddev, p75, p90, p95, p98, p99, p999);/*from ww w .j a v a 2 s.c om*/ }
From source file:org.apache.flink.runtime.metrics.dump.MetricDumpSerialization.java
private static MetricDump.CounterDump deserializeCounter(DataInputStream dis) throws IOException { QueryScopeInfo scope = deserializeMetricInfo(dis); String name = deserializeString(dis); return new MetricDump.CounterDump(scope, name, dis.readLong()); }
From source file:org.eclipse.swt.snippets.Snippet319.java
static MyType restoreFromByteArray(byte[] bytes) { DataInputStream dataInStream = null; try {// w ww . j av a 2 s . c om ByteArrayInputStream byteInStream = new ByteArrayInputStream(bytes); dataInStream = new DataInputStream(byteInStream); int size = dataInStream.readInt(); byte[] name = new byte[size]; dataInStream.read(name); MyType result = new MyType(); result.name = new String(name); result.time = dataInStream.readLong(); return result; } catch (IOException ex) { return null; } finally { if (dataInStream != null) { try { dataInStream.close(); } catch (IOException e) { } } } }