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

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

Introduction

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

Prototype

@Override
public float readFloat() throws IOException 

Source Link

Document

Reads a float as specified by DataInputStream#readFloat() , except using little-endian byte order.

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.
 *//*www .  j a v a  2  s .c om*/
@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);
    }
}