Example usage for java.io DataOutputStream writeFloat

List of usage examples for java.io DataOutputStream writeFloat

Introduction

In this page you can find the example usage for java.io DataOutputStream writeFloat.

Prototype

public final void writeFloat(float v) throws IOException 

Source Link

Document

Converts the float argument to an int using the floatToIntBits method in class Float, and then writes that int value to the underlying output stream as a 4-byte quantity, high byte first.

Usage

From source file:marytts.util.io.FileUtils.java

public static void writeBinaryFile(float[] x, DataOutputStream d) throws IOException {
    for (int i = 0; i < x.length; i++)
        d.writeFloat(x[i]);
}

From source file:RealFunctionValidation.java

public static Object readAndWritePrimitiveValue(final DataInputStream in, final DataOutputStream out,
        final Class<?> type) throws IOException {

    if (!type.isPrimitive()) {
        throw new IllegalArgumentException("type must be primitive");
    }//  w ww  . j  a  va2s  .com
    if (type.equals(Boolean.TYPE)) {
        final boolean x = in.readBoolean();
        out.writeBoolean(x);
        return Boolean.valueOf(x);
    } else if (type.equals(Byte.TYPE)) {
        final byte x = in.readByte();
        out.writeByte(x);
        return Byte.valueOf(x);
    } else if (type.equals(Character.TYPE)) {
        final char x = in.readChar();
        out.writeChar(x);
        return Character.valueOf(x);
    } else if (type.equals(Double.TYPE)) {
        final double x = in.readDouble();
        out.writeDouble(x);
        return Double.valueOf(x);
    } else if (type.equals(Float.TYPE)) {
        final float x = in.readFloat();
        out.writeFloat(x);
        return Float.valueOf(x);
    } else if (type.equals(Integer.TYPE)) {
        final int x = in.readInt();
        out.writeInt(x);
        return Integer.valueOf(x);
    } else if (type.equals(Long.TYPE)) {
        final long x = in.readLong();
        out.writeLong(x);
        return Long.valueOf(x);
    } else if (type.equals(Short.TYPE)) {
        final short x = in.readShort();
        out.writeShort(x);
        return Short.valueOf(x);
    } else {
        // This should never occur.
        throw new IllegalStateException();
    }
}

From source file:src.util.Vec3D.java

public Vec3D saveTo(DataOutputStream out) throws Exception {
    out.writeFloat(x);
    out.writeFloat(y);/*www.  ja  va 2s. co m*/
    out.writeFloat(z);
    return this;
}

From source file:src.util.Vec2D.java

public Vec2D saveTo(DataOutputStream out) throws Exception {
    out.writeFloat(x);
    out.writeFloat(y);//from  ww w .ja va 2  s . co m
    return this;
}

From source file:com.ebay.nest.io.sede.lazy.LazyUtils.java

/**
 * Write out a binary representation of a PrimitiveObject to a byte stream.
 *
 * @param out ByteStream.Output, an unsynchronized version of ByteArrayOutputStream, used as a
 *            backing buffer for the the DataOutputStream
 * @param o the PrimitiveObject/*from w  w  w.  j  a v a 2 s.c om*/
 * @param oi the PrimitiveObjectInspector
 * @throws IOException on error during the write operation
 */
public static void writePrimitive(OutputStream out, Object o, PrimitiveObjectInspector oi) throws IOException {

    DataOutputStream dos = new DataOutputStream(out);

    try {
        switch (oi.getPrimitiveCategory()) {
        case BOOLEAN:
            boolean b = ((BooleanObjectInspector) oi).get(o);
            dos.writeBoolean(b);
            break;

        case BYTE:
            byte bt = ((ByteObjectInspector) oi).get(o);
            dos.writeByte(bt);
            break;

        case SHORT:
            short s = ((ShortObjectInspector) oi).get(o);
            dos.writeShort(s);
            break;

        case INT:
            int i = ((IntObjectInspector) oi).get(o);
            dos.writeInt(i);
            break;

        case LONG:
            long l = ((LongObjectInspector) oi).get(o);
            dos.writeLong(l);
            break;

        case FLOAT:
            float f = ((FloatObjectInspector) oi).get(o);
            dos.writeFloat(f);
            break;

        case DOUBLE:
            double d = ((DoubleObjectInspector) oi).get(o);
            dos.writeDouble(d);
            break;

        default:
            throw new RuntimeException("Hive internal error.");
        }
    } finally {
        // closing the underlying ByteStream should have no effect, the data should still be
        // accessible
        dos.close();
    }
}

From source file:org.apache.hadoop.hive.serde2.lazy.LazyUtils.java

/**
 * Write out a binary representation of a PrimitiveObject to a byte stream.
 *
 * @param out ByteStream.Output, an unsynchronized version of ByteArrayOutputStream, used as a
 *            backing buffer for the the DataOutputStream
 * @param o the PrimitiveObject/*ww  w .j av  a2 s. c o m*/
 * @param oi the PrimitiveObjectInspector
 * @throws IOException on error during the write operation
 */
