List of usage examples for java.io ObjectOutputStream writeInt
public void writeInt(int val) throws IOException
From source file:IntHashMap.java
/** * Save the state of the <tt>IntHashMap</tt> instance to a stream (i.e., * serialize it).//from w ww . j a v a 2 s. c o m * * @serialData The <i>capacity</i> of the IntHashMap (the length of the * bucket array) is emitted (int), followed by the * <i>size</i> of the IntHashMap (the number of key-value * mappings), followed by the key (Object) and value (Object) * for each key-value mapping represented by the IntHashMap * The key-value mappings are emitted in no particular order. */ private void writeObject(java.io.ObjectOutputStream s) throws IOException { // Write out the threshold, loadfactor, and any hidden stuff s.defaultWriteObject(); // Write out number of buckets s.writeInt(table.length); // Write out size (number of Mappings) s.writeInt(count); // Write out keys and values (alternating) for (int index = table.length - 1; index >= 0; index--) { Entry entry = table[index]; while (entry != null) { s.writeInt(entry.key); s.writeObject(entry.value); entry = entry.next; } } }
From source file:tvbrowser.extras.reminderplugin.ReminderPlugin.java
/** * Save the data of this plugin in the given stream. * <p>//from w w w . java 2s . c o m * @param out The stream to write the data in. * @throws IOException */ public void writeData(ObjectOutputStream out) throws IOException { out.writeInt(3); mReminderList.writeData(out); out.writeInt(mClientPluginTargets.length); for (ProgramReceiveTarget target : mClientPluginTargets) { target.writeData(out); } }
From source file:IntHashMap.java
/** * Save the state of the <code>IntHashMap</code> instance to a stream (i.e., * serialize it)./*www.j ava 2 s. c om*/ * <p> * Context The <i>capacity</i> of the IntHashMap (the length of the bucket * array) is emitted (int), followed by the <i>size</i> of the IntHashMap * (the number of key-value mappings), followed by the key (Object) and value * (Object) for each key-value mapping represented by the IntHashMap The * key-value mappings are emitted in no particular order. * * @exception IOException */ private void writeObject(java.io.ObjectOutputStream s) throws IOException { // write out the threshold, loadfactor, and any hidden stuff s.defaultWriteObject(); // write out number of buckets s.writeInt(table.length); // write out size (number of Mappings) s.writeInt(count); // write out keys and values (alternating) for (int index = table.length - 1; index >= 0; index--) { Entry entry = table[index]; while (entry != null) { s.writeInt(entry.key); s.writeObject(entry.value); entry = entry.next; } } }
From source file:IdentityHashMap.java
/** * Save the state of the <tt>IdentityHashMap</tt> instance to a stream (i.e., * serialize it)./*from www . j a v a 2s . co m*/ * * @serialData The <i>capacity</i> of the IdentityHashMap (the length of the * bucket array) is emitted (int), followed by the * <i>size</i> of the IdentityHashMap (the number of key-value * mappings), followed by the key (Object) and value (Object) * for each key-value mapping represented by the IdentityHashMap * The key-value mappings are emitted in no particular order. */ private void writeObject(java.io.ObjectOutputStream s) throws IOException { // Write out the threshold, loadfactor, and any hidden stuff s.defaultWriteObject(); // Write out number of buckets s.writeInt(table.length); // Write out size (number of Mappings) s.writeInt(count); // Write out keys and values (alternating) for (int index = table.length - 1; index >= 0; index--) { Entry entry = table[index]; while (entry != null) { s.writeObject(entry.key); s.writeObject(entry.value); entry = entry.next; } } }
From source file:org.apache.openjpa.event.TCPRemoteCommitProvider.java
public void broadcast(RemoteCommitEvent event) { try {// ww w . j a v a2 s.c o m // build a packet notifying other JVMs of object changes. ByteArrayOutputStream baos = new ByteArrayOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(baos); oos.writeLong(PROTOCOL_VERSION); oos.writeLong(_id); oos.writeInt(_port); oos.writeObject(_localhost); oos.writeObject(event); oos.flush(); byte[] bytes = baos.toByteArray(); baos.close(); if (_broadcastThreads.isEmpty()) sendUpdatePacket(bytes); else _broadcastQueue.addPacket(bytes); } catch (IOException ioe) { if (log.isWarnEnabled()) log.warn(s_loc.get("tcp-payload-create-error"), ioe); } }
From source file:idontwant2see.IDontWant2See.java
public void writeData(final ObjectOutputStream out) throws IOException { // sort the list so that often used entries are in the front (for faster lookup) Collections.sort(mSettings.getSearchList(), new Comparator<IDontWant2SeeListEntry>() { public int compare(IDontWant2SeeListEntry o1, IDontWant2SeeListEntry o2) { return o2.getLastMatchedDate().compareTo(o1.getLastMatchedDate()); }//w ww .ja v a 2s.c o m }); out.writeInt(7); //version out.writeInt(mSettings.getSearchList().size()); for (IDontWant2SeeListEntry entry : mSettings.getSearchList()) { entry.writeData(out); } out.writeBoolean(mSettings.isSimpleMenu()); out.writeBoolean(mSettings.isSwitchToMyFilter()); out.writeUTF(mSettings.getLastEnteredExclusionString()); mSettings.getLastUsedDate().writeData((DataOutput) out); out.writeByte(mSettings.getProgramImportance()); }
From source file:org.apache.ojb.broker.util.ReferenceMap.java
/** * Writes this object to the given output stream. * * @param out the output stream to write to * @throws java.io.IOException if the stream raises it */// w w w .j a v a 2 s . co m private void writeObject(ObjectOutputStream out) throws IOException { out.defaultWriteObject(); out.writeInt(table.length); // Have to use null-terminated list because size might shrink // during iteration for (Iterator iter = entrySet().iterator(); iter.hasNext();) { Map.Entry entry = (Map.Entry) iter.next(); out.writeObject(entry.getKey()); out.writeObject(entry.getValue()); } out.writeObject(null); }
From source file:org.jactr.tools.async.message.ast.BaseASTMessage.java
private void writeObject(java.io.ObjectOutputStream out) throws IOException { out.defaultWriteObject();// www .j a v a 2 s . c o m if (_ast != null) { out.writeBoolean(true); out.writeBoolean(_compress); if (_compress) { /* * go to a GZIPOutputStream */ ByteArrayOutputStream baos = _localBAOS.get(); if (baos == null) { baos = new ByteArrayOutputStream(); _localBAOS.set(baos); } baos.reset(); DataOutputStream zip = new DataOutputStream(new GZIPOutputStream(baos)); Serializer.write(_ast, zip); zip.flush(); zip.close(); // byte[] bytes = baos.toByteArray(); if (LOGGER.isDebugEnabled()) LOGGER.debug(String.format("Writing %d compressed bytes", baos.size())); out.writeInt(baos.size()); baos.writeTo(out); // if (LOGGER.isDebugEnabled()) // LOGGER.debug("Compressed AST to "+bytes.length); // out.writeInt(bytes.length); // out.write(bytes); } else Serializer.write(_ast, out); } else out.writeBoolean(false); }
From source file:aprofplot.jfreechart.SamplingXYLineAndShapeRenderer.java
/** * Provides serialization support./*from w ww. j a v a 2 s . c o m*/ * * @param stream the output stream. * * @throws IOException if there is an I/O error. */ private void writeObject(ObjectOutputStream stream) throws IOException { stream.defaultWriteObject(); stream.writeInt(this.lineWidth); stream.writeInt(this.shapeSize); }
From source file:Main.java
/** * Serialises a <code>Shape</code> object. * * @param shape the shape object (<code>null</code> permitted). * @param stream the output stream (<code>null</code> not permitted). * * @throws IOException if there is an I/O error. *//*from w w w .j a va 2s. c o m*/ public static void writeShape(final Shape shape, final ObjectOutputStream stream) throws IOException { if (stream == null) { throw new IllegalArgumentException("Null 'stream' argument."); } if (shape != null) { stream.writeBoolean(false); if (shape instanceof Line2D) { final Line2D line = (Line2D) shape; stream.writeObject(Line2D.class); stream.writeDouble(line.getX1()); stream.writeDouble(line.getY1()); stream.writeDouble(line.getX2()); stream.writeDouble(line.getY2()); } else if (shape instanceof Rectangle2D) { final Rectangle2D rectangle = (Rectangle2D) shape; stream.writeObject(Rectangle2D.class); stream.writeDouble(rectangle.getX()); stream.writeDouble(rectangle.getY()); stream.writeDouble(rectangle.getWidth()); stream.writeDouble(rectangle.getHeight()); } else if (shape instanceof Ellipse2D) { final Ellipse2D ellipse = (Ellipse2D) shape; stream.writeObject(Ellipse2D.class); stream.writeDouble(ellipse.getX()); stream.writeDouble(ellipse.getY()); stream.writeDouble(ellipse.getWidth()); stream.writeDouble(ellipse.getHeight()); } else if (shape instanceof Arc2D) { final Arc2D arc = (Arc2D) shape; stream.writeObject(Arc2D.class); stream.writeDouble(arc.getX()); stream.writeDouble(arc.getY()); stream.writeDouble(arc.getWidth()); stream.writeDouble(arc.getHeight()); stream.writeDouble(arc.getAngleStart()); stream.writeDouble(arc.getAngleExtent()); stream.writeInt(arc.getArcType()); } else if (shape instanceof GeneralPath) { stream.writeObject(GeneralPath.class); final PathIterator pi = shape.getPathIterator(null); final float[] args = new float[6]; stream.writeBoolean(pi.isDone()); while (!pi.isDone()) { final int type = pi.currentSegment(args); stream.writeInt(type); // TODO: could write this to only stream the values // required for the segment type for (int i = 0; i < 6; i++) { stream.writeFloat(args[i]); } stream.writeInt(pi.getWindingRule()); pi.next(); stream.writeBoolean(pi.isDone()); } } else { stream.writeObject(shape.getClass()); stream.writeObject(shape); } } else { stream.writeBoolean(true); } }