KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > geronimo > kernel > StoredObject


1 /**
2  *
3  * Copyright 2004 The Apache Software Foundation
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17 package org.apache.geronimo.kernel;
18
19 import java.io.Serializable JavaDoc;
20 import java.io.IOException JavaDoc;
21 import java.io.ByteArrayOutputStream JavaDoc;
22 import java.io.ObjectOutputStream JavaDoc;
23 import java.io.ByteArrayInputStream JavaDoc;
24 import java.io.ObjectInputStream JavaDoc;
25
26 /**
27  * @version $Rev$ $Date$
28  */

29 public class StoredObject implements Serializable JavaDoc {
30
31     private byte[] content;
32
33     public StoredObject(Serializable JavaDoc object) throws IOException JavaDoc {
34         ByteArrayOutputStream JavaDoc buffer = new ByteArrayOutputStream JavaDoc();
35         ObjectOutputStream JavaDoc out = new ObjectOutputStream JavaDoc(buffer);
36         out.writeObject(object);
37         out.flush();
38         out.close();
39         this.content = buffer.toByteArray();
40         buffer.close();
41     }
42
43     public Object JavaDoc getObject(ClassLoader JavaDoc classLoader) throws IOException JavaDoc, ClassNotFoundException JavaDoc {
44         ByteArrayInputStream JavaDoc buffer = new ByteArrayInputStream JavaDoc(this.content);
45         ObjectInputStream JavaDoc in = new ObjectInputStreamExt(buffer, classLoader);
46         Object JavaDoc obj = in.readObject();
47         buffer.close();
48         in.close();
49         return obj;
50     }
51 }
52
Popular Tags