1 <!DOCTYPE HTML PUBLIC
"-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
5 <!-- Generated by javadoc (build 1.4.2_16) on Sat Mar 15 20:43:47 PDT 2008 -->
6 <META http-equiv=
"Content-Type" content=
"text/html; charset=ISO-8859-1">
8 SerializationUtils (Commons Lang
2.4 API)
11 <META NAME=
"keywords" CONTENT=
"org.apache.commons.lang.SerializationUtils class">
13 <LINK REL =
"stylesheet" TYPE=
"text/css" HREF=
"../../../../stylesheet.css" TITLE=
"Style">
15 <SCRIPT type=
"text/javascript">
16 function windowTitle()
18 parent.document.
title=
"SerializationUtils (Commons Lang 2.4 API)";
24 <BODY BGCOLOR=
"white" onload=
"windowTitle();">
27 <!-- ========= START OF TOP NAVBAR ======= -->
28 <A NAME=
"navbar_top"><!-- --></A>
29 <A HREF=
"#skip-navbar_top" title=
"Skip navigation links"></A>
30 <TABLE BORDER=
"0" WIDTH=
"100%" CELLPADDING=
"1" CELLSPACING=
"0" SUMMARY=
"">
32 <TD COLSPAN=
3 BGCOLOR=
"#EEEEFF" CLASS=
"NavBarCell1">
33 <A NAME=
"navbar_top_firstrow"><!-- --></A>
34 <TABLE BORDER=
"0" CELLPADDING=
"0" CELLSPACING=
"3" SUMMARY=
"">
35 <TR ALIGN=
"center" VALIGN=
"top">
36 <TD BGCOLOR=
"#EEEEFF" CLASS=
"NavBarCell1"> <A HREF=
"../../../../overview-summary.html"><FONT CLASS=
"NavBarFont1"><B>Overview
</B></FONT></A> </TD>
37 <TD BGCOLOR=
"#EEEEFF" CLASS=
"NavBarCell1"> <A HREF=
"package-summary.html"><FONT CLASS=
"NavBarFont1"><B>Package
</B></FONT></A> </TD>
38 <TD BGCOLOR=
"#FFFFFF" CLASS=
"NavBarCell1Rev"> <FONT CLASS=
"NavBarFont1Rev"><B>Class
</B></FONT> </TD>
39 <TD BGCOLOR=
"#EEEEFF" CLASS=
"NavBarCell1"> <A HREF=
"class-use/SerializationUtils.html"><FONT CLASS=
"NavBarFont1"><B>Use
</B></FONT></A> </TD>
40 <TD BGCOLOR=
"#EEEEFF" CLASS=
"NavBarCell1"> <A HREF=
"package-tree.html"><FONT CLASS=
"NavBarFont1"><B>Tree
</B></FONT></A> </TD>
41 <TD BGCOLOR=
"#EEEEFF" CLASS=
"NavBarCell1"> <A HREF=
"../../../../deprecated-list.html"><FONT CLASS=
"NavBarFont1"><B>Deprecated
</B></FONT></A> </TD>
42 <TD BGCOLOR=
"#EEEEFF" CLASS=
"NavBarCell1"> <A HREF=
"../../../../index-all.html"><FONT CLASS=
"NavBarFont1"><B>Index
</B></FONT></A> </TD>
43 <TD BGCOLOR=
"#EEEEFF" CLASS=
"NavBarCell1"> <A HREF=
"../../../../help-doc.html"><FONT CLASS=
"NavBarFont1"><B>Help
</B></FONT></A> </TD>
47 <TD ALIGN=
"right" VALIGN=
"top" ROWSPAN=
3><EM>
53 <TD BGCOLOR=
"white" CLASS=
"NavBarCell2"><FONT SIZE=
"-2">
54 <A HREF=
"../../../../org/apache/commons/lang/RandomStringUtils.html" title=
"class in org.apache.commons.lang"><B>PREV CLASS
</B></A>
55 <A HREF=
"../../../../org/apache/commons/lang/StringEscapeUtils.html" title=
"class in org.apache.commons.lang"><B>NEXT CLASS
</B></A></FONT></TD>
56 <TD BGCOLOR=
"white" CLASS=
"NavBarCell2"><FONT SIZE=
"-2">
57 <A HREF=
"../../../../index.html" target=
"_top"><B>FRAMES
</B></A>
58 <A HREF=
"SerializationUtils.html" target=
"_top"><B>NO FRAMES
</B></A>
59 <SCRIPT type=
"text/javascript">
62 document.writeln('<A HREF="../../../../allclasses-noframe.html"><B>All Classes</B></A>');
67 <A HREF=
"../../../../allclasses-noframe.html"><B>All Classes
</B></A>
73 <TD VALIGN=
"top" CLASS=
"NavBarCell3"><FONT SIZE=
"-2">
74 SUMMARY:
NESTED
|
FIELD
|
<A HREF=
"#constructor_summary">CONSTR
</A> |
<A HREF=
"#method_summary">METHOD
</A></FONT></TD>
75 <TD VALIGN=
"top" CLASS=
"NavBarCell3"><FONT SIZE=
"-2">
76 DETAIL:
FIELD
|
<A HREF=
"#constructor_detail">CONSTR
</A> |
<A HREF=
"#method_detail">METHOD
</A></FONT></TD>
79 <A NAME=
"skip-navbar_top"></A>
80 <!-- ========= END OF TOP NAVBAR ========= -->
83 <!-- ======== START OF CLASS DATA ======== -->
86 org.apache.commons.lang
</FONT>
88 Class SerializationUtils
</H2>
91 <IMG SRC=
"../../../../resources/inherit.gif" ALT=
"extended by"><B>org.apache.commons.lang.SerializationUtils
</B>
95 <DT>public class
<B>SerializationUtils
</B><DT>extends java.lang.Object
</DL>
98 <p>Assists with the serialization process and performs additional functionality based
102 <li>Deep clone using serialization
103 <li>Serialize managing finally and IOException
104 <li>Deserialize managing finally and IOException
107 <p>This class throws exceptions for invalid
<code>null
</code> inputs.
108 Each method documents its behaviour in more detail.
</p>
113 <DT><B>Since:
</B></DT>
115 <DT><B>Version:
</B></DT>
116 <DD>$Id: SerializationUtils.java
512889 2007-
02-
28 18:
18:
20Z dlr $
</DD>
117 <DT><B>Author:
</B></DT>
118 <DD><a href=
"mailto:nissim@nksystems.com">Nissim Karpenstein
</a>,
<a href=
"mailto:janekdb@yahoo.co.uk">Janek Bogucki
</a>, Daniel L. Rall, Stephen Colebourne, Jeff Varszegi, Gary Gregory
</DD>
123 <!-- ======== NESTED CLASS SUMMARY ======== -->
126 <!-- =========== FIELD SUMMARY =========== -->
129 <!-- ======== CONSTRUCTOR SUMMARY ======== -->
131 <A NAME=
"constructor_summary"><!-- --></A>
132 <TABLE BORDER=
"1" WIDTH=
"100%" CELLPADDING=
"3" CELLSPACING=
"0" SUMMARY=
"">
133 <TR BGCOLOR=
"#CCCCFF" CLASS=
"TableHeadingColor">
134 <TD COLSPAN=
2><FONT SIZE=
"+2">
135 <B>Constructor Summary
</B></FONT></TD>
137 <TR BGCOLOR=
"white" CLASS=
"TableRowColor">
138 <TD><CODE><B><A HREF=
"../../../../org/apache/commons/lang/SerializationUtils.html#SerializationUtils()">SerializationUtils
</A></B>()
</CODE>
141 SerializationUtils instances should NOT be constructed in standard programming.
</TD>
145 <!-- ========== METHOD SUMMARY =========== -->
147 <A NAME=
"method_summary"><!-- --></A>
148 <TABLE BORDER=
"1" WIDTH=
"100%" CELLPADDING=
"3" CELLSPACING=
"0" SUMMARY=
"">
149 <TR BGCOLOR=
"#CCCCFF" CLASS=
"TableHeadingColor">
150 <TD COLSPAN=
2><FONT SIZE=
"+2">
151 <B>Method Summary
</B></FONT></TD>
153 <TR BGCOLOR=
"white" CLASS=
"TableRowColor">
154 <TD ALIGN=
"right" VALIGN=
"top" WIDTH=
"1%"><FONT SIZE=
"-1">
155 <CODE>static
java.lang.Object
</CODE></FONT></TD>
156 <TD><CODE><B><A HREF=
"../../../../org/apache/commons/lang/SerializationUtils.html#clone(java.io.Serializable)">clone
</A></B>(java.io.Serializable
object)
</CODE>
159 Deep clone an
<code>Object
</code> using serialization.
</TD>
161 <TR BGCOLOR=
"white" CLASS=
"TableRowColor">
162 <TD ALIGN=
"right" VALIGN=
"top" WIDTH=
"1%"><FONT SIZE=
"-1">
163 <CODE>static
java.lang.Object
</CODE></FONT></TD>
164 <TD><CODE><B><A HREF=
"../../../../org/apache/commons/lang/SerializationUtils.html#deserialize(byte[])">deserialize
</A></B>(byte[]
objectData)
</CODE>
167 Deserializes a single
<code>Object
</code> from an array of bytes.
</TD>
169 <TR BGCOLOR=
"white" CLASS=
"TableRowColor">
170 <TD ALIGN=
"right" VALIGN=
"top" WIDTH=
"1%"><FONT SIZE=
"-1">
171 <CODE>static
java.lang.Object
</CODE></FONT></TD>
172 <TD><CODE><B><A HREF=
"../../../../org/apache/commons/lang/SerializationUtils.html#deserialize(java.io.InputStream)">deserialize
</A></B>(java.io.InputStream
inputStream)
</CODE>
175 Deserializes an
<code>Object
</code> from the specified stream.
</TD>
177 <TR BGCOLOR=
"white" CLASS=
"TableRowColor">
178 <TD ALIGN=
"right" VALIGN=
"top" WIDTH=
"1%"><FONT SIZE=
"-1">
179 <CODE>static
byte[]
</CODE></FONT></TD>
180 <TD><CODE><B><A HREF=
"../../../../org/apache/commons/lang/SerializationUtils.html#serialize(java.io.Serializable)">serialize
</A></B>(java.io.Serializable
obj)
</CODE>
183 Serializes an
<code>Object
</code> to a byte array for
184 storage/serialization.
</TD>
186 <TR BGCOLOR=
"white" CLASS=
"TableRowColor">
187 <TD ALIGN=
"right" VALIGN=
"top" WIDTH=
"1%"><FONT SIZE=
"-1">
188 <CODE>static
void
</CODE></FONT></TD>
189 <TD><CODE><B><A HREF=
"../../../../org/apache/commons/lang/SerializationUtils.html#serialize(java.io.Serializable, java.io.OutputStream)">serialize
</A></B>(java.io.Serializable
obj,
190 java.io.OutputStream
outputStream)
</CODE>
193 Serializes an
<code>Object
</code> to the specified stream.
</TD>
196 <A NAME=
"methods_inherited_from_class_java.lang.Object"><!-- --></A>
197 <TABLE BORDER=
"1" WIDTH=
"100%" CELLPADDING=
"3" CELLSPACING=
"0" SUMMARY=
"">
198 <TR BGCOLOR=
"#EEEEFF" CLASS=
"TableSubHeadingColor">
199 <TD><B>Methods inherited from class java.lang.Object
</B></TD>
201 <TR BGCOLOR=
"white" CLASS=
"TableRowColor">
202 <TD><CODE>clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
</CODE></TD>
208 <!-- ============ FIELD DETAIL =========== -->
211 <!-- ========= CONSTRUCTOR DETAIL ======== -->
213 <A NAME=
"constructor_detail"><!-- --></A>
214 <TABLE BORDER=
"1" WIDTH=
"100%" CELLPADDING=
"3" CELLSPACING=
"0" SUMMARY=
"">
215 <TR BGCOLOR=
"#CCCCFF" CLASS=
"TableHeadingColor">
216 <TD COLSPAN=
1><FONT SIZE=
"+2">
217 <B>Constructor Detail
</B></FONT></TD>
221 <A NAME=
"SerializationUtils()"><!-- --></A><H3>
222 SerializationUtils
</H3>
224 public
<B>SerializationUtils
</B>()
</PRE>
226 <DD><p>SerializationUtils instances should NOT be constructed in standard programming.
227 Instead, the class should be used as
<code>SerializationUtils.clone(object)
</code>.
</p>
229 <p>This constructor is public to permit tools that require a JavaBean instance
232 <DT><B>Since:
</B></DT>
236 <!-- ============ METHOD DETAIL ========== -->
238 <A NAME=
"method_detail"><!-- --></A>
239 <TABLE BORDER=
"1" WIDTH=
"100%" CELLPADDING=
"3" CELLSPACING=
"0" SUMMARY=
"">
240 <TR BGCOLOR=
"#CCCCFF" CLASS=
"TableHeadingColor">
241 <TD COLSPAN=
1><FONT SIZE=
"+2">
242 <B>Method Detail
</B></FONT></TD>
246 <A NAME=
"clone(java.io.Serializable)"><!-- --></A><H3>
249 public static java.lang.Object
<B>clone
</B>(java.io.Serializable
object)
</PRE>
251 <DD><p>Deep clone an
<code>Object
</code> using serialization.
</p>
253 <p>This is many times slower than writing clone methods by hand
254 on all objects in your object graph. However, for complex object
255 graphs, or for those that don't support deep cloning this can
256 be a simple alternative implementation. Of course all the objects
257 must be
<code>Serializable
</code>.
</p>
260 <DT><B>Parameters:
</B><DD><CODE>object
</CODE> - the
<code>Serializable
</code> object to clone
261 <DT><B>Returns:
</B><DD>the cloned object
263 <DD><CODE><A HREF=
"../../../../org/apache/commons/lang/SerializationException.html" title=
"class in org.apache.commons.lang">SerializationException
</A></CODE> - (runtime) if the serialization fails
</DL>
268 <A NAME=
"serialize(java.io.Serializable, java.io.OutputStream)"><!-- --></A><H3>
271 public static void
<B>serialize
</B>(java.io.Serializable
obj,
272 java.io.OutputStream
outputStream)
</PRE>
274 <DD><p>Serializes an
<code>Object
</code> to the specified stream.
</p>
276 <p>The stream will be closed once the object is written.
277 This avoids the need for a finally clause, and maybe also exception
278 handling, in the application code.
</p>
280 <p>The stream passed in is not buffered internally within this method.
281 This is the responsibility of your application if desired.
</p>
284 <DT><B>Parameters:
</B><DD><CODE>obj
</CODE> - the object to serialize to bytes, may be null
<DD><CODE>outputStream
</CODE> - the stream to write to, must not be null
286 <DD><CODE>java.lang.IllegalArgumentException
</CODE> - if
<code>outputStream
</code> is
<code>null
</code>
287 <DD><CODE><A HREF=
"../../../../org/apache/commons/lang/SerializationException.html" title=
"class in org.apache.commons.lang">SerializationException
</A></CODE> - (runtime) if the serialization fails
</DL>
292 <A NAME=
"serialize(java.io.Serializable)"><!-- --></A><H3>
295 public static byte[]
<B>serialize
</B>(java.io.Serializable
obj)
</PRE>
297 <DD><p>Serializes an
<code>Object
</code> to a byte array for
298 storage/serialization.
</p>
301 <DT><B>Parameters:
</B><DD><CODE>obj
</CODE> - the object to serialize to bytes
302 <DT><B>Returns:
</B><DD>a byte[] with the converted Serializable
304 <DD><CODE><A HREF=
"../../../../org/apache/commons/lang/SerializationException.html" title=
"class in org.apache.commons.lang">SerializationException
</A></CODE> - (runtime) if the serialization fails
</DL>
309 <A NAME=
"deserialize(java.io.InputStream)"><!-- --></A><H3>
312 public static java.lang.Object
<B>deserialize
</B>(java.io.InputStream
inputStream)
</PRE>
314 <DD><p>Deserializes an
<code>Object
</code> from the specified stream.
</p>
316 <p>The stream will be closed once the object is written. This
317 avoids the need for a finally clause, and maybe also exception
318 handling, in the application code.
</p>
320 <p>The stream passed in is not buffered internally within this method.
321 This is the responsibility of your application if desired.
</p>
324 <DT><B>Parameters:
</B><DD><CODE>inputStream
</CODE> - the serialized object input stream, must not be null
325 <DT><B>Returns:
</B><DD>the deserialized object
327 <DD><CODE>java.lang.IllegalArgumentException
</CODE> - if
<code>inputStream
</code> is
<code>null
</code>
328 <DD><CODE><A HREF=
"../../../../org/apache/commons/lang/SerializationException.html" title=
"class in org.apache.commons.lang">SerializationException
</A></CODE> - (runtime) if the serialization fails
</DL>
333 <A NAME=
"deserialize(byte[])"><!-- --></A><H3>
336 public static java.lang.Object
<B>deserialize
</B>(byte[]
objectData)
</PRE>
338 <DD><p>Deserializes a single
<code>Object
</code> from an array of bytes.
</p>
341 <DT><B>Parameters:
</B><DD><CODE>objectData
</CODE> - the serialized object, must not be null
342 <DT><B>Returns:
</B><DD>the deserialized object
344 <DD><CODE>java.lang.IllegalArgumentException
</CODE> - if
<code>objectData
</code> is
<code>null
</code>
345 <DD><CODE><A HREF=
"../../../../org/apache/commons/lang/SerializationException.html" title=
"class in org.apache.commons.lang">SerializationException
</A></CODE> - (runtime) if the serialization fails
</DL>
348 <!-- ========= END OF CLASS DATA ========= -->
352 <!-- ======= START OF BOTTOM NAVBAR ====== -->
353 <A NAME=
"navbar_bottom"><!-- --></A>
354 <A HREF=
"#skip-navbar_bottom" title=
"Skip navigation links"></A>
355 <TABLE BORDER=
"0" WIDTH=
"100%" CELLPADDING=
"1" CELLSPACING=
"0" SUMMARY=
"">
357 <TD COLSPAN=
3 BGCOLOR=
"#EEEEFF" CLASS=
"NavBarCell1">
358 <A NAME=
"navbar_bottom_firstrow"><!-- --></A>
359 <TABLE BORDER=
"0" CELLPADDING=
"0" CELLSPACING=
"3" SUMMARY=
"">
360 <TR ALIGN=
"center" VALIGN=
"top">
361 <TD BGCOLOR=
"#EEEEFF" CLASS=
"NavBarCell1"> <A HREF=
"../../../../overview-summary.html"><FONT CLASS=
"NavBarFont1"><B>Overview
</B></FONT></A> </TD>
362 <TD BGCOLOR=
"#EEEEFF" CLASS=
"NavBarCell1"> <A HREF=
"package-summary.html"><FONT CLASS=
"NavBarFont1"><B>Package
</B></FONT></A> </TD>
363 <TD BGCOLOR=
"#FFFFFF" CLASS=
"NavBarCell1Rev"> <FONT CLASS=
"NavBarFont1Rev"><B>Class
</B></FONT> </TD>
364 <TD BGCOLOR=
"#EEEEFF" CLASS=
"NavBarCell1"> <A HREF=
"class-use/SerializationUtils.html"><FONT CLASS=
"NavBarFont1"><B>Use
</B></FONT></A> </TD>
365 <TD BGCOLOR=
"#EEEEFF" CLASS=
"NavBarCell1"> <A HREF=
"package-tree.html"><FONT CLASS=
"NavBarFont1"><B>Tree
</B></FONT></A> </TD>
366 <TD BGCOLOR=
"#EEEEFF" CLASS=
"NavBarCell1"> <A HREF=
"../../../../deprecated-list.html"><FONT CLASS=
"NavBarFont1"><B>Deprecated
</B></FONT></A> </TD>
367 <TD BGCOLOR=
"#EEEEFF" CLASS=
"NavBarCell1"> <A HREF=
"../../../../index-all.html"><FONT CLASS=
"NavBarFont1"><B>Index
</B></FONT></A> </TD>
368 <TD BGCOLOR=
"#EEEEFF" CLASS=
"NavBarCell1"> <A HREF=
"../../../../help-doc.html"><FONT CLASS=
"NavBarFont1"><B>Help
</B></FONT></A> </TD>
372 <TD ALIGN=
"right" VALIGN=
"top" ROWSPAN=
3><EM>
378 <TD BGCOLOR=
"white" CLASS=
"NavBarCell2"><FONT SIZE=
"-2">
379 <A HREF=
"../../../../org/apache/commons/lang/RandomStringUtils.html" title=
"class in org.apache.commons.lang"><B>PREV CLASS
</B></A>
380 <A HREF=
"../../../../org/apache/commons/lang/StringEscapeUtils.html" title=
"class in org.apache.commons.lang"><B>NEXT CLASS
</B></A></FONT></TD>
381 <TD BGCOLOR=
"white" CLASS=
"NavBarCell2"><FONT SIZE=
"-2">
382 <A HREF=
"../../../../index.html" target=
"_top"><B>FRAMES
</B></A>
383 <A HREF=
"SerializationUtils.html" target=
"_top"><B>NO FRAMES
</B></A>
384 <SCRIPT type=
"text/javascript">
387 document.writeln('<A HREF="../../../../allclasses-noframe.html"><B>All Classes</B></A>');
392 <A HREF=
"../../../../allclasses-noframe.html"><B>All Classes
</B></A>
398 <TD VALIGN=
"top" CLASS=
"NavBarCell3"><FONT SIZE=
"-2">
399 SUMMARY:
NESTED
|
FIELD
|
<A HREF=
"#constructor_summary">CONSTR
</A> |
<A HREF=
"#method_summary">METHOD
</A></FONT></TD>
400 <TD VALIGN=
"top" CLASS=
"NavBarCell3"><FONT SIZE=
"-2">
401 DETAIL:
FIELD
|
<A HREF=
"#constructor_detail">CONSTR
</A> |
<A HREF=
"#method_detail">METHOD
</A></FONT></TD>
404 <A NAME=
"skip-navbar_bottom"></A>
405 <!-- ======== END OF BOTTOM NAVBAR ======= -->
408 Copyright ©
2001-
2008 <a href=
"http://www.apache.org/">The Apache Software Foundation
</a>. All Rights Reserved.