List of usage examples for com.google.common.io LittleEndianDataInputStream readByte
@Override public byte readByte() throws IOException
From source file:pw.simplyintricate.bitcoin.models.datastructures.VariableInteger.java
public static VariableInteger fromInputStream(LittleEndianDataInputStream reader) throws IOException { byte determiningSize = reader.readByte(); UnsignedInteger value;//w ww.j a va 2s .co m if (determiningSize < 0xfd) { value = UnsignedInteger.fromIntBits(determiningSize); } else if (determiningSize <= 0xffff) { int followUpValue = reader.readUnsignedShort(); value = UnsignedInteger.fromIntBits(followUpValue); } else if (determiningSize <= 0xffffffff) { int followUpValue = reader.readInt(); value = UnsignedInteger.valueOf(followUpValue); } else { long followUpValue = reader.readLong(); value = UnsignedInteger.valueOf(followUpValue); } VariableInteger variableInteger = new VariableInteger(value); return variableInteger; }
From source file:org.broad.igv.sam.cram.CRAMFileReader.java
public static CRAMFile openFile(String path) throws IOException { SeekableStream stream = IGVSeekableStreamFactory.getInstance().getStreamFor(path); LittleEndianDataInputStream lis = new LittleEndianDataInputStream(stream); byte[] mn = new byte[4]; for (int i = 0; i < 4; i++) { mn[i] = lis.readByte(); }/*w w w.j a v a 2 s. c o m*/ String magicNumber = new String(mn); int majorFormatNumber = lis.readUnsignedByte(); int minorFormatNumber = lis.readUnsignedByte(); byte[] fileId = new byte[20]; for (int i = 0; i < 20; i++) { fileId[i] = lis.readByte(); } String fileName = new String(fileId); return new CRAMFile(path, majorFormatNumber, minorFormatNumber, fileName); }
From source file:org.linguafranca.pwdb.kdbx.stream_3_1.KdbxSerializer.java
/** * Populate a KdbxHeader from the input stream supplied * @param kdbxHeader a header to be populated * @param inputStream an input stream/*w w w .j av a2 s . com*/ * @return the populated KdbxHeader * @throws IOException on error */ public static KdbxHeader readKdbxHeader(KdbxHeader kdbxHeader, InputStream inputStream) throws IOException { MessageDigest digest = Encryption.getMessageDigestInstance(); // we do not close this stream, otherwise we lose our place in the underlying stream DigestInputStream digestInputStream = new DigestInputStream(inputStream, digest); // we do not close this stream, otherwise we lose our place in the underlying stream LittleEndianDataInputStream ledis = new LittleEndianDataInputStream(digestInputStream); if (!verifyMagicNumber(ledis)) { throw new IllegalStateException("Magic number did not match"); } if (!verifyFileVersion(ledis)) { throw new IllegalStateException("File version did not match"); } byte headerType; while ((headerType = ledis.readByte()) != HeaderType.END) { switch (headerType) { case HeaderType.COMMENT: getByteArray(ledis); break; case HeaderType.CIPHER_ID: kdbxHeader.setCipherUuid(getByteArray(ledis)); break; case HeaderType.COMPRESSION_FLAGS: kdbxHeader.setCompressionFlags(getInt(ledis)); break; case HeaderType.MASTER_SEED: kdbxHeader.setMasterSeed(getByteArray(ledis)); break; case HeaderType.TRANSFORM_SEED: kdbxHeader.setTransformSeed(getByteArray(ledis)); break; case HeaderType.TRANSFORM_ROUNDS: kdbxHeader.setTransformRounds(getLong(ledis)); break; case HeaderType.ENCRYPTION_IV: kdbxHeader.setEncryptionIv(getByteArray(ledis)); break; case HeaderType.PROTECTED_STREAM_KEY: kdbxHeader.setProtectedStreamKey(getByteArray(ledis)); break; case HeaderType.STREAM_START_BYTES: kdbxHeader.setStreamStartBytes(getByteArray(ledis)); break; case HeaderType.INNER_RANDOM_STREAM_ID: kdbxHeader.setInnerRandomStreamId(getInt(ledis)); break; default: throw new IllegalStateException("Unknown File Header"); } } // consume length etc. following END flag getByteArray(ledis); kdbxHeader.setHeaderHash(digest.digest()); return kdbxHeader; }
From source file:org.lambda3.indra.util.VectorIterator.java
private void parseHeadline(LittleEndianDataInputStream input) throws IOException { ByteArrayDataOutput out = ByteStreams.newDataOutput(); byte c;/*from w w w. j av a 2 s.c o m*/ while ((c = input.readByte()) != '\n') { out.writeByte(c); } String[] headline = new String(out.toByteArray(), StandardCharsets.UTF_8).split(" "); this.numberOfVectors = Integer.parseInt(headline[0]); this.dimensions = Integer.parseInt(headline[1]); }