1 21 package org.apache.derby.iapi.services.io; 22 23 import java.io.*; 24 import org.apache.derby.iapi.services.io.AccessibleByteArrayOutputStream; 25 26 27 class DebugByteTeeOutputStream extends FilterOutputStream { 28 private AccessibleByteArrayOutputStream tee = new AccessibleByteArrayOutputStream(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 46 void checkObject(Formatable f) { 47 48 ByteArrayInputStream in = new ByteArrayInputStream(tee.getInternalByteArray(), 0, tee.size()); 49 50 FormatIdInputStream fin = new FormatIdInputStream(in); 51 52 56 Formatable f1 = null; 57 try { 58 59 f1 = (Formatable) fin.readObject(); 60 61 if (f1.equals(f)) { 62 return; 63 } 64 65 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 : " + t.toString()); 75 System.out.println("FormatableError:class written : " + f.getClass()); 76 if( null == f1) 77 System.out.println("FormatableError:read back as null"); 78 else 79 System.out.println("FormatableError:class read : " + f1.getClass()); 80 System.out.println("FormatableError:write id : " + FormatIdUtil.formatIdToString(f.getTypeFormatId())); 81 if( null != f1) 82 System.out.println("FormatableError:read id : " + FormatIdUtil.formatIdToString(f1.getTypeFormatId())); 83 t.printStackTrace(System.out); 84 } 85 86 } 90 91 } 92 | Popular Tags |