Example usage for java.io ObjectInputStream readBoolean

List of usage examples for java.io ObjectInputStream readBoolean

Introduction

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

Prototype

public boolean readBoolean() throws IOException 

Source Link

Document

Reads in a boolean.

Usage

From source file:Main.java

public static void main(String[] args) throws Exception {
    FileOutputStream out = new FileOutputStream("test.txt");
    ObjectOutputStream oout = new ObjectOutputStream(out);

    // write something in the file
    oout.writeBoolean(true);//from  w  w  w .  j a v a2 s .  com
    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 boolean
    System.out.println(ois.readBoolean());
    ois.close();

}

From source file:Main.java

public static Stroke readStroke(ObjectInputStream in) throws IOException, ClassNotFoundException {
    boolean wroteStroke = in.readBoolean();
    if (wroteStroke) {
        boolean serializedStroke = in.readBoolean();
        if (serializedStroke) {
            return (Stroke) in.readObject();
        } else {/*from  w  ww .  ja  v a 2s  .  c o m*/
            float[] dash = null;
            int dashLength = in.read();

            if (dashLength != 0) {
                dash = new float[dashLength];
                for (int i = 0; i < dashLength; i++) {
                    dash[i] = in.readFloat();
                }
            }

            float lineWidth = in.readFloat();
            int endCap = in.readInt();
            int lineJoin = in.readInt();
            float miterLimit = in.readFloat();
            float dashPhase = in.readFloat();

            return new BasicStroke(lineWidth, endCap, lineJoin, miterLimit, dash, dashPhase);
        }
    } else {
        return null;
    }
}

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.
 *//*from  w w  w . ja va  2 s. co 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:Main.java

/**
 * Reads a <code>Stroke</code> object that has been serialised by the
 * {@link SerialUtilities#writeStroke(Stroke, ObjectOutputStream)} method.
 *
 * @param stream  the input stream (<code>null</code> not permitted).
 *
 * @return The stroke 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  ww w  . ja  v  a2  s .  c  o m*/
public static Stroke readStroke(final ObjectInputStream stream) throws IOException, ClassNotFoundException {

    if (stream == null) {
        throw new IllegalArgumentException("Null 'stream' argument.");
    }
    Stroke result = null;
    final boolean isNull = stream.readBoolean();
    if (!isNull) {
        final Class c = (Class) stream.readObject();
        if (c.equals(BasicStroke.class)) {
            final float width = stream.readFloat();
            final int cap = stream.readInt();
            final int join = stream.readInt();
            final float miterLimit = stream.readFloat();
            final float[] dash = (float[]) stream.readObject();
            final float dashPhase = stream.readFloat();
            result = new BasicStroke(width, cap, join, miterLimit, dash, dashPhase);
        } else {
            result = (Stroke) stream.readObject();
        }
    }
    return result;

}

From source file:Main.java

/**
 * Reads a <code>Paint</code> object that has been serialised by the
 * {@link SerialUtilities#writePaint(Paint, ObjectOutputStream)} method.
 *
 * @param stream  the input stream (<code>null</code> not permitted).
 *
 * @return The paint object (possibly <code>null</code>).
 *
 * @throws IOException  if there is an I/O problem.
 * @throws ClassNotFoundException  if there is a problem loading a class.
 *///  w  w w.  j  a v  a 2s  .c o  m
public static Paint readPaint(final ObjectInputStream stream) throws IOException, ClassNotFoundException {

    if (stream == null) {
        throw new IllegalArgumentException("Null 'stream' argument.");
    }
    Paint result = null;
    final boolean isNull = stream.readBoolean();
    if (!isNull) {
        final Class c = (Class) stream.readObject();
        if (isSerializable(c)) {
            result = (Paint) stream.readObject();
        } else if (c.equals(GradientPaint.class)) {
            final float x1 = stream.readFloat();
            final float y1 = stream.readFloat();
            final Color c1 = (Color) stream.readObject();
            final float x2 = stream.readFloat();
            final float y2 = stream.readFloat();
            final Color c2 = (Color) stream.readObject();
            final boolean isCyclic = stream.readBoolean();
            result = new GradientPaint(x1, y1, c1, x2, y2, c2, isCyclic);
        }
    }
    return result;

}

From source file:Main.java

/**
 * Reads a <code>AttributedString</code> object that has been serialised by
 * the {@link SerialUtilities#writeAttributedString(AttributedString,
 * ObjectOutputStream)} method./* www  .  j ava2s .c  om*/
 *
 * @param stream  the input stream (<code>null</code> not permitted).
 *
 * @return The attributed string object (possibly <code>null</code>).
 *
 * @throws IOException  if there is an I/O problem.
 * @throws ClassNotFoundException  if there is a problem loading a class.
 */
public static AttributedString readAttributedString(ObjectInputStream stream)
        throws IOException, ClassNotFoundException {

    if (stream == null) {
        throw new IllegalArgumentException("Null 'stream' argument.");
    }
    AttributedString result = null;
    final boolean isNull = stream.readBoolean();
    if (!isNull) {
        // read string and attributes then create result
        String plainStr = (String) stream.readObject();
        result = new AttributedString(plainStr);
        char c = stream.readChar();
        int start = 0;
        while (c != CharacterIterator.DONE) {
            int limit = stream.readInt();
            Map atts = (Map) stream.readObject();
            result.addAttributes(atts, start, limit);
            start = limit;
            c = stream.readChar();
        }
    }
    return result;
}

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 w  w w  .  j a  va2s  . c o m
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.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);//  w ww .  j av  a2s  . co  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:com.gsma.mobileconnect.discovery.DiscoveryResponse.java

private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
    in.defaultReadObject();/*from w  w w.  j  a v a2  s . c o  m*/
    if (in.readBoolean()) {
        this.responseData = new ObjectMapper().configure(JsonParser.Feature.AUTO_CLOSE_SOURCE, false)
                .readValue(in, JsonNode.class);
    }
}

From source file:captureplugin.drivers.defaultdriver.ParamEntry.java

/**
 * Read Data from Stream//from w w  w  .  j  a  v  a  2  s  . c  om
 * @param in read data from this stream
 * @throws IOException read errors
 * @throws ClassNotFoundException problems while creating classes
 */
public void readData(java.io.ObjectInputStream in) throws IOException, ClassNotFoundException {
    int version = in.readInt();
    mName = (String) in.readObject();
    mParam = (String) in.readObject();

    mEnabled = version < 2 || in.readBoolean();
}