01: ///////////////////////////////////////////////////////////////////////////////
02: //
03: // Copyright (C) 2003-@year@ by Thomas M. Hazel, MyOODB (www.myoodb.org)
04: //
05: // All Rights Reserved
06: //
07: // This program is free software; you can redistribute it and/or modify
08: // it under the terms of the GNU General Public License and GNU Library
09: // General Public License as published by the Free Software Foundation;
10: // either version 2, or (at your option) any later version.
11: //
12: // This program is distributed in the hope that it will be useful,
13: // but WITHOUT ANY WARRANTY; without even the implied warranty of
14: // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15: // GNU General Public License and GNU Library General Public License
16: // for more details.
17: //
18: // You should have received a copy of the GNU General Public License
19: // and GNU Library General Public License along with this program; if
20: // not, write to the Free Software Foundation, 675 Mass Ave, Cambridge,
21: // MA 02139, USA.
22: //
23: ///////////////////////////////////////////////////////////////////////////////
24: package org.myoodb.util;
25:
26: import java.io.*;
27: import java.util.*;
28:
29: public class FastObjectInputStream extends ObjectInputStream {
30: public static HashMap CLASS_TABLE = null;
31:
32: private Object m_context;
33:
34: public FastObjectInputStream(InputStream in) throws IOException {
35: this (in, null);
36: }
37:
38: public FastObjectInputStream(InputStream in, Object context)
39: throws IOException {
40: super (in);
41:
42: m_context = context;
43: }
44:
45: protected ObjectStreamClass readClassDescriptor()
46: throws IOException, ClassNotFoundException {
47: if (CLASS_TABLE == null) {
48: return super .readClassDescriptor();
49: }
50:
51: Short id = null;
52: String className = null;
53:
54: try {
55: boolean registered = readBoolean();
56:
57: if (registered == true) {
58: id = new Short(readShort());
59: Class cl = (Class) CLASS_TABLE.get(id);
60: return ObjectStreamClass.lookup(cl);
61: } else {
62: byte len = readByte();
63: byte[] byteField = new byte[len];
64: readFully(byteField);
65: return ObjectStreamClass.lookup(Class
66: .forName(new String(byteField)));
67: }
68: } catch (Exception e) {
69: throw new org.myoodb.exception.InternalException(
70: "Caught during read: " + e, e);
71: }
72: }
73:
74: public void setContext(Object context) {
75: m_context = context;
76: }
77:
78: public Object getContext() {
79: return m_context;
80: }
81: }
|