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 writeSettings(String file, Object... objs) throws IOException { DataOutputStream out = new DataOutputStream(new BufferedOutputStream(new FileOutputStream(file), 1024)); try {//from w ww. java2 s .c o m out.writeInt(objs.length); for (Object obj : objs) { char cl; if (obj instanceof Byte) { cl = 'Y'; } else { cl = obj.getClass().getSimpleName().charAt(0); } out.writeChar(cl); if (obj instanceof String) { out.writeUTF((String) obj); } else if (obj instanceof Float) { out.writeFloat((Float) obj); } else if (obj instanceof Double) { out.writeDouble((Double) obj); } else if (obj instanceof Integer) { out.writeInt((Integer) obj); } else if (obj instanceof Long) { out.writeLong((Long) obj); } else if (obj instanceof Boolean) { out.writeBoolean((Boolean) obj); } else { throw new IllegalStateException("Unsupported type"); } } } finally { out.close(); } }
From source file:net.datenwerke.transloader.primitive.WrapperConverter.java
private static void write(Object wrapper, DataOutputStream dataStream) throws IOException { char typeCode = getTypeCode(wrapper); switch (typeCode) { case 'B': dataStream.writeByte(intValue(wrapper)); break;/* ww w .j a v a2 s. c o m*/ case 'C': dataStream.writeChar(charValue(wrapper)); break; case 'S': dataStream.writeShort(intValue(wrapper)); break; case 'I': dataStream.writeInt(intValue(wrapper)); break; case 'J': dataStream.writeLong(number(wrapper).longValue()); break; case 'F': dataStream.writeFloat(number(wrapper).floatValue()); break; case 'D': dataStream.writeDouble(number(wrapper).doubleValue()); break; case 'Z': dataStream.writeBoolean(booleanValue(wrapper)); } }
From source file:marytts.util.io.FileUtils.java
public static void writeBinaryFile(double[] x, DataOutputStream d) throws IOException { for (int i = 0; i < x.length; i++) d.writeDouble(x[i]); }
From source file:org.hyperic.hq.measurement.agent.server.SenderThread.java
private static String encodeRecord(Record record) throws IOException { ByteArrayOutputStream bOs;//from w w w.j a va2s . com DataOutputStream dOs; bOs = new ByteArrayOutputStream(); dOs = new DataOutputStream(bOs); dOs.writeInt(record.derivedID); dOs.writeLong(record.data.getTimestamp()); dOs.writeInt(record.dsnId); dOs.writeDouble(record.data.getValue()); return Base64.encode(bOs.toByteArray()); }
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"); }/*from w w w .ja v a 2 s . co m*/ 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:com.anhth12.word2vec.VocabWord.java
public void write(DataOutputStream out) throws IOException { out.writeDouble(this.wordFrequency.get()); }
From source file:org.deeplearning4j.models.word2vec.VocabWord.java
public void write(DataOutputStream dos) throws IOException { dos.writeDouble(wordFrequency.get()); }
From source file:TimeComputation.java
public void run() throws IOException { DataOutputStream n = new DataOutputStream(new BufferedOutputStream(new FileOutputStream("java2s"))); long t0, t1;//w ww. j ava2 s . com System.out.println("Java Starts at " + (t0 = System.currentTimeMillis())); double k; for (int i = 0; i < 100000; i++) { k = 2.1 * Math.sqrt((double) i); n.writeDouble(k); } System.out.println("Java Ends at " + (t1 = System.currentTimeMillis())); double deltaT = t1 - t0; System.out.println("This run took " + DecimalFormat.getInstance().format(deltaT / 1000.) + " seconds."); }
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 ww .j a v a 2 s. co 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; 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:uk.ac.ebi.mdk.io.ReactionMatrixIO.java
public static void writeCompressedBasicStoichiometricMatrix(StoichiometricMatrix<?, ?> s, OutputStream writer) throws IOException { DataOutputStream out = new DataOutputStream(new BufferedOutputStream(writer, 2048)); int n = s.getMoleculeCount(); int m = s.getReactionCount(); out.writeInt(n);//from w w w . j a v a 2 s. co m out.writeInt(m); for (int j = 0; j < m; j++) { out.writeUTF(s.getReaction(j).toString()); } for (int i = 0; i < n; i++) { out.writeUTF(s.getMolecule(i).toString()); } out.writeBoolean(convertDoubles); out.writeInt(s.getNonNullCount()); for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { // if the value is null if (convertDoubles) { int value = s.get(i, j).intValue(); if (value != 0) { out.writeInt(i); out.writeInt(j); out.writeInt(value); } } else { double value = s.get(i, j); if (value != 0d) { out.writeInt(i); out.writeInt(j); out.writeDouble(value); } } } } out.close(); }