Example usage for java.io ObjectInputStream readDouble

List of usage examples for java.io ObjectInputStream readDouble

Introduction

In this page you can find the example usage for java.io ObjectInputStream readDouble.

Prototype

public double readDouble() throws IOException 

Source Link

Document

Reads a 64 bit double.

Usage

From source file:Main.java

public static void main(String[] args) throws Exception {

    double b = 123.234d;

    FileOutputStream out = new FileOutputStream("test.txt");
    ObjectOutputStream oout = new ObjectOutputStream(out);

    // write something in the file
    oout.writeDouble(b);//w  ww  . j  av  a 2  s. co m
    oout.writeDouble(456.789d);
    oout.flush();
    oout.close();
    // create an ObjectInputStream for the file we created before
    ObjectInputStream ois = new ObjectInputStream(new FileInputStream("test.txt"));

    // read and print a double
    System.out.println(ois.readDouble());

    // read and print a double
    System.out.println(ois.readDouble());
    ois.close();
}

From source file:DataIOTest2.java

public static void main(String[] args) throws IOException {

    // write the data out
    ObjectOutputStream out = new ObjectOutputStream(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]);/*w w  w.j a v  a 2  s . c  o  m*/
        out.writeChar('\t');
        out.writeInt(units[i]);
        out.writeChar('\t');
        out.writeChars(descs[i]);
        out.writeChar('\n');
    }
    out.close();

    // read it in again
    ObjectInputStream in = new ObjectInputStream(new FileInputStream("invoice1.txt"));

    double price;
    int unit;
    String 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
            desc = in.readLine();
            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

/**
 * Reads a <code>Point2D</code> object that has been serialised by the
 * {@link #writePoint2D(Point2D, ObjectOutputStream)} method.
 *
 * @param stream  the input stream (<code>null</code> not permitted).
 *
 * @return The point object (possibly <code>null</code>).
 *
 * @throws IOException  if there is an I/O problem.
 *//*w w w. java2  s.  c  o m*/
public static Point2D readPoint2D(final ObjectInputStream stream) throws IOException {

    if (stream == null) {
        throw new IllegalArgumentException("Null 'stream' argument.");
    }
    Point2D result = null;
    final boolean isNull = stream.readBoolean();
    if (!isNull) {
        final double x = stream.readDouble();
        final double y = stream.readDouble();
        result = new Point2D.Double(x, y);
    }
    return result;

}

From source file:org.mrgeo.utils.Base64Utils.java

public static double[] decodeToDoubleArray(String encoded) throws IOException {
    byte[] objBytes = Base64.decodeBase64(encoded.getBytes());

    ByteArrayInputStream bais = null;
    ObjectInputStream ois = null;

    try {//w w  w. j  av  a 2 s . c o  m
        bais = new ByteArrayInputStream(objBytes);
        ois = new ObjectInputStream(bais);
        int arrayLength = ois.readInt();
        double result[] = new double[arrayLength];
        for (int i = 0; i < arrayLength; i++) {
            result[i] = ois.readDouble();
        }
        return result;
    } finally {
        if (ois != null) {
            ois.close();
        }
        if (bais != null) {
            bais.close();
        }
    }
}

From source file:Main.java

/**
 * Reads a <code>Shape</code> object that has been serialised by the
 * {@link #writeShape(Shape, ObjectOutputStream)} method.
 *
 * @param stream  the input stream (<code>null</code> not permitted).
 *
 * @return The shape object (possibly <code>null</code>).
 *
 * @throws IOException  if there is an I/O problem.
 * @throws ClassNotFoundException  if there is a problem loading a class.
 *///from   www . j a  va2 s.com
