You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by sc...@apache.org on 2004/06/02 00:57:18 UTC
cvs commit: jakarta-commons/collections/src/java/org/apache/commons/collections/buffer UnboundedFifoBuffer.java
scolebourne 2004/06/01 15:57:18
Modified: collections/src/java/org/apache/commons/collections/buffer
UnboundedFifoBuffer.java
Log:
Make serializable
Revision Changes Path
1.9 +49 -6 jakarta-commons/collections/src/java/org/apache/commons/collections/buffer/UnboundedFifoBuffer.java
Index: UnboundedFifoBuffer.java
===================================================================
RCS file: /home/cvs/jakarta-commons/collections/src/java/org/apache/commons/collections/buffer/UnboundedFifoBuffer.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- UnboundedFifoBuffer.java 15 May 2004 12:33:23 -0000 1.8
+++ UnboundedFifoBuffer.java 1 Jun 2004 22:57:18 -0000 1.9
@@ -15,6 +15,10 @@
*/
package org.apache.commons.collections.buffer;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.io.Serializable;
import java.util.AbstractCollection;
import java.util.Iterator;
import java.util.NoSuchElementException;
@@ -42,6 +46,8 @@
* </pre>
* <p>
* This buffer prevents null objects from being added.
+ * <p>
+ * This class is Serializable from Commons Collections 3.1.
*
* @since Commons Collections 3.0 (previously in main package v2.1)
* @version $Revision$ $Date$
@@ -52,14 +58,17 @@
* @author Paul Jack
* @author Stephen Colebourne
*/
-public class UnboundedFifoBuffer extends AbstractCollection implements Buffer {
-
+public class UnboundedFifoBuffer extends AbstractCollection implements Buffer, Serializable {
+
+ /** Serialization vesrion */
+ private static final long serialVersionUID = -3482960336579541419L;
+
/** The array of objects in the buffer. */
- protected Object[] buffer;
+ protected transient Object[] buffer;
/** The current head index. */
- protected int head;
+ protected transient int head;
/** The current tail index. */
- protected int tail;
+ protected transient int tail;
/**
* Constructs an UnboundedFifoBuffer with the default number of elements.
@@ -89,6 +98,40 @@
tail = 0;
}
+ //-----------------------------------------------------------------------
+ /**
+ * Write the buffer out using a custom routine.
+ *
+ * @param out the output stream
+ * @throws IOException
+ */
+ private void writeObject(ObjectOutputStream out) throws IOException {
+ out.defaultWriteObject();
+ out.writeInt(size());
+ for (Iterator it = iterator(); it.hasNext();) {
+ out.writeObject(it.next());
+ }
+ }
+
+ /**
+ * Read the buffer in using a custom routine.
+ *
+ * @param in the input stream
+ * @throws IOException
+ * @throws ClassNotFoundException
+ */
+ private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
+ in.defaultReadObject();
+ int size = in.readInt();
+ buffer = new Object[size];
+ for (int i = 0; i < size; i++) {
+ buffer[i] = in.readObject();
+ }
+ head = 0;
+ tail = size;
+ }
+
+ //-----------------------------------------------------------------------
/**
* Returns the number of elements stored in the buffer.
*
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org