List of usage examples for com.google.common.io LittleEndianDataInputStream LittleEndianDataInputStream
public LittleEndianDataInputStream(InputStream in)
From source file:org.lambda3.indra.util.VectorIterator.java
public VectorIterator(File vectorsFile, long dimensions, boolean sparse) throws IOException { this.sparse = sparse; this.input = new LittleEndianDataInputStream(new FileInputStream(vectorsFile)); parseHeadline(this.input); if (this.dimensions != (int) dimensions) { throw new IOException("inconsistent number of dimensions."); }/*from ww w . jav a2s . c o m*/ setCurrentContent(); }
From source file:garmintools.adapters.garmin.TableOfContentsGarminAdapter.java
/** * Reading the table of contents does not fit well into the GarminAdapter.read interface * for two reasons://from w w w . j a va 2 s . co m * 1) the first entry in the TOC is for the TOC itself, so the length is not known a priori. * 2) it is useful to know the input file length to construct the TOC, and this is not available * in the traditional GarminAdapter.read interface. */ public TableOfContents read(InputStream originalInputStream, int inputFileLength) throws IOException { LittleEndianDataInputStream inputStream = new LittleEndianDataInputStream(originalInputStream); TableOfContentsEntry toc = readTableOfContentsEntry(inputStream); Preconditions.checkState(toc.itemQuantity <= MAX_ITEM_QUANTITY); Preconditions.checkState(toc.itemLength == ITEM_LENGTH); Map<Integer, TableOfContentsEntry> offsetToEntries = new HashMap<>(); ImmutableMap.Builder<Integer, Integer> emptySectionItemLengths = ImmutableMap.builder(); for (int sectionNumber = 0; sectionNumber < toc.itemQuantity - 1; ++sectionNumber) { TableOfContentsEntry entry = TableOfContentsEntry.newBuilder(readTableOfContentsEntry(inputStream)) .setSectionNumber(sectionNumber).build(); if (entry.fileOffset == 0) { if (entry.itemLength > 0) { emptySectionItemLengths.put(sectionNumber, entry.itemLength); } continue; // the section is not present in the file. } offsetToEntries.put(entry.fileOffset, entry); } List<Integer> orderedDeclaredOffsets = new ArrayList<Integer>( new TreeSet<Integer>(offsetToEntries.keySet())); orderedDeclaredOffsets.add(inputFileLength); ImmutableMap.Builder<Integer, TableOfContentsEntry> mapBuilder = ImmutableMap.builder(); for (int i = 0; i < orderedDeclaredOffsets.size() - 1; ++i) { int currentOffset = orderedDeclaredOffsets.get(i); int nextOffset = orderedDeclaredOffsets.get(i + 1); TableOfContentsEntry entry = TableOfContentsEntry.newBuilder(offsetToEntries.get(currentOffset)) .setActualLength(Ints.checkedCast(nextOffset - currentOffset)).build(); mapBuilder.put(entry.sectionNumber, entry); } return new TableOfContents(toc.itemQuantity, mapBuilder.build(), emptySectionItemLengths.build()); }
From source file:org.broad.igv.sam.cram.CRAMFile.java
public void readBlocks(InputStream is, int nBlocks) throws IOException { LittleEndianDataInputStream lis = new LittleEndianDataInputStream(is); for (int i = 0; i < nBlocks; i++) { int compressionMethod = lis.read(); int contentType = lis.read(); int contentId = ITF8.readUnsignedITF8(lis); int size = ITF8.readUnsignedITF8(lis); int rawSize = ITF8.readUnsignedITF8(lis); byte[] blockData = new byte[size]; lis.readFully(blockData);/*from w ww. j a va 2s . c o m*/ blockData = uncompress(blockData, compressionMethod); String tmp = new String(blockData); if (major >= 3) { int checksum = CramInt.int32(lis); } } }
From source file:com.google.classyshark.translator.xml.XmlDecompressor.java
public String decompressXml(InputStream is) throws IOException { StringBuilder result = new StringBuilder("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"); try (LittleEndianDataInputStream dis = new LittleEndianDataInputStream(is)) { //Getting and checking the marker for a valid XMl file int fileMarker = dis.readInt(); if (fileMarker != PACKED_XML_IDENTIFIER) { throw new IOException(String.format(ERROR_INVALID_MAGIC_NUMBER, PACKED_XML_IDENTIFIER, fileMarker)); }//from ww w . j av a 2 s . c o m dis.skipBytes(12); List<String> packedStrings = parseStrings(dis); //Unknown content after the strings. Seeking for a start tag int tag; do { tag = dis.readInt(); } while (tag != START_ELEMENT_TAG); int ident = 0; do { switch (tag) { case START_ELEMENT_TAG: { parseStartTag(result, dis, packedStrings, ident); ident++; break; } case END_ELEMENT_TAG: { ident--; parseEndTag(result, dis, packedStrings, ident); break; } case CDATA_TAG: { parseCDataTag(result, dis, packedStrings, ident); break; } default: System.err.println(String.format(ERROR_UNKNOWN_TAG, tag)); } tag = dis.readInt(); } while (tag != END_DOC_TAG); return result.toString(); } }
From source file:brut.androlib.res.decoder.ARSCDecoder.java
private ARSCDecoder(InputStream arscStream, ResTable resTable, boolean storeFlagsOffsets, boolean keepBroken) { arscStream = mCountIn = new CountingInputStream(arscStream); if (storeFlagsOffsets) { mFlagsOffsets = new ArrayList<FlagsOffset>(); } else {/*from ww w.j a va 2 s . com*/ mFlagsOffsets = null; } // We need to explicitly cast to DataInput as otherwise the constructor is ambiguous. // We choose DataInput instead of InputStream as ExtDataInput wraps an InputStream in // a DataInputStream which is big-endian and ignores the little-endian behavior. mIn = new ExtDataInput((DataInput) new LittleEndianDataInputStream(arscStream)); mResTable = resTable; mKeepBroken = keepBroken; }
From source file:sx.kenji.sharpserializerjvm.SharpSerializer.java
public Optional<Property> deserialize() { try {//from w w w . j a va 2 s . com FileInputStream baseStream = new FileInputStream(targetFile); try (LittleEndianDataInputStream stream = new LittleEndianDataInputStream(baseStream)) { baseStream.getChannel().position(position); Deserializer deserializer = new Deserializer(stream, this); Property property = deserializer.deserialize(); position = baseStream.getChannel().position(); return Optional.ofNullable(createObject(property)); } } catch (IOException e) { logger.error("Error opening target file '%s' for deserializing: `{}`.", targetFile, e.getMessage()); } return Optional.empty(); }
From source file:brut.androlib.res.decoder.AXmlResourceParser.java
public void open(InputStream stream) { close();/*from ww w. j a v a 2s .c o m*/ if (stream != null) { // We need to explicitly cast to DataInput as otherwise the constructor is ambiguous. // We choose DataInput instead of InputStream as ExtDataInput wraps an InputStream in // a DataInputStream which is big-endian and ignores the little-endian behavior. m_reader = new ExtDataInput((DataInput) new LittleEndianDataInputStream(stream)); } }
From source file:org.necsave.NMPUtilities.java
public static Message decompress(CompressedMsg msg) { Inflater inflater = new Inflater(); inflater.setInput(msg.getPayload()); byte[] out = new byte[65535]; try {//from w w w.ja v a2 s . c o m int len = inflater.inflate(out); Message decompressed = ProtoDefinition.getFactory().createMessage(msg.getMsgType(), ProtoDefinition.getInstance()); ProtoDefinition.getInstance().deserializeFields(decompressed, new LittleEndianDataInputStream(new ByteArrayInputStream(out, 0, len))); return decompressed; } catch (Exception e) { e.printStackTrace(); return null; } }
From source file:xyz.kuori.timeseries.TimeSeries.java
public int load(File archive) { FileInputStream fin = null;/*from w w w. ja v a 2s. co m*/ try { fin = new FileInputStream(archive); } catch (Exception e) { init(0); return (-1); } int record_count = (int) (archive.length() / 16); init(record_count); LittleEndianDataInputStream in = new LittleEndianDataInputStream(fin); try { for (int i = 0; i < record_count; i++) { timestamps[i] = in.readLong(); values[i] = in.readDouble(); } } catch (Exception e) { init(0); return (-1); } return (record_count); }
From source file:com.broadwave.android.brut.androlib.res.decoder.ARSCDecoder.java
private ARSCDecoder(InputStream arscStream, ResTable resTable, boolean storeFlagsOffsets, boolean keepBroken) { if (storeFlagsOffsets) { arscStream = mCountIn = new CountingInputStream(arscStream); mFlagsOffsets = new ArrayList<FlagsOffset>(); } else {//from w w w .ja v a2 s .c o m mCountIn = null; mFlagsOffsets = null; } mIn = new ExtDataInput((DataInput) new LittleEndianDataInputStream(arscStream)); mResTable = resTable; mKeepBroken = keepBroken; }