Example usage for com.google.common.io LittleEndianDataInputStream skipBytes

List of usage examples for com.google.common.io LittleEndianDataInputStream skipBytes

Introduction

In this page you can find the example usage for com.google.common.io LittleEndianDataInputStream skipBytes.

Prototype

@Override
    public int skipBytes(int n) throws IOException 

Source Link

Usage

From source file:org.esa.nest.gpf.ReadRatFileOp.java

/**
 * Called by the framework in order to compute a tile for the given target band.
 * <p>The default implementation throws a runtime exception with the message "not implemented".</p>
 *
 * @param targetTileMap   The target tiles associated with all target bands to be computed.
 * @param targetRectangle The rectangle of target tile.
 * @param pm              A progress monitor which should be used to determine computation cancelation requests.
 * @throws org.esa.beam.framework.gpf.OperatorException
 *          If an error occurs during computation of the target raster.
 *//*  ww w.ja  v  a  2 s.  c  o m*/
@Override
public synchronized void computeTileStack(Map<Band, Tile> targetTileMap, Rectangle targetRectangle,
        ProgressMonitor pm) throws OperatorException {

    final int x0 = targetRectangle.x;
    final int y0 = targetRectangle.y;
    final int w = targetRectangle.width;
    final int h = targetRectangle.height;
    final int xMax = x0 + w;
    final int yMax = y0 + h;
    //System.out.println("x0 = " + x0 + ", y0 = " + y0 + ", w = " + w + ", h = " + h);

    final Band tgtBandI = targetProduct.getBand("i_band");
    final Band tgtBandQ = targetProduct.getBand("q_band");
    final Tile tgtTileI = targetTileMap.get(tgtBandI);
    final Tile tgtTileQ = targetTileMap.get(tgtBandQ);
    final ProductData tgtBufferI = tgtTileI.getDataBuffer();
    final ProductData tgtBufferQ = tgtTileQ.getDataBuffer();
    final TileIndex tgtIndex = new TileIndex(tgtTileI);

    try {
        LittleEndianDataInputStream in = new LittleEndianDataInputStream(
                new BufferedInputStream(new FileInputStream(ratFilePath)));
        in.skipBytes(1000 + y0 * width * 4 * 2);

        for (int y = y0; y < yMax; y++) {
            tgtIndex.calculateStride(y);
            for (int x = x0; x < xMax; x++) {
                final int tgtIdx = tgtIndex.getIndex(x);
                final float vI = in.readFloat();
                final float vQ = in.readFloat();
                tgtBufferI.setElemDoubleAt(tgtIdx, vI);
                tgtBufferQ.setElemDoubleAt(tgtIdx, vQ);
            }
        }

        in.close();

    } catch (Throwable e) {
        OperatorUtils.catchOperatorException("computeTileStack", e);
    }
}

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.//from  w ww.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);
        }
    }
}