Return-Path: Delivered-To: apmail-jakarta-commons-dev-archive@www.apache.org Received: (qmail 67119 invoked from network); 1 Jun 2004 22:57:30 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur-2.apache.org with SMTP; 1 Jun 2004 22:57:30 -0000 Received: (qmail 58267 invoked by uid 500); 1 Jun 2004 22:57:41 -0000 Delivered-To: apmail-jakarta-commons-dev-archive@jakarta.apache.org Received: (qmail 58116 invoked by uid 500); 1 Jun 2004 22:57:40 -0000 Mailing-List: contact commons-dev-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "Jakarta Commons Developers List" Reply-To: "Jakarta Commons Developers List" Delivered-To: mailing list commons-dev@jakarta.apache.org Received: (qmail 58085 invoked by uid 500); 1 Jun 2004 22:57:40 -0000 Received: (qmail 58069 invoked by uid 99); 1 Jun 2004 22:57:40 -0000 Received: from [209.237.227.194] (HELO minotaur.apache.org) (209.237.227.194) by apache.org (qpsmtpd/0.27.1) with SMTP; Tue, 01 Jun 2004 15:57:40 -0700 Received: (qmail 67023 invoked by uid 1529); 1 Jun 2004 22:57:18 -0000 Date: 1 Jun 2004 22:57:18 -0000 Message-ID: <20040601225718.67021.qmail@minotaur.apache.org> From: scolebourne@apache.org To: jakarta-commons-cvs@apache.org Subject: cvs commit: jakarta-commons/collections/src/java/org/apache/commons/collections/buffer UnboundedFifoBuffer.java X-Virus-Checked: Checked X-Spam-Rating: minotaur-2.apache.org 1.6.2 0/1000/N 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 @@ * *

* This buffer prevents null objects from being added. + *

+ * 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