List of usage examples for java.io ObjectInputStream readFloat
public float readFloat() throws IOException
From source file:Main.java
public static void main(String[] args) throws Exception { float f = 1.23456f; FileOutputStream out = new FileOutputStream("test.txt"); ObjectOutputStream oout = new ObjectOutputStream(out); oout.writeFloat(f);/*from www . j a va 2s .co m*/ oout.writeFloat(1234.56789f); oout.flush(); oout.close(); ObjectInputStream ois = new ObjectInputStream(new FileInputStream("test.txt")); System.out.println(ois.readFloat()); System.out.println(ois.readFloat()); ois.close(); }
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. *//* w w w . ja v a 2s. c om*/ 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
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 w w. jav 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>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 a2 s .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:FloatArrayList.java
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException { in.defaultReadObject();// w w w . j a v a 2s .co m array = new float[in.readInt()]; for (int i = 0; i < size; i++) { array[i] = in.readFloat(); } }
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 ww w . ja v a 2s . 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:org.datanucleus.store.hbase.fieldmanager.FetchFieldManager.java
private float fetchFloatInternal(AbstractMemberMetaData mmd, byte[] bytes) { float value;/*from w ww . ja v a 2 s. c o m*/ if (bytes == null) { // Handle missing field String dflt = HBaseUtils.getDefaultValueForMember(mmd); if (dflt != null) { return Float.valueOf(dflt).floatValue(); } return 0; } if (mmd.isSerialized()) { try { ByteArrayInputStream bis = new ByteArrayInputStream(bytes); ObjectInputStream ois = new ObjectInputStream(bis); value = ois.readFloat(); ois.close(); bis.close(); } catch (IOException e) { throw new NucleusException(e.getMessage(), e); } } else { value = Bytes.toFloat(bytes); } return value; }
From source file:org.dishevelled.multimap.impl.AbstractHashedMap.java
/** * Reads the map data from the stream. This method must be overridden if a * subclass must be setup before <code>put()</code> is used. * * Serialization is not one of the JDK's nicest topics. Normal serialization will * initialise the superclass before the subclass. Sometimes however, this isn't * what you want, as in this case the <code>put()</code> method on read can be * affected by subclass state.// www . ja va 2s . co m * * The solution adopted here is to deserialize the state data of this class in * this protected method. This method must be called by the * <code>readObject()</code> of the first serializable subclass. * * Subclasses may override if the subclass has a specific field that must be present * before <code>put()</code> or <code>calculateThreshold()</code> will work correctly. * * @param in the input stream * @throws IOException if an I/O error occurs * @throws ClassNotFoundException if a deserialized class cannot be found */ protected void doReadObject(ObjectInputStream in) throws IOException, ClassNotFoundException { loadFactor = in.readFloat(); int capacity = in.readInt(); int size = in.readInt(); init(); data = new HashEntry[capacity]; for (int i = 0; i < size; i++) { K key = (K) in.readObject(); V value = (V) in.readObject(); put(key, value); } threshold = calculateThreshold(data.length, loadFactor); }
From source file:org.globus.examples.services.filebuy.seller.impl.FileResource.java
public void load(ResourceKey key) throws ResourceException { /* Try to retrieve the persisted resource from disk */ File file = getKeyAsFile(key.getValue()); /*//from ww w . ja v a 2 s. c o m * If the file does not exist, no resource with that key was ever * persisted */ if (!file.exists()) { throw new NoSuchResourceException(); } /* * We try to initialize the resource. This places default values in the * RPs. We still have to load the values of the RPs from disk */ try { initialize(key.getValue()); } catch (Exception e) { throw new ResourceException("Failed to initialize resource", e); } /* Now, we open the resource file and load the values */ logger.info("Attempting to load resource " + key.getValue()); /* We will use this to read from the file */ FileInputStream fis = null; /* We will store the RPs in these variables */ String name; String location; float price; try { /* Open the file */ fis = new FileInputStream(file); ObjectInputStream ois = new ObjectInputStream(fis); /* Read the RPs */ price = ois.readFloat(); name = ois.readUTF(); location = ois.readUTF(); logger.info("Successfully loaded resource with Name=" + name); /* Assign the RPs to the resource class's attributes */ setName(name); setLocation(location); setPrice(price); } catch (Exception e) { throw new ResourceException("Failed to load resource", e); } finally { /* Make sure we clean up, whether the load succeeds or not */ if (fis != null) { try { fis.close(); } catch (Exception ee) { } } } }
From source file:org.spout.api.geo.discrete.Point.java
private void readObject(java.io.ObjectInputStream in) throws IOException { float x = in.readFloat(); float y = in.readFloat(); float z = in.readFloat(); String world = in.readUTF();//from w ww .ja va2 s . co m World w = Spout.getEngine().getWorld(world); try { Field field; field = Vector3.class.getDeclaredField("x"); field.setAccessible(true); field.set(this, x); field = Vector3.class.getDeclaredField("y"); field.setAccessible(true); field.set(this, y); field = Vector3.class.getDeclaredField("z"); field.setAccessible(true); field.set(this, z); field = Point.class.getDeclaredField("world"); field.setAccessible(true); field.set(this, w); } catch (Exception e) { if (Spout.debugMode()) { e.printStackTrace(); } } }