List of usage examples for com.google.common.io LittleEndianDataInputStream read
public int read(byte b[], int off, int len) throws IOException
len
bytes of data from this input stream into an array of bytes. From source file:pw.simplyintricate.bitcoin.models.datastructures.InventoryVector.java
public static InventoryVector fromInputStream(LittleEndianDataInputStream reader) throws IOException { int type = reader.readInt(); byte[] hash = new byte[32]; reader.read(hash, 0, hash.length); return new InventoryVector(UnsignedInteger.fromIntBits(type), hash); }
From source file:pw.simplyintricate.bitcoin.models.datastructures.VariableString.java
public static VariableString fromInputStream(LittleEndianDataInputStream reader) throws IOException { VariableInteger variableInteger = VariableInteger.fromInputStream(reader); int stringSize = variableInteger.getValue().intValue(); byte[] stringBuffer = new byte[stringSize]; reader.read(stringBuffer, 0, stringSize); VariableString variableString = new VariableString(new String(stringBuffer)); return variableString; }
From source file:pw.simplyintricate.bitcoin.models.datastructures.NetworkAddress.java
public static NetworkAddress fromInputStream(LittleEndianDataInputStream reader, boolean readTime) throws IOException { int time = -1; if (readTime) { time = reader.readInt();//from www . j a va 2 s . c o m } long services = reader.readLong(); reader.skip(12); // skip ipv6 support :( byte[] ipAddress = new byte[4]; reader.read(ipAddress, 0, 4); short port = EndianUtils.swapShort(((short) reader.readUnsignedShort())); NetworkAddress networkAddress; if (readTime) { networkAddress = new NetworkAddress(UnsignedInteger.valueOf(services), ipAddress, port, UnsignedInteger.fromIntBits(time)); } else { networkAddress = new NetworkAddress(UnsignedInteger.valueOf(services), ipAddress, port); } return networkAddress; }
From source file:pw.simplyintricate.bitcoin.models.datastructures.BlockVersion.java
public static BlockVersion fromInputStream(LittleEndianDataInputStream reader) throws IOException { int version = reader.readInt(); long services = reader.readLong(); long timestamp = reader.readLong(); NetworkAddress receivingNetworkAddress = NetworkAddress.fromInputStream(reader); NetworkAddress emittingNetworkAddress = NetworkAddress.fromInputStream(reader); byte[] nonce = new byte[8]; reader.read(nonce, 0, nonce.length); VariableString userAgent = VariableString.fromInputStream(reader); int startingHeight = reader.readInt(); BlockVersion blockVersion = new BlockVersion(version, UnsignedInteger.valueOf(services), timestamp, receivingNetworkAddress, emittingNetworkAddress, nonce, userAgent, startingHeight); return blockVersion; }
From source file:com.google.devtools.build.android.AndroidCompiledDataDeserializer.java
private void readResourceTable(LittleEndianDataInputStream resourceTableStream, KeyValueConsumers consumers) throws IOException { long alignedSize = resourceTableStream.readLong(); Preconditions.checkArgument(alignedSize <= Integer.MAX_VALUE); byte[] tableBytes = new byte[(int) alignedSize]; resourceTableStream.read(tableBytes, 0, (int) alignedSize); ResourceTable resourceTable = ResourceTable.parseFrom(tableBytes); readPackages(consumers, resourceTable); }
From source file:com.google.devtools.build.android.AndroidCompiledDataDeserializer.java
/** * Reads compiled resource data files and adds them to consumers * * @param compiledFileStream First byte is number of compiled files represented in this file. Next * 8 bytes is a long indicating the length of the metadata describing the compiled file. Next * N bytes is the metadata describing the compiled file. The remaining bytes are the actual * original file./*w w w . j av a 2 s . c o m*/ * @param consumers * @param fqnFactory * @throws IOException */ private void readCompiledFile(LittleEndianDataInputStream compiledFileStream, KeyValueConsumers consumers, Factory fqnFactory) throws IOException { // Skip aligned size. We don't need it here. Preconditions.checkArgument(compiledFileStream.skipBytes(8) == 8); int resFileHeaderSize = compiledFileStream.readInt(); // Skip data payload size. We don't need it here. Preconditions.checkArgument(compiledFileStream.skipBytes(8) == 8); byte[] file = new byte[resFileHeaderSize]; compiledFileStream.read(file, 0, resFileHeaderSize); CompiledFile compiledFile = CompiledFile.parseFrom(file); Path sourcePath = Paths.get(compiledFile.getSourcePath()); FullyQualifiedName fqn = fqnFactory.parse(sourcePath); DataSource dataSource = DataSource.of(sourcePath); if (consumers != null) { consumers.overwritingConsumer.accept(fqn, DataValueFile.of(dataSource)); } for (CompiledFile.Symbol exportedSymbol : compiledFile.getExportedSymbolList()) { if (!exportedSymbol.getResourceName().startsWith("android:")) { // Skip writing resource xml's for resources in the sdk FullyQualifiedName symbolFqn = fqnFactory.create(ResourceType.ID, exportedSymbol.getResourceName().replaceFirst("id/", "")); DataResourceXml dataResourceXml = DataResourceXml.from(null, dataSource, ResourceType.ID, null); consumers.combiningConsumer.accept(symbolFqn, dataResourceXml); } } }