01: /*
02:
03: Derby - Class org.apache.derby.iapi.services.io.DebugByteTeeOutputStream
04:
05: Licensed to the Apache Software Foundation (ASF) under one or more
06: contributor license agreements. See the NOTICE file distributed with
07: this work for additional information regarding copyright ownership.
08: The ASF licenses this file to you under the Apache License, Version 2.0
09: (the "License"); you may not use this file except in compliance with
10: the License. You may obtain a copy of the License at
11:
12: http://www.apache.org/licenses/LICENSE-2.0
13:
14: Unless required by applicable law or agreed to in writing, software
15: distributed under the License is distributed on an "AS IS" BASIS,
16: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17: See the License for the specific language governing permissions and
18: limitations under the License.
19:
20: */
21: package org.apache.derby.iapi.services.io;
22:
23: import java.io.*;
24: import org.apache.derby.iapi.services.io.AccessibleByteArrayOutputStream;
25:
26: class DebugByteTeeOutputStream extends FilterOutputStream {
27: private AccessibleByteArrayOutputStream tee = new AccessibleByteArrayOutputStream(
28: 256);
29:
30: DebugByteTeeOutputStream(OutputStream out) {
31: super (out);
32: }
33:
34: public void write(int b) throws IOException {
35: out.write(b);
36: tee.write(b);
37: }
38:
39: public void write(byte[] b, int off, int len) throws IOException {
40:
41: out.write(b, off, len);
42: tee.write(b, off, len);
43: }
44:
45: void checkObject(Formatable f) {
46:
47: ByteArrayInputStream in = new ByteArrayInputStream(tee
48: .getInternalByteArray(), 0, tee.size());
49:
50: FormatIdInputStream fin = new FormatIdInputStream(in);
51:
52: // now get an empty object given the format identification
53: // read it in
54: // then compare it???
55:
56: Formatable f1 = null;
57: try {
58:
59: f1 = (Formatable) fin.readObject();
60:
61: if (f1.equals(f)) {
62: return;
63: }
64:
65: // If the two objects are not equal and it looks
66: // like they don't implement their own equals()
67: // (which requires a matching hashCode() then
68: // just return. The object was read sucessfully.
69:
70: if ((f1.hashCode() == System.identityHashCode(f1))
71: && (f.hashCode() == System.identityHashCode(f)))
72: return;
73: } catch (Throwable t) {
74: System.out.println("FormatableError:read error : "
75: + t.toString());
76: System.out.println("FormatableError:class written : "
77: + f.getClass());
78: if (null == f1)
79: System.out.println("FormatableError:read back as null");
80: else
81: System.out.println("FormatableError:class read : "
82: + f1.getClass());
83: System.out.println("FormatableError:write id : "
84: + FormatIdUtil
85: .formatIdToString(f.getTypeFormatId()));
86: if (null != f1)
87: System.out.println("FormatableError:read id : "
88: + FormatIdUtil.formatIdToString(f1
89: .getTypeFormatId()));
90: t.printStackTrace(System.out);
91: }
92:
93: //System.out.println("FormatableError:Class written " + f.getClass() + " format id " + f.getTypeFormatId());
94: //if (f1 != null)
95: //System.out.println("FormatableError:Class read " + f1.getClass() + " format id " + f1.getTypeFormatId());
96: }
97:
98: }
|