Here you can find the source of writeFloat(OutputStream os, float val, ByteOrder bo)
Parameter | Description |
---|---|
os | a parameter |
val | a parameter |
bo | a parameter |
Parameter | Description |
---|---|
IOException | an exception |
public static void writeFloat(OutputStream os, float val, ByteOrder bo) throws IOException
//package com.java2s; /*/* w w w. j a v a2 s . c om*/ Copyright (c) 2009-2011 Speech Group at Informatik 5, Univ. Erlangen-Nuremberg, GERMANY Korbinian Riedhammer Tobias Bocklet This file is part of the Java Speech Toolkit (JSTK). The JSTK is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. The JSTK is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with the JSTK. If not, see <http://www.gnu.org/licenses/>. */ import java.io.BufferedWriter; import java.io.IOException; import java.io.OutputStream; import java.nio.ByteBuffer; import java.nio.ByteOrder; public class Main { /** * Write a float to the OutputStream * pointer respectively. * @param os * @param val * @param bo * @return * @throws IOException */ public static void writeFloat(OutputStream os, float val, ByteOrder bo) throws IOException { ByteBuffer bb = ByteBuffer.allocate(Float.SIZE / 8); bb.order(bo); bb.putFloat(val); os.write(bb.array()); } /** * Write the given float array to the OutputStream using the specified * ByteOrder * @param os * @param buf * @param bo * @throws IOException */ public static void writeFloat(OutputStream os, float[] buf, ByteOrder bo) throws IOException { ByteBuffer bb = ByteBuffer.allocate(buf.length * Float.SIZE / 8); bb.order(bo); for (float f : buf) bb.putFloat(f); os.write(bb.array()); } /** * Write the given double array as floats to the OutputStream using the * specified ByteOrder * @param os * @param buf * @param bo * @throws IOException */ public static void writeFloat(OutputStream os, double[] buf, ByteOrder bo) throws IOException { ByteBuffer bb = ByteBuffer.allocate(buf.length * Float.SIZE / 8); bb.order(bo); for (double d : buf) { // truncate to 3 digits int i = (int) Math.round(d * 1000); d = (double) i / 1000; bb.putFloat((float) d); } os.write(bb.array()); } /** * Write a given float array to the ASCII stream * @param bw * @param buf * @throws IOException */ public static void writeFloat(BufferedWriter bw, float[] buf) throws IOException { StringBuffer sb = new StringBuffer(); for (int i = 0; i < buf.length - 1; ++i) sb.append(Float.toString(buf[i]) + " "); sb.append(Float.toString(buf[buf.length - 1]) + "\n"); bw.append(sb.toString()); } }