List of usage examples for java.io ObjectInputStream readInt
public int readInt() throws IOException
From source file:net.sf.jasperreports.engine.base.ElementsBlock.java
@SuppressWarnings("unchecked") private void readObject(java.io.ObjectInputStream in) throws IOException, ClassNotFoundException { // we do not use the original ID as the source object might still be // alive in the JVM String oldUid = (String) in.readObject(); uid = makeUID();/*from w ww. j a v a2 s. com*/ if (log.isDebugEnabled()) { log.debug("Original uid " + oldUid + "; new uid " + uid); } context = (JRVirtualizationContext) in.readObject(); int length = in.readInt(); //FIXME put a limit on the buffer byte[] buffer = new byte[length]; in.readFully(buffer); ByteArrayInputStream inputStream = new ByteArrayInputStream(buffer, 0, buffer.length); VirtualizationObjectInputStream elementsStream = new VirtualizationObjectInputStream(inputStream, context); elements = (List<JRPrintElement>) elementsStream.readObject(); size = elements.size(); if (!elements.isEmpty()) { register(); } }
From source file:HashMap.java
/** * Adapted from {@link org.apache.commons.collections.map.AbstractHashedMap}. *//*w w w . j av a 2s .co m*/ @SuppressWarnings("unchecked") protected void doReadObject(ObjectInputStream in) throws IOException, ClassNotFoundException { int capacity = in.readInt(); initTable(capacity); int items = in.readInt(); for (int i = 0; i < items; i++) { Object key = in.readObject(); Object value = in.readObject(); put((K) key, (V) value); } }
From source file:org.protempa.proposition.AbstractProposition.java
protected void readAbstractProposition(ObjectInputStream s) throws IOException, ClassNotFoundException { String tempId = (String) s.readObject(); UniqueId tempUniqueId = (UniqueId) s.readObject(); if (tempUniqueId == null) { throw new InvalidObjectException("Can't restore. All propositions must have an unique id"); }/*from www . j a va 2 s. c o m*/ initializeAbstractProposition(tempId, tempUniqueId); int numProperties = s.readInt(); if (numProperties < 0) { throw new InvalidObjectException("Negative properties count. Can't restore"); } if (numProperties > 0) { for (int i = 0; i < numProperties; i++) { String propertyName = (String) s.readObject(); Value val = (Value) s.readObject(); if (val != null) { val = val.replace(); } setProperty(propertyName, val); } } int numRefs = s.readInt(); if (numRefs < 0) { throw new InvalidObjectException("Negative reference count. Can't restore"); } if (numRefs > 0) { for (int i = 0; i < numRefs; i++) { String refName = (String) s.readObject(); int numUids = s.readInt(); if (numUids < 0) { throw new InvalidObjectException("Negative unique identifier count. Can't restore"); } List<UniqueId> uids = new ArrayList<>(numUids); for (int j = 0; j < numUids; j++) { uids.add((UniqueId) s.readObject()); } setReferences(refName, uids); } } setSourceSystem((SourceSystem) s.readObject()); this.changes = (PropertyChangeSupport) s.readObject(); }
From source file:ArrayDeque.java
/** * Deserialize this deque./*from w ww.ja v a 2 s.c o m*/ */ private void readObject(ObjectInputStream s) throws IOException, ClassNotFoundException { s.defaultReadObject(); // Read in size and allocate array int size = s.readInt(); allocateElements(size); head = 0; tail = size; // Read in all elements in the proper order. for (int i = 0; i < size; i++) elements[i] = (E) s.readObject(); }
From source file:ArraySet.java
/** * Reconstitute the <tt>HashSet</tt> instance from a stream (that is, * deserialize it).// www. j a va 2 s . c om */ @SuppressWarnings("unchecked") private void readObject(java.io.ObjectInputStream s) throws java.io.IOException, ClassNotFoundException { // Read in any hidden serialization magic s.defaultReadObject(); int size = s.readInt(); map = new ArrayMap<E, Object>(size); for (int i = 0; i < size; i++) { E e = (E) s.readObject(); map.put(e, PRESENT); } }
From source file:IntHashMap.java
/** * Reconstitute the <tt>IntHashMap</tt> instance from a stream (i.e., * deserialize it)./*w w w . jav a2s. co m*/ */ private void readObject(java.io.ObjectInputStream s) throws IOException, ClassNotFoundException { // Read in the threshold, loadfactor, and any hidden stuff s.defaultReadObject(); // Read in number of buckets and allocate the bucket array; int numBuckets = s.readInt(); table = new Entry[numBuckets]; // Read in size (number of Mappings) int size = s.readInt(); // Read the keys and values, and put the mappings in the IntHashMap for (int i = 0; i < size; i++) { int key = s.readInt(); V value = (V) s.readObject(); put(key, value); } }
From source file:tvbrowser.extras.reminderplugin.ReminderPlugin.java
private void readData(ObjectInputStream in) throws IOException, ClassNotFoundException { int version = in.readInt(); // version mReminderList.setReminderTimerListener(null); mReminderList.read(in);/*w ww . ja v a 2s.c om*/ if (version == 3) { mClientPluginTargets = new ProgramReceiveTarget[in.readInt()]; for (int i = 0; i < mClientPluginTargets.length; i++) { mClientPluginTargets[i] = new ProgramReceiveTarget(in); } } }
From source file:tvbrowser.extras.reminderplugin.ReminderPlugin.java
private void readReminderFromTVBrowser21and20(ObjectInputStream in) throws IOException, ClassNotFoundException { int cnt = in.readInt(); for (int i = 0; i < cnt; i++) { int type = in.readInt(); if (type == 2) { // Node.PROGRAM ProgramItem item = new ProgramItem(); item.read(in);/*w w w . j av a 2 s . co m*/ String m = item.getProperty("minutes"); int minutes; try { minutes = Integer.parseInt(m); } catch (NumberFormatException e) { minutes = 10; } Program program = item.getProgram(); if (program != null) { mReminderList.add(program, new ReminderContent(minutes)); } in.readInt(); // cnt (should be 0) } } in.close(); }
From source file:tvbrowser.extras.reminderplugin.ReminderPlugin.java
/** * read the object from an input stream. * * @param in the stream to read from/* www.j av a2s. c om*/ * @throws IOException if something went wrong reading the stream * @throws ClassNotFoundException if the object could not be deserialized */ private void readReminderFromBeforeTVBrowser20(final ObjectInputStream in) throws IOException, ClassNotFoundException { int version = in.readInt(); if (version == 1) { int size = in.readInt(); for (int i = 0; i < size; i++) { in.readInt(); // read version int reminderMinutes = in.readInt(); Date programDate = Date.readData(in); String programId = (String) in.readObject(); Program program = Plugin.getPluginManager().getProgram(programDate, programId); // Only add items that were able to load their program if (program != null) { mReminderList.add(program, new ReminderContent(reminderMinutes)); } } } else if (version == 2) { mReminderList.setReminderTimerListener(null); mReminderList.read(in); } }
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. */// ww w . j a v a 2 s .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; }