List of usage examples for java.io DataOutputStream writeDouble
public final void writeDouble(double v) throws IOException
long
using the doubleToLongBits
method in class Double
, and then writes that long
value to the underlying output stream as an 8-byte quantity, high byte first. From source file:Main.java
public static void main(String[] args) throws Exception { ByteArrayOutputStream baos = new ByteArrayOutputStream(); DataOutputStream dos = new DataOutputStream(baos); MessageDigest md = MessageDigest.getInstance("MD5"); SomeObject testObject = new SomeObject(); dos.writeInt(testObject.count);//from w w w .j a va 2s. co m dos.writeLong(testObject.product); dos.writeDouble(testObject.stdDev); dos.writeUTF(testObject.name); dos.writeChar(testObject.delimiter); dos.flush(); byte[] hashBytes = md.digest(baos.toByteArray()); BigInteger testObjectHash = new BigInteger(hashBytes); System.out.println("Hash " + testObjectHash); dos.close(); }
From source file:DataIODemo.java
public static void main(String[] args) throws IOException { // write the data out DataOutputStream out = new DataOutputStream(new FileOutputStream("invoice1.txt")); double[] prices = { 19.99, 9.99, 15.99, 3.99, 4.99 }; int[] units = { 12, 8, 13, 29, 50 }; String[] descs = { "Java T-shirt", "Java Mug", "Duke Juggling Dolls", "Java Pin", "Java Key Chain" }; for (int i = 0; i < prices.length; i++) { out.writeDouble(prices[i]); out.writeChar('\t'); out.writeInt(units[i]);//from www . j av a 2 s . c o m out.writeChar('\t'); out.writeChars(descs[i]); out.writeChar('\n'); } out.close(); // read it in again DataInputStream in = new DataInputStream(new FileInputStream("invoice1.txt")); double price; int unit; StringBuffer desc; double total = 0.0; try { while (true) { price = in.readDouble(); in.readChar(); // throws out the tab unit = in.readInt(); in.readChar(); // throws out the tab char chr; desc = new StringBuffer(20); char lineSep = System.getProperty("line.separator").charAt(0); while ((chr = in.readChar()) != lineSep) desc.append(chr); System.out.println("You've ordered " + unit + " units of " + desc + " at $" + price); total = total + unit * price; } } catch (EOFException e) { } System.out.println("For a TOTAL of: $" + total); in.close(); }
From source file:Main.java
public static void writeDecimal(DataOutputStream out, double val) throws IOException { out.writeDouble(val); }
From source file:WriteBinaryFile.java
private static void writeMovie(Product m, DataOutputStream out) throws Exception { out.writeUTF(m.title);/*www .ja va2s . c om*/ out.writeInt(m.year); out.writeDouble(m.price); }
From source file:MainClass.java
public static byte[] makeBytes(long t, double q) { try {//from w ww. j a va 2 s . c o m ByteArrayOutputStream byteOut = new ByteArrayOutputStream(); DataOutputStream dataOut = new DataOutputStream(byteOut); dataOut.writeLong(t); dataOut.writeDouble(q); return byteOut.toByteArray(); } catch (IOException e) { return new byte[0]; } }
From source file:Main.java
public static byte[] createAuthenticationDigest(String passcode, long t1, double q1) throws IOException, NoSuchAlgorithmException { ByteArrayOutputStream baos = new ByteArrayOutputStream(512); DataOutputStream out = new DataOutputStream(baos); byte[] digest = createDigest(passcode, t1, q1); out.writeLong(t1);//from ww w. ja v a 2 s . com out.writeDouble(q1); out.writeInt(digest.length); out.write(digest); out.flush(); return baos.toByteArray(); }
From source file:cfa.vo.interop.EncodeDoubleArray.java
private static byte[] doubleToByte(double[] data) throws IOException { ByteArrayOutputStream byteStream = new ByteArrayOutputStream(); DataOutputStream outputStream = new DataOutputStream(byteStream); try {/* ww w . j ava 2 s .c o m*/ for (int ii = 0; ii < data.length; ii++) outputStream.writeDouble(data[ii]); } catch (EOFException e) { throw new IOException("Unable to read from dataInputStream, found EOF"); } catch (IOException e) { throw new IOException("Unable to read from dataInputStream, IO error"); } byte[] result = byteStream.toByteArray(); return result; }
From source file:com.opensoc.json.serialization.JSONEncoderHelper.java
public static void putNumber(DataOutputStream data, Number value) throws IOException { // TODO Auto-generated method stub data.writeByte(JSONKafkaSerializer.NumberID); if (value instanceof Double) { data.writeByte(0);// w w w . j a va2s.c om data.writeDouble((Double) value); return; } data.writeByte(1); data.writeLong((Long) value); }
From source file:org.apache.flink.runtime.metrics.dump.MetricDumpSerialization.java
private static void serializeMeter(DataOutputStream dos, Meter meter) throws IOException { dos.writeDouble(meter.getRate()); }
From source file:org.apache.flink.runtime.metrics.dump.MetricDumpSerialization.java
private static void serializeHistogram(DataOutputStream dos, Histogram histogram) throws IOException { HistogramStatistics stat = histogram.getStatistics(); dos.writeLong(stat.getMin());/*from w w w . j av a2 s .com*/ dos.writeLong(stat.getMax()); dos.writeDouble(stat.getMean()); dos.writeDouble(stat.getQuantile(0.5)); dos.writeDouble(stat.getStdDev()); dos.writeDouble(stat.getQuantile(0.75)); dos.writeDouble(stat.getQuantile(0.90)); dos.writeDouble(stat.getQuantile(0.95)); dos.writeDouble(stat.getQuantile(0.98)); dos.writeDouble(stat.getQuantile(0.99)); dos.writeDouble(stat.getQuantile(0.999)); }