List of usage examples for com.google.common.io LittleEndianDataInputStream LittleEndianDataInputStream
public LittleEndianDataInputStream(InputStream in)
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 . ja va 2s. c om } 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.jpmml.xgboost.XGBoostDataInput.java
public XGBoostDataInput(InputStream is) throws IOException { this.dis = new LittleEndianDataInputStream(init(new PushbackInputStream(is, 4))); }
From source file:org.glukit.dexcom.sync.LittleEndianDataInputFactory.java
@Override public DataInput create(InputStream inputStream) { return new LittleEndianDataInputStream(inputStream); }
From source file:io.airlift.slice.InputStreamSliceInput.java
@SuppressWarnings("IOResourceOpenedButNotSafelyClosed") public InputStreamSliceInput(InputStream inputStream) { checkNotNull(inputStream, "inputStream is null"); pushbackInputStream = new PushbackInputStream(inputStream); countingInputStream = new CountingInputStream(pushbackInputStream); dataInputStream = new LittleEndianDataInputStream(countingInputStream); }
From source file:org.linguafranca.pwdb.kdb.KdbSerializer.java
/** * Construct a KDB database from the supplied inputstream. * * @param credentials the credentials//from w w w .j av a2 s . c o m * @param kdbHeader a header to be populated with values read from the stream * @param inputStream an inputStream to read from * @return a constructed KdbDatabase * @throws IOException if reading of the inputStream fails * @throws IllegalStateException if decoding of KDB format fails */ public static KdbDatabase createKdbDatabase(Credentials credentials, KdbHeader kdbHeader, InputStream inputStream) throws IOException { // everything is little endian DataInput dataInput = new LittleEndianDataInputStream(inputStream); // check the magic values to verify file type checkSignature(dataInput); // load the header deserializeHeader(kdbHeader, dataInput); // Create a decrypted stream from where we have read to InputStream decryptedInputStream = kdbHeader.createDecryptedInputStream(credentials.getKey(), inputStream); // Wrap the decrypted stream in a digest stream MessageDigest digest = Encryption.getMessageDigestInstance(); DigestInputStream digestInputStream = new DigestInputStream(decryptedInputStream, digest); // Start the dataInput at wherever we have got to in the stream dataInput = new LittleEndianDataInputStream(digestInputStream); // read the decrypted serialized form of all groups KdbDatabase kdbDatabase = new KdbDatabase(); KdbGroup lastGroup = (KdbGroup) kdbDatabase.getRootGroup(); for (long group = 0; group < kdbHeader.getGroupCount(); group++) { lastGroup = deserializeGroup(lastGroup, dataInput); } // read the decrypted serialized form of all entries for (long entry = 0; entry < kdbHeader.getEntryCount(); entry++) { deserializeEntry(kdbDatabase, dataInput); } // check that the digest is correct (one would imagine that it would all have failed horribly by now if not) if (!Arrays.equals(digest.digest(), kdbHeader.getContentHash())) { throw new IllegalStateException("Hash values did not match"); } // close digest and all underlying streams digestInputStream.close(); return kdbDatabase; }
From source file:org.apache.hadoop.hive.ql.io.slice.InputStreamSliceInput.java
@SuppressWarnings("IOResourceOpenedButNotSafelyClosed") public InputStreamSliceInput(InputStream inputStream) { pushbackInputStream = new PushbackInputStream(inputStream); countingInputStream = new CountingInputStream(pushbackInputStream); dataInputStream = new LittleEndianDataInputStream(countingInputStream); }
From source file:de.johni0702.api.noteblock.parser.NbsParser.java
@Override public Song parseFile(File file) throws IOException { FileInputStream inputStream = new FileInputStream(file); DataInput in = new LittleEndianDataInputStream(inputStream); int length = in.readShort(); int height = in.readShort(); String name = readString(in); String author = readString(in); String originalAuthor = readString(in); String description = readString(in); double tempo = in.readShort() / 100d; in.skipBytes(23);//from ww w . ja v a2 s. c om in.skipBytes(in.readInt()); Layer[] layers = new Layer[height]; for (int i = 0; i < layers.length; i++) { layers[i] = new Layer(); } int jump; int tick = -1; while ((jump = in.readShort()) != 0) { tick += jump; int layer = -1; while ((jump = in.readShort()) != 0) { layer += jump; Instrument instrument = Instrument.forId(in.readByte()); NotePitch pitch = notePitchForId((in.readByte() - 33) % 24); layers[layer].setNoteBlock(tick, new Note(instrument, pitch)); } } for (Layer layer : layers) { layer.setName(readString(in)); layer.setVolume(in.readByte() / 100d); } Song song = new Song(length, name, author, originalAuthor, description, tempo); song.getLayers().addAll(Arrays.asList(layers)); return song; }
From source file:terralib.World.java
public World(File file) throws IOException { buffer = Files.map(file);//from w w w . j av a 2 s . c om parse(new LittleEndianDataInputStream(new ByteBufferInputStream(buffer))); buffer.rewind(); }
From source file:org.ambud.marauder.source.ids.pcap.LibpcapFileReader.java
@Override public void preProcess() throws IOException { validateFileLock();// w w w . ja v a2 s . com fileHeader = new LibpcapGlobalHeader(getStream()); if (fileHeader.isSwapped()) { this.reader = new LittleEndianDataInputStream(getStream()); } else { this.reader = new DataInputStream(getStream()); } }
From source file:org.ambud.marauder.source.ids.pcap.LibpcapGlobalHeader.java
public LibpcapGlobalHeader(InputStream inputStream) throws IOException { this.magicNumber |= inputStream.read() << 24; this.magicNumber |= inputStream.read() << 16; this.magicNumber |= inputStream.read() << 8; this.magicNumber |= inputStream.read(); this.isSwapped = (this.magicNumber == 0xd4c3b2a1) ? true : false; DataInput temp = null;/*from w w w . j a va 2 s .c om*/ if (isSwapped) { temp = new LittleEndianDataInputStream(inputStream); this.versionMajor = temp.readUnsignedShort(); this.versionMinor = temp.readUnsignedShort(); this.thisZone = temp.readInt(); this.sigFigs = temp.readInt(); this.snaplen = temp.readInt(); this.network = temp.readInt(); } else { temp = new DataInputStream(inputStream); this.versionMajor = temp.readUnsignedShort(); this.versionMinor = temp.readUnsignedShort(); this.thisZone = temp.readInt(); this.sigFigs = temp.readInt(); this.snaplen = temp.readInt(); this.network = temp.readInt(); } }