private final void doStart() throws IOException { ReadUtil.readCheckType(m_stream, AXML_CHUNK_TYPE); /*chunk size*/ ReadUtil.readInt(m_stream); m_strings = StringBlock.read(new ExtDataInput((DataInput) new LittleEndianDataInputStream(m_stream))); ReadUtil.readCheckType(m_stream, RESOURCEIDS_CHUNK_TYPE); int chunkSize = ReadUtil.readInt(m_stream); if (chunkSize < 8 || (chunkSize % 4) != 0) { throw new IOException("Invalid resource ids size (" + chunkSize + ")."); } m_resourceIDs = ReadUtil.readIntArray(m_stream, chunkSize / 4 - 2); resetState(); }
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); blockData = uncompress(blockData, compressionMethod); String tmp = new String(blockData); if (major >= 3) { int checksum = CramInt.int32(lis); } } }
public IfcGeomServerClient(String executableFilename) throws RenderEngineException { try { process = Runtime.getRuntime().exec(executableFilename); dos = new LittleEndianDataOutputStream(process.getOutputStream()); dis = new LittleEndianDataInputStream(process.getInputStream()); if (dis.readInt() != HELLO) { terminate(); LOGGER.error("Invalid welcome message received"); return; } Hello h = new Hello(); h.read(dis); String reportedVersion = h.getString(); if (!VERSION.equals(reportedVersion)) { terminate(); LOGGER.error(String.format("Version mismatch: Plugin version %s does not match IfcOpenShell version %s", VERSION, reportedVersion)); return; } } catch (IOException e) { throw new RenderEngineException(e); } }
@Override void read_contents(LittleEndianDataInputStream s) throws IOException { entity = new IfcGeomServerClientEntity( s.readInt(), readString(s), readString(s), readString(s), s.readInt(), readDoubleWhichShouldBeFloatArray(s), s.readInt(), readFloatArray(s), readFloatArray(s), readIntArray(s), readFloatArray(s), readIntArray(s) ); }
private Tile readTile(LittleEndianDataInputStream stream, int x, int y) throws IOException { Tile tile = new Tile(tiles[x][y]); int attributes = stream.read(); if (attributes==1 || attributes==3) { int length = stream.read(); byte[] textBytes = new byte[length]; stream.read(textBytes); String text = new String(textBytes, "US-ASCII"); tile.setLabel(new Label(Font.decode("Arial-18"), text, new Color(0, 0, 0)), false); stream.skipBytes(3); } if (attributes==2 || attributes==3) { stream.skipBytes(4); } int terrain = stream.read(); GroundData ground = WAKData.grounds.get(terrain); tile.setGround(ground, RoadDirection.CENTER, false); int itemsNumber = stream.readInt(); for (int i=0; i<itemsNumber; i++) { readObject(stream, tile); } return tile; }
private void readObject(LittleEndianDataInputStream stream, Tile tile) throws IOException { int pos = stream.read(); int type = stream.read(); if (pos==2 || pos==10) { WallData wallData = WAKData.walls.get(type); if (pos==2) { Tile t = getTile(tile, 0, 1); if (t!=null) { t.setHorizontalWall(wallData, 0, false); } } if (pos==10) { tile.setVerticalWall(wallData, 0, false); } stream.skipBytes(1); } else { ObjectLocation loc = WAKData.locations.get(pos); GameObjectData data = WAKData.objects.get(type); if (data!=null) { tile.setGameObject(data, loc, 0); } stream.skipBytes(1); } }
/** * @param dataStream * @throws IOException */ private void skipTimeIndependentData(LittleEndianDataInputStream dataStream) throws IOException { header = BinaryHeaderDAO.readData(dataStream); // System.out.println(header.getModelAndVersion()); // System.out.println("Fileversion: " + header.getFileversion()); ComponentData compData = ComponentDataDAO.readData(dataStream, header.getFileversion()); SpecieDataDAO.readData(dataStream); dataStream.skip(24); // other stuff releaseSiteData = ReleaseSiteDataDAO.readData(dataStream); ReleaseDataDAO.readData(dataStream, releaseSiteData.getNumberSites(), compData.getTotalNumberOfComponents()); expandingGrid = (dataStream.readShort() == 1); dataStream.skip(6); // more other stuff ResponseDataDAO.readData(dataStream); }
/** * Create releaseSite from data read from dataStream * * @param dataStream * @throws IOException */ public static ReleaseSite readData( LittleEndianDataInputStream dataStream) throws IOException { ReleaseSite data = new ReleaseSite(); data.longitude = dataStream.readDouble(); data.latitude = dataStream.readDouble(); data.depth = dataStream.readDouble(); data.bathymetry = dataStream.readDouble(); data.releaseDiameter = dataStream.readDouble(); data.startTime = dataStream.readDouble(); data.duration = dataStream.readDouble(); data.moving = dataStream.readShort(); return data; }
/** * * @param dataStream * @param numberSites * @param numberComponentsInProfile * @throws IOException */ public static ReleaseData readData( LittleEndianDataInputStream dataStream, int numberSites, int numberComponentsInProfile) throws IOException { ReleaseData data = new ReleaseData(); if (numberSites > 0) { Vector<Release> releases = new Vector<Release>(); for (int i = 0; i < numberSites; i++) { releases.add(new Release(dataStream, numberComponentsInProfile)); } data.releases = releases; } return data; }
public static ComponentData readData( LittleEndianDataInputStream dataStream, short fileversion) throws IOException { ComponentData data = new ComponentData(); data.lengthOfComponentName = dataStream.readInt(); data.totalNumberOfComponents = dataStream.readInt(); data.numberOfOilComponents = dataStream.readInt(); data.numberOfChemComponents = dataStream.readInt(); data.numberOfParticleMaterialComponents = dataStream.readInt(); // gas particles from version 23 if (fileversion >= GRF.GRFFILEGASVERSION) { data.numberOfGasComponents = dataStream.readInt(); // number gas // components } byte[] componentName = new byte[data.lengthOfComponentName]; for (int i = 0; i < data.totalNumberOfComponents; i++) { dataStream.read(componentName); data.components.add(new Component(new String(componentName), dataStream.readFloat() /* density */, dataStream .readFloat() /* background concentration */, dataStream.readShort() /* is degradable */ )); } return data; }
/** * * @param dataStream * @throws IOException */ public static ResponseData readData( LittleEndianDataInputStream dataStream) throws IOException { ResponseData data = new ResponseData(); int lengthOfResponseVesselName = dataStream.readInt(); int numberResponseVessels = dataStream.readInt(); if (numberResponseVessels > 0) { Vector<String> units = new Vector<String>(); for (int i = 0; i < numberResponseVessels; i++) { units.add(getString(dataStream, lengthOfResponseVesselName)); } data.units = units; } return data; }
/** * Read SpecieData from dataStream * * @param dataStream * @throws IOException */ public static SpecieData readData(LittleEndianDataInputStream dataStream) throws IOException { SpecieData data = new SpecieData(); short numberSpecies = dataStream.readShort(); if (numberSpecies > 0) { Vector<Specie> species = new Vector<Specie>(); for (int i = 0; i < numberSpecies; i++) { species.add(SpecieDAO.readData(dataStream)); } data.species = species; } return data; }
/** * * @param datastream * @param numberOfLayers * @return * @throws IOException */ public static SubsurfaceGridDimensions readData( LittleEndianDataInputStream datastream, short numberOfLayers) throws IOException { SubsurfaceGridDimensions data = new SubsurfaceGridDimensions(); data.cellHeightPerLayer = new Vector<Float>(); data.numberWatConcCellsPerLayer = new Vector<Integer>(); for (short i = 0; i < numberOfLayers; i++) { data.cellHeightPerLayer.add(datastream.readFloat()); } // additional mean and max layer for (short i = 0; i < numberOfLayers + 2; i++) { data.numberWatConcCellsPerLayer.add(datastream.readInt()); } return data; }
@Override public void preProcess() throws IOException { validateFileLock(); fileHeader = new LibpcapGlobalHeader(getStream()); if (fileHeader.isSwapped()) { this.reader = new LittleEndianDataInputStream(getStream()); } else { this.reader = new DataInputStream(getStream()); } }
protected String readString(LittleEndianDataInputStream s) throws IOException { int len = s.readInt(); byte[] b = new byte[len]; s.readFully(b); String str = new String(b); while (len++ % 4 != 0) s.read(); return str; }
protected float[] readFloatArray(LittleEndianDataInputStream s) throws IOException { int len = s.readInt() / 4; float[] fs = new float[len]; for (int i = 0; i < len; ++i) { fs[i] = s.readFloat(); } return fs; }
protected double[] readDoubleArray(LittleEndianDataInputStream s) throws IOException { int len = s.readInt() / 4; double[] fs = new double[len]; for (int i = 0; i < len; ++i) { fs[i] = s.readDouble(); } return fs; }
protected double[] readDoubleWhichShouldBeFloatArray(LittleEndianDataInputStream s) throws IOException { int len = s.readInt() / 4; double[] fs = new double[len]; for (int i = 0; i < len; ++i) { // TODO ask IOS to return doubles fs[i] = s.readFloat(); } return fs; }
protected int[] readIntArray(LittleEndianDataInputStream s) throws IOException { int len = s.readInt() / 4; int[] is = new int[len]; for (int i = 0; i < len; ++i) { is[i] = s.readInt(); } return is; }
private static void checkStartBytes(KdbxHeader kdbxHeader, InputStream decryptedInputStream) throws IOException { LittleEndianDataInputStream ledis = new LittleEndianDataInputStream(decryptedInputStream); byte [] startBytes = new byte[32]; ledis.readFully(startBytes); if (!Arrays.equals(startBytes, kdbxHeader.getStreamStartBytes())) { throw new IllegalStateException("Inconsistent stream start bytes. This usually means the credentials were wrong."); } }
private static int getInt(LittleEndianDataInputStream ledis) throws IOException { short fieldLength = ledis.readShort(); if (fieldLength != 4) { throw new IllegalStateException("Int required but length was " + fieldLength); } return ledis.readInt(); }
private static long getLong(LittleEndianDataInputStream ledis) throws IOException { short fieldLength = ledis.readShort(); if (fieldLength != 8) { throw new IllegalStateException("Long required but length was " + fieldLength); } return ledis.readLong(); }
private List<NamedTag> read(byte[] data) { ArrayList<NamedTag> list = new ArrayList<>(); ByteArrayInputStream baos = new ByteArrayInputStream(data); try (NBTInputStream in = new NBTInputStream((DataInput) new LittleEndianDataInputStream(baos))) { while (baos.available() > 0) { NamedTag nt = in.readNamedTag(); list.add(nt); } } catch (IOException e) { e.printStackTrace(); } return list; }
@Test public void whenWriteReadLittleEndian_thenCorrect() throws IOException { final int value = 100; final LittleEndianDataOutputStream writer = new LittleEndianDataOutputStream(new FileOutputStream("src/test/resources/test_le.txt")); writer.writeInt(value); writer.close(); final LittleEndianDataInputStream reader = new LittleEndianDataInputStream(new DataInputStream(new FileInputStream("src/test/resources/test_le.txt"))); final int result = reader.readInt(); reader.close(); assertEquals(value, result); }
public static Gif decode(InputStream is) throws IOException { final LittleEndianDataInputStream in = new LittleEndianDataInputStream(is); final GifHeader header = readHeader(in); final GifContent content = readContent(header, in); final Gif gif = new Gif(header.getWidth(), header.getHeight(), content.getLoopCount(), header.getPixelAspectRatio(), header.getColorTable()); gif.getFrameList().addAll(content.getFrameList()); return gif; }
private Map(LittleEndianDataInputStream stream) throws DeedPlannerException, IOException { byte[] wakWordBytes = new byte[3]; stream.read(wakWordBytes); String wakWordString = new String(wakWordBytes, "US-ASCII"); if (!"WMP".equals(wakWordString)) { throw new DeedPlannerException("Not a WAK map"); } stream.skipBytes(20); width = Math.max(stream.readInt(), 50); height = Math.max(stream.readInt(), 50); tiles = new Tile[width+1][height+1]; for (int i=0; i<=width; i++) { for (int i2=0; i2<=height; i2++) { tiles[i][i2] = new Tile(this, i, i2); } } boolean bigMap = width > 255 || height> 255; stream.skipBytes(34); int tileCount = stream.readInt(); for (int i=0; i<tileCount; i++) { final int x = readCoordinate(stream, bigMap); final int y = height - readCoordinate(stream, bigMap) - 1; final int layers = stream.read(); if (layers==1 || layers==3) { tiles[x][y] = readTile(stream, x, y); } if (layers==2 || layers==3) { readTile(stream, x, y); } } createHeightData(); }
private int readCoordinate(LittleEndianDataInputStream stream, boolean bigMap) throws IOException { if (bigMap) { return stream.readInt(); } else { return stream.read(); } }
/** * Read ReleaseSiteData from dataStream * * @param dataStream * @throws IOException */ public static ReleaseSiteData readData( LittleEndianDataInputStream dataStream) throws IOException { ReleaseSiteData data = new ReleaseSiteData(); int numberReleaseSites = dataStream.readShort(); if (numberReleaseSites > 0) { Vector<ReleaseSite> sites = new Vector<ReleaseSite>(); for (int i = 0; i < numberReleaseSites; i++) { sites.add(ReleaseSiteDAO.readData(dataStream)); } data.sites = sites; } return data; }
/** * * @param datastream * @return * @throws IOException */ public static SurfaceCellOil readData(LittleEndianDataInputStream datastream) throws IOException { SurfaceCellOil data = new SurfaceCellOil(); data.cellIndex = datastream.readInt(); data.thickness = datastream.readFloat(); data.emulsionWaterContent = datastream.readFloat(); data.emulsionViscosity = datastream.readFloat(); data.coverage = datastream.readFloat(); return data; }
/** * * @param datastream * @return * @throws IOException */ public static SurfaceCellGas readData( LittleEndianDataInputStream datastream) throws IOException { SurfaceCellGas data = new SurfaceCellGas(); data.cellIndex = datastream.readInt(); data.massFlux = datastream.readFloat(); data.voidFraction = datastream.readFloat(); return data; }
/** * Create Specie with data from dataStream * @param dataStream * @throws IOException */ public static Specie readData(LittleEndianDataInputStream dataStream) throws IOException { int lengthOfSpecieName = dataStream.readShort(); Specie data = new Specie(); data.name = getString(dataStream, lengthOfSpecieName); int numberOfStages = dataStream.readShort(); for (int j = 0; j < numberOfStages; j++) { String stageName = getString(dataStream, dataStream.readShort()); data.stages.add(stageName); } return data; }
/** * * @param datastream * @return * @throws IOException */ public static WaterConcentration readData( LittleEndianDataInputStream datastream) throws IOException { WaterConcentration data = new WaterConcentration(); data.setiCell(datastream.readInt()); data.setConcentration(datastream.readFloat()); data.setTotalconcentration(datastream.readFloat()); data.setPercentEvap(datastream.readByte()); return data; }
/** * * @param dataStream * @param numberComponentsInProfile * @throws IOException */ public Release(LittleEndianDataInputStream dataStream, int numberComponentsInProfile) throws IOException { short lengthOfProfileName; lengthOfProfileName = dataStream.readShort(); this.profile = getString(dataStream, lengthOfProfileName); this.releaseRate = dataStream.readFloat(); this.componentConcentrations = new Vector<Float>(); for (int i = 0; i < numberComponentsInProfile; i++) { this.componentConcentrations.add(Float.valueOf(dataStream.readFloat())); } }
/** * @throws FileNotFoundException * @param file the file to read from * Provides a datastream im LitteEndian byteorder */ public BinaryFileDAO(File file) throws FileNotFoundException { super(); // Wrap the FileInputStream with a DataInputStream dataStream = new LittleEndianDataInputStream(new FileInputStream(file)); }
/** * @param myStream * @param length * @return String with length length read from myStream * @throws IOException */ public static String getString(LittleEndianDataInputStream myStream, int length) throws IOException { byte[] b = new byte[length]; myStream.read(b); return new String(b); }
/** * * @param dataStream * @return * @throws IOException */ public static BinaryHeader readData( LittleEndianDataInputStream dataStream) throws IOException { byte[] header = new byte[BinaryHeader.size]; dataStream.read(header); return new BinaryHeader(header); }
@Override public int[] deserialize(File file) throws IOException { LittleEndianDataInputStream is = new LittleEndianDataInputStream(new BufferedInputStream(new FileInputStream(file))); int[] ret = new int[(int)(file.length() / 4)]; for (int i = 0; i < ret.length; ++i) { ret[i] = is.readInt(); } return ret; }
public TempFileIterator( Path tempPath, int tmpCount, Serializer<K> keySerializer ) throws IOException { this.tmpCount = tmpCount; this.keySerializer = keySerializer; in = new LittleEndianDataInputStream(new BufferedInputStream(Files.newInputStream(tempPath), 131072)); }
public Reader(Path path, Comparator<K> comparator, Serializer<K> keySerializer, Serializer<V> valueSerializer, final boolean mlockFiles) throws IOException { this.comparator = comparator; indexFile = path.resolve("index.bin"); sizeInBytes = Files.size(indexFile); buffer = new MMapBuffer(indexFile, FileChannel.MapMode.READ_ONLY, ByteOrder.LITTLE_ENDIAN); try { stuffToClose = SharedReference.create((Closeable)buffer); final MemoryDataInput in = new MemoryDataInput(buffer.memory()); if (sizeInBytes < Header.length()) { throw new IOException("file is less than header length bytes"); } final byte[] headerBytes = new byte[Header.length()]; in.seek(sizeInBytes - Header.length()); in.readFully(headerBytes); final LittleEndianDataInputStream headerStream = new LittleEndianDataInputStream(new ByteArrayInputStream(headerBytes)); final Header header = new HeaderSerializer().read(headerStream); hasDeletions = header.hasDeletions; size = header.size; if (header.fileLength != sizeInBytes) { log.error(header.fileLength); throw new IOException("file length written to last 8 bytes of file does not match file length, file is inconsistent"); } rootLevel = Level.build(buffer.memory(), keySerializer, valueSerializer, comparator, header.hasDeletions, header.indexLevels); rootLevelStartAddress = header.rootLevelStartAddress; if (mlockFiles) buffer.mlock(0, buffer.memory().length()); } catch (Throwable t) { Closeables2.closeQuietly(buffer, log); Throwables.propagateIfInstanceOf(t, IOException.class); throw Throwables.propagate(t); } }
/** * 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. * @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); } } }