public static Shape readShape(final ObjectInputStream stream) throws IOException, ClassNotFoundException {

    if (stream == null) {
        throw new IllegalArgumentException("Null 'stream' argument.");
    }
    Shape result = null;
    final boolean isNull = stream.readBoolean();
    if (!isNull) {
        final Class c = (Class) stream.readObject();
        if (c.equals(Line2D.class)) {
            final double x1 = stream.readDouble();
            final double y1 = stream.readDouble();
            final double x2 = stream.readDouble();
            final double y2 = stream.readDouble();
            result = new Line2D.Double(x1, y1, x2, y2);
        } else if (c.equals(Rectangle2D.class)) {
            final double x = stream.readDouble();
            final double y = stream.readDouble();
            final double w = stream.readDouble();
            final double h = stream.readDouble();
            result = new Rectangle2D.Double(x, y, w, h);
        } else if (c.equals(Ellipse2D.class)) {
            final double x = stream.readDouble();
            final double y = stream.readDouble();
            final double w = stream.readDouble();
            final double h = stream.readDouble();
            result = new Ellipse2D.Double(x, y, w, h);
        } else if (c.equals(Arc2D.class)) {
            final double x = stream.readDouble();
            final double y = stream.readDouble();
            final double w = stream.readDouble();
            final double h = stream.readDouble();
            final double as = stream.readDouble(); // Angle Start
            final double ae = stream.readDouble(); // Angle Extent
            final int at = stream.readInt(); // Arc type
            result = new Arc2D.Double(x, y, w, h, as, ae, at);
        } else if (c.equals(GeneralPath.class)) {
            final GeneralPath gp = new GeneralPath();
            final float[] args = new float[6];
            boolean hasNext = stream.readBoolean();
            while (!hasNext) {
                final int type = stream.readInt();
                for (int i = 0; i < 6; i++) {
                    args[i] = stream.readFloat();
                }
                switch (type) {
                case PathIterator.SEG_MOVETO:
                    gp.moveTo(args[0], args[1]);
                    break;
                case PathIterator.SEG_LINETO:
                    gp.lineTo(args[0], args[1]);
                    break;
                case PathIterator.SEG_CUBICTO:
                    gp.curveTo(args[0], args[1], args[2], args[3], args[4], args[5]);
                    break;
                case PathIterator.SEG_QUADTO:
                    gp.quadTo(args[0], args[1], args[2], args[3]);
                    break;
                case PathIterator.SEG_CLOSE:
                    gp.closePath();
                    break;
                default:
                    throw new RuntimeException("JFreeChart - No path exists");
                }
                gp.setWindingRule(stream.readInt());
                hasNext = stream.readBoolean();
            }
            result = gp;
        } else {
            result = (Shape) stream.readObject();
        }
    }
    return result;

}

From source file:com.projity.pm.criticalpath.TaskSchedule.java

public static TaskSchedule deserialize(ObjectInputStream s) throws IOException, ClassNotFoundException {
    TaskSchedule t = new TaskSchedule();
    t.setPercentComplete(s.readDouble());
    t.setRawDuration(s.readLong());/*from  www .  ja v  a2  s. c  om*/
    t.setStart(s.readLong());
    t.setFinish(s.readLong());
    return t;
}

From source file:com.projity.pm.task.TaskSnapshot.java

public static TaskSnapshot deserialize(ObjectInputStream s, NormalTask hasAssignments)
        throws IOException, ClassNotFoundException {
    TaskSnapshot t = new TaskSnapshot();
    TaskSchedule schedule = TaskSchedule.deserialize(s);
    schedule.setTask(hasAssignments);/*from   w w w. j  a v  a 2  s  . c o  m*/
    t.setCurrentSchedule(schedule);
    t.hasAssignments = new HasAssignmentsImpl();//(HasAssignments)s.readObject();

    t.setFixedCost(s.readDouble());
    t.setFixedCostAccrual(s.readInt());
    t.setIgnoreResourceCalendar(s.readBoolean());

    if (hasAssignments.getVersion() >= 2) {
        t.hasAssignments.setSchedulingType(s.readInt());
        t.hasAssignments.setEffortDriven(s.readBoolean());
    }
    return t;
}

From source file:edu.pdx.its.portal.routelandia.entities.Station.java

/**
 * implement get back the latlng object after serializable*
 * @param in//from  w  w  w. j a  va 2s  .  c o  m
 * @throws IOException
 * @throws ClassNotFoundException
 */
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
    in.defaultReadObject();
    latLngList.add(new LatLng(in.readDouble(), in.readDouble()));
}

From source file:DoubleList.java

private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
    int version = in.readInt();
    int len = in.readInt();
    data = new double[len];
    for (int i = 1; i < len; i++) {
        data[i] = in.readDouble();
    }//from  ww w .  jav a  2s.  com
    size = in.readInt();
}

From source file:DoubleArrayList.java

private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
    in.defaultReadObject();/*w  w w  .j  a v  a2s  .  c  o m*/
    array = new double[in.readInt()];
    for (int i = 0; i < size; i++) {
        array[i] = in.readDouble();
    }
}