List of usage examples for java.io DataInputStream readLong
public final long readLong() throws IOException
readLong
method of DataInput
. From source file:com.google.gwt.dev.javac.CachedCompilationUnit.java
public static CachedCompilationUnit load(InputStream inputStream, JsProgram jsProgram) throws Exception { DataInputStream dis = new DataInputStream(new BufferedInputStream(inputStream)); try {/*from ww w .j a v a2s . c o m*/ CachedCompilationUnit compilationUnit = new CachedCompilationUnit(); // version long version = dis.readLong(); if (version != CompilationUnitDiskCache.CACHE_VERSION) { return null; } // some simple stuff :) compilationUnit.m_lastModified = dis.readLong(); compilationUnit.m_displayLocation = dis.readUTF(); compilationUnit.m_typeName = dis.readUTF(); compilationUnit.m_contentId = new ContentId(dis.readUTF()); compilationUnit.m_isSuperSource = dis.readBoolean(); // compiled classes { int size = dis.readInt(); compilationUnit.m_compiledClasses = new ArrayList<CompiledClass>(size); for (int i = 0; i < size; ++i) { // internal name String internalName = dis.readUTF(); // is local boolean isLocal = dis.readBoolean(); // bytes int byteSize = dis.readInt(); byte[] bytes = new byte[byteSize]; dis.readFully(bytes); // enclosing class CompiledClass enclosingClass = null; String enclosingClassName = dis.readUTF(); if (!StringUtils.isEmpty(enclosingClassName)) { for (CompiledClass cc : compilationUnit.m_compiledClasses) { if (enclosingClassName.equals(cc.getInternalName())) { enclosingClass = cc; break; } } } // some assertion if (!StringUtils.isEmpty(enclosingClassName) && enclosingClass == null) { throw new IllegalStateException("Can't find the enclosing class \"" + enclosingClassName + "\" for \"" + internalName + "\""); } // init unit CompiledClass cc = new CompiledClass(internalName, bytes, isLocal, enclosingClass); cc.initUnit(compilationUnit); compilationUnit.m_compiledClasses.add(cc); } } // dependencies { compilationUnit.m_dependencies = new HashSet<ContentId>(); int size = dis.readInt(); if (size > 0) { for (int i = 0; i < size; i++) { compilationUnit.m_dependencies.add(new ContentId(dis.readUTF())); } } } // JSNI methods { compilationUnit.m_jsniMethods = new ArrayList<JsniMethod>(); int size = dis.readInt(); if (size > 0) { for (int i = 0; i < size; i++) { String name = dis.readUTF(); int startPos = dis.readInt(); int endPos = dis.readInt(); int startLine = dis.readInt(); String source = dis.readUTF(); String fileName = compilationUnit.m_displayLocation; SourceInfo jsInfo = SourceOrigin.create(startPos, endPos, startLine, fileName); compilationUnit.m_jsniMethods .add(JsniCollector.restoreJsniMethod(name, source, jsInfo, jsProgram)); } } } // Method lookup { compilationUnit.m_methodArgs = MethodArgNamesLookup.load(dis); } return compilationUnit; } finally { IOUtils.closeQuietly(dis); } }
From source file:org.archive.crawler.frontier.BdbMultipleWorkQueues.java
protected static String insertKeyToString(DatabaseEntry holderKey) { StringBuilder result = new StringBuilder(); byte[] data = holderKey.getData(); int p = findFirstZero(data); result.append(new String(data, 0, p)); java.io.ByteArrayInputStream binp = new java.io.ByteArrayInputStream(data, p + 1, data.length); java.io.DataInputStream dinp = new java.io.DataInputStream(binp); long l = 0;/*from w w w. j av a2s.co m*/ try { l = dinp.readLong(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } result.append(" blah=").append(l); return result.toString(); }
From source file:Main.java
public static Object[] readSettings(String file) throws IOException { DataInputStream in = new DataInputStream(new FileInputStream(file)); try {/*from w w w .j a v a 2 s . c o m*/ Object[] res = new Object[in.readInt()]; for (int i = 0; i < res.length; i++) { char cl = in.readChar(); switch (cl) { case 'S': res[i] = in.readUTF(); break; case 'F': res[i] = in.readFloat(); break; case 'D': res[i] = in.readDouble(); break; case 'I': res[i] = in.readInt(); break; case 'L': res[i] = in.readLong(); break; case 'B': res[i] = in.readBoolean(); break; case 'Y': res[i] = in.readByte(); break; default: throw new IllegalStateException("cannot read type " + cl + " from " + file); } } return res; } finally { in.close(); } }
From source file:org.hyperic.hq.measurement.agent.server.SenderThread.java
private static Record decodeRecord(String val) throws IOException { ByteArrayInputStream bIs;//from w w w .j av a 2 s. co m DataInputStream dIs; MetricValue measVal; boolean isAvail; int derivedID, dsnID; long retTime; bIs = new ByteArrayInputStream(Base64.decode(val)); dIs = new DataInputStream(bIs); derivedID = dIs.readInt(); retTime = dIs.readLong(); dsnID = dIs.readInt(); measVal = new MetricValue(dIs.readDouble(), retTime); return new Record(dsnID, measVal, derivedID); }
From source file:org.nuras.mcpha.Client.java
/** * Get timer value in seconds which is derived from the 64-bit unsigned * integer value returned from the server, that is the number of counts * at 125MHz from the start of the acquisition. * //from w w w .j a v a 2s.c om * @param chan * @return the timer value in seconds since the start of acquisition * @throws java.io.IOException */ synchronized public static double mcphaGetTimerValue(long chan) throws IOException { sendCommand(MCPHA_COMMAND_READ_TIMER, chan, 0L); // read response DataInputStream in = new DataInputStream(deviceSocket.getInputStream()); long number = Long.reverseBytes(in.readLong()); return (double) number * TIME_PER_TICK; }
From source file:ClassFileUtilities.java
/** * Returns the dependencies of the given class. * @return a list of strings representing the used classes. */// w w w.j ava2 s. co m public static Set getClassDependencies(InputStream is) throws IOException { DataInputStream dis = new DataInputStream(is); if (dis.readInt() != 0xcafebabe) { throw new IOException("Invalid classfile"); } dis.readInt(); int len = dis.readShort(); String[] strs = new String[len]; Set classes = new HashSet(); Set desc = new HashSet(); for (int i = 1; i < len; i++) { int constCode = dis.readByte() & 0xff; switch (constCode) { case CONSTANT_LONG_INFO: case CONSTANT_DOUBLE_INFO: dis.readLong(); i++; break; case CONSTANT_FIELDREF_INFO: case CONSTANT_METHODREF_INFO: case CONSTANT_INTERFACEMETHODREF_INFO: case CONSTANT_INTEGER_INFO: case CONSTANT_FLOAT_INFO: dis.readInt(); break; case CONSTANT_CLASS_INFO: classes.add(new Integer(dis.readShort() & 0xffff)); break; case CONSTANT_STRING_INFO: dis.readShort(); break; case CONSTANT_NAMEANDTYPE_INFO: dis.readShort(); desc.add(new Integer(dis.readShort() & 0xffff)); break; case CONSTANT_UTF8_INFO: strs[i] = dis.readUTF(); break; default: throw new RuntimeException("unexpected data in constant-pool:" + constCode); } } Set result = new HashSet(); Iterator it = classes.iterator(); while (it.hasNext()) { result.add(strs[((Integer) it.next()).intValue()]); } it = desc.iterator(); while (it.hasNext()) { result.addAll(getDescriptorClasses(strs[((Integer) it.next()).intValue()])); } return result; }
From source file:org.apache.cassandra.db.SystemKeyspace.java
private static Pair<ReplayPosition, Long> truncationRecordFromBlob(ByteBuffer bytes) { try {/*from w w w.jav a2 s.c o m*/ DataInputStream in = new DataInputStream(ByteBufferUtil.inputStream(bytes)); return Pair.create(ReplayPosition.serializer.deserialize(in), in.available() > 0 ? in.readLong() : Long.MIN_VALUE); } catch (IOException e) { throw new RuntimeException(e); } }
From source file:com.yattatech.io.ShalomFileReader.java
public Seminary read(String path) { Seminary seminary = null;/*from ww w . j a va 2 s. co m*/ DataInputStream input = null; try { input = new DataInputStream(new FileInputStream(path)); long checksum = input.readLong(); input.readUTF(); // skip /n character String json = input.readUTF(); long checksum2 = ChecksumCalculator.calculateChecksum(json); if (checksum == checksum2) { seminary = new Gson().fromJson(json, Seminary.class); } } catch (IOException ioe) { LOGGER.log(Level.SEVERE, ioe.getMessage()); } finally { IOUtils.closeQuietly(input); return seminary; } }
From source file:mitm.common.security.crypto.PBEncryptedStreamParameters.java
private void fromInputStream(InputStream input) throws IOException { DataInputStream dis = new DataInputStream(input); long version = dis.readLong(); if (version != serialVersionUID) { throw new SerializationException("Version expected '" + serialVersionUID + "' but got '" + version); }// ww w.j av a 2 s . com algorithm = dis.readUTF(); int saltSize = dis.readInt(); this.salt = new byte[saltSize]; dis.readFully(salt); this.iterationCount = dis.readInt(); }
From source file:org.calrissian.accumulorecipes.commons.support.qfd.KeyToAttributeStoreQueryXform.java
@Override public V apply(Map.Entry<Key, Value> keyValueEntry) { EventFields eventFields = new EventFields(); eventFields.read(kryo, new Input(keyValueEntry.getValue().get()), EventFields.class); B entry = null;/*w w w .j a v a2 s. co m*/ for (Map.Entry<String, Set<EventFields.FieldValue>> fieldValue : eventFields.entrySet()) { for (EventFields.FieldValue fieldValue1 : fieldValue.getValue()) { String[] aliasVal = splitPreserveAllTokens(new String(fieldValue1.getValue()), ONE_BYTE); Object javaVal = typeRegistry.decode(aliasVal[0], aliasVal[1]); String vis = fieldValue1.getVisibility().getExpression().length > 0 ? new String(fieldValue1.getVisibility().getExpression()) : ""; try { ByteArrayInputStream bais = new ByteArrayInputStream(fieldValue1.getMetadata()); DataInputStream dis = new DataInputStream(bais); dis.readLong(); // minimum expiration of keys and values long timestamp = dis.readLong(); if (entry == null) entry = buildAttributeCollectionFromKey( 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, vis); Attribute attribute = new Attribute(fieldValue.getKey(), javaVal, metadata); entry.attr(attribute); } catch (Exception e) { log.error("There was an error deserializing the metadata for a attribute", e); } } } return entry.build(); }