public static void writePrimitive(OutputStream out, Object o, PrimitiveObjectInspector oi) throws IOException {

    DataOutputStream dos = new DataOutputStream(out);

    try {
        switch (oi.getPrimitiveCategory()) {
        case BOOLEAN:
            boolean b = ((BooleanObjectInspector) oi).get(o);
            dos.writeBoolean(b);
            break;

        case BYTE:
            byte bt = ((ByteObjectInspector) oi).get(o);
            dos.writeByte(bt);
            break;

        case SHORT:
            short s = ((ShortObjectInspector) oi).get(o);
            dos.writeShort(s);
            break;

        case INT:
            int i = ((IntObjectInspector) oi).get(o);
            dos.writeInt(i);
            break;

        case LONG:
            long l = ((LongObjectInspector) oi).get(o);
            dos.writeLong(l);
            break;

        case FLOAT:
            float f = ((FloatObjectInspector) oi).get(o);
            dos.writeFloat(f);
            break;

        case DOUBLE:
            double d = ((DoubleObjectInspector) oi).get(o);
            dos.writeDouble(d);
            break;

        case BINARY: {
            BytesWritable bw = ((BinaryObjectInspector) oi).getPrimitiveWritableObject(o);
            out.write(bw.getBytes(), 0, bw.getLength());
            break;
        }

        default:
            throw new RuntimeException("Hive internal error.");
        }
    } finally {
        // closing the underlying ByteStream should have no effect, the data should still be
        // accessible
        dos.close();
    }
}

From source file:com.mbrlabs.mundus.assets.EditorAssetManager.java

public TerrainAsset createTerrainAsset(int vertexResolution, int size) throws IOException {
    String terraFilename = "terrain_" + UUID.randomUUID().toString() + ".terra";
    String metaFilename = terraFilename + ".meta";

    // create meta file
    String metaPath = FilenameUtils.concat(rootFolder.path(), metaFilename);
    MetaFile meta = createNewMetaFile(new FileHandle(metaPath), AssetType.TERRAIN);
    meta.setTerrainSize(size);//from   ww  w .  ja  v  a 2s .  co m
    meta.save();

    // create terra file
    String terraPath = FilenameUtils.concat(rootFolder.path(), terraFilename);
    File terraFile = new File(terraPath);
    FileUtils.touch(terraFile);

    // create initial height data
    float[] data = new float[vertexResolution * vertexResolution];
    for (int i = 0; i < data.length; i++) {
        data[i] = 0;
    }

    // write terra file
    DataOutputStream outputStream = new DataOutputStream(
            new BufferedOutputStream(new GZIPOutputStream(new FileOutputStream(terraFile))));
    for (float f : data) {
        outputStream.writeFloat(f);
    }
    outputStream.flush();
    outputStream.close();

    // load & apply standard chessboard texture
    TerrainAsset asset = new TerrainAsset(meta, new FileHandle(terraFile));
    asset.load();

    TextureAsset chessboard = (TextureAsset) findAssetByID(STANDARD_ASSET_TEXTURE_CHESSBOARD);
    if (chessboard != null) {
        // create splatmap
        PixmapTextureAsset splatmap = createPixmapTextureAsset(SplatMap.DEFAULT_SIZE);
        asset.setSplatmap(splatmap);
        asset.setSplatBase(chessboard);
        asset.applyDependencies();
    }

    addAsset(asset);
    return asset;
}

From source file:com.mbrlabs.mundus.assets.EditorAssetManager.java

public void saveTerrainAssets() throws IOException {
    for (TerrainAsset terrain : getTerrainAssets()) {

        // save .terra file
        DataOutputStream outputStream = new DataOutputStream(
                new BufferedOutputStream(new GZIPOutputStream(new FileOutputStream(terrain.getFile().file()))));
        for (float f : terrain.getData()) {
            outputStream.writeFloat(f);
        }/*from w w w  .jav a2 s .  c  om*/
        outputStream.flush();
        outputStream.close();

        // save splatmap
        PixmapTextureAsset splatmap = terrain.getSplatmap();
        if (splatmap != null) {
            PixmapIO.writePNG(splatmap.getFile(), splatmap.getPixmap());
        }

        // save meta file
        terrain.getMeta().save();
    }
}

From source file:com.rapidminer.cryptography.hashing.DigesterProvider.java

/**
 * Writes the provided value to the provided {@link DataOutputStream}.
 *///from www .j  ava 2  s.com
private void writeBytes(Object value, DataOutputStream dos) throws IOException, JEPFunctionException {
    if (value instanceof String) {
        dos.writeUTF((String) value);
    } else if (value instanceof Integer) {
        dos.writeInt((int) value);
    } else if (value instanceof Long) {
        dos.writeLong((long) value);
    } else if (value instanceof Float) {
        dos.writeFloat((float) value);
    } else if (value instanceof GregorianCalendar) {
        dos.writeLong(((GregorianCalendar) value).getTimeInMillis());
    } else if (value instanceof Date) {
        dos.writeLong(((Date) value).getTime());
    } else if (value instanceof Double) {
        dos.writeDouble((double) value);
    } else if (value instanceof UnknownValue) {
        dos.writeDouble(Double.NaN);
    } else {
        // should not happen
        throw new JEPFunctionException("Unknown input type: " + value.getClass());
    }
}

From source file:org.structr.core.graph.SyncCommand.java

private static void writeObject(final DataOutputStream outputStream, final byte type, final Object value)
        throws IOException {

    switch (type) {

    case 0://from   w w  w . j ava2s.  c  om
    case 1:
        outputStream.writeByte((byte) value);
        break;

    case 2:
    case 3:
        outputStream.writeShort((short) value);
        break;

    case 4:
    case 5:
        outputStream.writeInt((int) value);
        break;

    case 6:
    case 7:
        outputStream.writeLong((long) value);
        break;

    case 8:
    case 9:
        outputStream.writeFloat((float) value);
        break;

    case 10:
    case 11:
        outputStream.writeDouble((double) value);
        break;

    case 12:
    case 13:
        outputStream.writeChar((char) value);
        break;

    case 14:
    case 15:
        serializeData(outputStream, ((String) value).getBytes("UTF-8"));

        // this doesn't work with very long strings
        //outputStream.writeUTF((String)value);
        break;

    case 16:
    case 17:
        outputStream.writeBoolean((boolean) value);
        break;
    }
}