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 FastObjectOutputStream extends ObjectOutputStream {
30: public static HashMap ID_TABLE = null;
31:
32: private Object m_context;
33:
34: public FastObjectOutputStream(OutputStream out) throws IOException {
35: this (out, null);
36: }
37:
38: public FastObjectOutputStream(OutputStream out, Object context)
39: throws IOException {
40: super (out);
41:
42: m_context = context;
43: }
44:
45: protected void writeClassDescriptor(ObjectStreamClass classdesc)
46: throws IOException {
47: if (ID_TABLE == null) {
48: super .writeClassDescriptor(classdesc);
49: return;
50: }
51:
52: try {
53: Short id = null;
54:
55: if (ID_TABLE != null) {
56: id = (Short) ID_TABLE.get(classdesc.forClass());
57: }
58:
59: if (id != null) {
60: writeBoolean(true);
61: writeShort(id.shortValue());
62: } else {
63: writeBoolean(false);
64: byte[] className = classdesc.forClass().getName()
65: .getBytes();
66: writeByte(className.length);
67: write(className);
68: }
69: } catch (Exception e) {
70: throw new org.myoodb.exception.InternalException(
71: "Caught during write: " + e, e);
72: }
73: }
74:
75: public void setContext(Object context) {
76: m_context = context;
77: }
78:
79: public Object getContext() {
80: return m_context;
81: }
82: }
|