List of usage examples for java.io DataInputStream readDouble
public final double readDouble() throws IOException
readDouble
method of DataInput
. From source file:Main.java
public static double readDecimal(DataInputStream in) throws IOException { return in.readDouble(); }
From source file:ReadBinaryFile.java
private static Product readMovie(DataInputStream in) { String title = ""; int year = 0; double price = 0.0; try {// ww w.j a v a 2s. co m title = in.readUTF(); year = in.readInt(); price = in.readDouble(); } catch (EOFException e) { return null; } catch (IOException e) { System.out.println("I/O Error"); System.exit(0); } return new Product(title, year, price); }
From source file:com.opensoc.json.serialization.JSONDecoderHelper.java
public static Number getNumber(DataInputStream data) throws IOException { // Treating all ints,shorts, long as long. // Everything else as Double int flag = data.readByte(); if (flag == 0) return data.readDouble(); return data.readLong(); }
From source file:cfa.vo.interop.EncodeDoubleArray.java
private static double[] byteToDouble(byte[] data) throws IOException { int len = data.length; if (len % WORDSIZE != 0) { throw new IOException("Array length is not divisible by wordsize"); }/* w w w.ja v a 2s .c o m*/ int size = len / WORDSIZE; double[] result = new double[size]; DataInputStream inputStream = new DataInputStream(new ByteArrayInputStream(data)); try { int ii = 0; while (inputStream.available() > 0) { result[ii] = inputStream.readDouble(); 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"); } return result; }
From source file:IO.java
public static double[][] readBinaryData(File file, int nData, int nDim) { FileInputStream inStream;//from w w w . j a v a 2 s .c om double[][] data = new double[nData][nDim]; try { inStream = new FileInputStream(file); DataInputStream input = new DataInputStream(inStream); for (int i = 0; i < nData; i++) for (int j = 0; j < nDim; j++) { data[i][j] = input.readDouble(); } } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return data; }
From source file:org.apache.flink.runtime.metrics.dump.MetricDumpSerialization.java
private static MetricDump.MeterDump deserializeMeter(DataInputStream dis) throws IOException { QueryScopeInfo info = deserializeMetricInfo(dis); String name = deserializeString(dis); double rate = dis.readDouble(); return new MetricDump.MeterDump(info, name, rate); }
From source file:com.splout.db.benchmark.TCPTest.java
public static void tcpTest(String file, String table) throws UnknownHostException, IOException, InterruptedException, JSONSerDeException { final TCPServer server = new TCPServer(8888, file, table); Thread t = new Thread() { @Override/* w w w .ja va 2 s . com*/ public void run() { server.serve(); } }; t.start(); while (!server.isServing()) { Thread.sleep(100); } Socket clientSocket = new Socket("localhost", 8888); DataInputStream inFromServer = new DataInputStream(new BufferedInputStream(clientSocket.getInputStream())); try { do { // Read a record inFromServer.readUTF(); inFromServer.readInt(); inFromServer.readDouble(); inFromServer.readUTF(); } while (true); } catch (Throwable th) { th.printStackTrace(); } clientSocket.close(); server.stop(); t.interrupt(); }
From source file:org.apache.flink.runtime.metrics.dump.MetricDumpSerialization.java
private static MetricDump.HistogramDump deserializeHistogram(DataInputStream dis) throws IOException { QueryScopeInfo info = deserializeMetricInfo(dis); String name = deserializeString(dis); long min = dis.readLong(); long max = dis.readLong(); double mean = dis.readDouble(); double median = dis.readDouble(); double stddev = dis.readDouble(); double p75 = dis.readDouble(); double p90 = dis.readDouble(); double p95 = dis.readDouble(); double p98 = dis.readDouble(); double p99 = dis.readDouble(); double p999 = dis.readDouble(); return new MetricDump.HistogramDump(info, name, min, max, mean, median, stddev, p75, p90, p95, p98, p99, p999);/*from w w w . j a v a2s . c o m*/ }
From source file:Main.java
public static Object[] readSettings(String file) throws IOException { DataInputStream in = new DataInputStream(new FileInputStream(file)); try {// w w w. j ava 2s .co m Object[] res = new Object[in.readInt()]; for (int i = 0; i < res.length; i++) { char cl = in.readChar(); switch (cl) { case 'S': res[i] = in.readUTF(); break; case 'F': res[i] = in.readFloat(); break; case 'D': res[i] = in.readDouble(); break; case 'I': res[i] = in.readInt(); break; case 'L': res[i] = in.readLong(); break; case 'B': res[i] = in.readBoolean(); break; case 'Y': res[i] = in.readByte(); break; default: throw new IllegalStateException("cannot read type " + cl + " from " + file); } } return res; } finally { in.close(); } }
From source file:uk.ac.ebi.mdk.io.ReactionMatrixIO.java
public static StoichiometricMatrix readCompressedBasicStoichiometricMatrix(InputStream stream, StoichiometricMatrix s) throws IOException { DataInputStream in = new DataInputStream(stream); int n = in.readInt(); int m = in.readInt(); s.ensure(n, m);// w w w . j a va 2s . co m for (int j = 0; j < m; j++) { s.setReaction(j, in.readUTF()); } for (int i = 0; i < n; i++) { s.setMolecule(i, in.readUTF()); } boolean convert = in.readBoolean(); int size = in.readInt(); while (--size >= 0) { int i = in.readInt(); int j = in.readInt(); Object value = convert ? in.readInt() : in.readDouble(); Double dValue = value instanceof Double ? (Double) value : ((Integer) value).doubleValue(); s.setValue(i, j, dValue); } in.close(); return s; }