Update for performance, from Jeff Varszegi

git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/lang/trunk@137200 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Stephen Colebourne 2002-12-22 19:55:30 +00:00
parent d91d14530a
commit 706ed81a15
1 changed files with 20 additions and 9 deletions

View File

@ -1,5 +1,3 @@
package org.apache.commons.lang;
/* ==================================================================== /* ====================================================================
* The Apache Software License, Version 1.1 * The Apache Software License, Version 1.1
* *
@ -53,6 +51,7 @@ package org.apache.commons.lang;
* information on the Apache Software Foundation, please see * information on the Apache Software Foundation, please see
* <http://www.apache.org/>. * <http://www.apache.org/>.
*/ */
package org.apache.commons.lang;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
@ -64,8 +63,8 @@ import java.io.OutputStream;
import java.io.Serializable; import java.io.Serializable;
/** /**
* <p>Methods that assist with the serialization process, or perform * <p><code>SerializationUtils</code> provides methods that assist with the
* additional functionality based on serialization.</p> * serialization process, or perform additional functionality based on serialization.</p>
* <ul> * <ul>
* <li>Deep clone using serialization * <li>Deep clone using serialization
* <li>Serialize managing finally and IOException * <li>Serialize managing finally and IOException
@ -75,15 +74,21 @@ import java.io.Serializable;
* @author <a href="mailto:nissim@nksystems.com">Nissim Karpenstein</a> * @author <a href="mailto:nissim@nksystems.com">Nissim Karpenstein</a>
* @author <a href="mailto:janekdb@yahoo.co.uk">Janek Bogucki</a> * @author <a href="mailto:janekdb@yahoo.co.uk">Janek Bogucki</a>
* @author <a href="mailto:dlr@finemaltcoding.com">Daniel Rall</a> * @author <a href="mailto:dlr@finemaltcoding.com">Daniel Rall</a>
* @author <a href="mailto:scolebourne@joda.org">Stephen Colebourne</a> * @author Stephen Colebourne
* @version $Id: SerializationUtils.java,v 1.3 2002/11/16 10:41:03 scolebourne Exp $ * @author Jeff Varszegi
* @since 1.0
* @version $Id: SerializationUtils.java,v 1.4 2002/12/22 19:55:30 scolebourne Exp $
*/ */
public class SerializationUtils { public class SerializationUtils {
/** /**
* <p>Constructor for SerializationUtils is private.</p> * <p>SerializationUtils instances should NOT be constructed in standard programming.
* Instead, the class should be used as <code>SerializationUtils.clone(object)</code>.</p>
*
* <p>This constructor is public to permit tools that require a JavaBean instance
* to operate.</p>
*/ */
private SerializationUtils() { public SerializationUtils() {
super(); super();
} }
@ -111,6 +116,9 @@ public class SerializationUtils {
* This avoids the need for a finally clause, and maybe also exception * This avoids the need for a finally clause, and maybe also exception
* handling, in the application code.</p> * handling, in the application code.</p>
* *
* <p>The stream passed in is not buffered internally within this method.
* This is the responsibility of your application if desired.</p>
*
* @param obj the object to serialize to bytes * @param obj the object to serialize to bytes
* @param outputStream the stream to write to * @param outputStream the stream to write to
* @throws SerializationException (runtime) if the serialization fails * @throws SerializationException (runtime) if the serialization fails
@ -144,7 +152,7 @@ public class SerializationUtils {
* @throws SerializationException (runtime) if the serialization fails * @throws SerializationException (runtime) if the serialization fails
*/ */
public static byte[] serialize(Serializable obj) { public static byte[] serialize(Serializable obj) {
ByteArrayOutputStream baos = new ByteArrayOutputStream(); ByteArrayOutputStream baos = new ByteArrayOutputStream(512);
serialize(obj, baos); serialize(obj, baos);
return baos.toByteArray(); return baos.toByteArray();
} }
@ -156,6 +164,9 @@ public class SerializationUtils {
* avoids the need for a finally clause, and maybe also exception * avoids the need for a finally clause, and maybe also exception
* handling, in the application code.</p> * handling, in the application code.</p>
* *
* <p>The stream passed in is not buffered internally within this method.
* This is the responsibility of your application if desired.</p>
*
* @param inputStream the serialized object input stream * @param inputStream the serialized object input stream
* @return the deserialized object * @return the deserialized object
* @throws SerializationException (runtime) if the serialization fails * @throws SerializationException (runtime) if the serialization fails