📄 dxobjectoutputstream.java
字号:
// You can redistribute this software and/or modify it under the terms of// the Ozone Library License version 1 published by ozone-db.org.//// The original code and portions created by SMB are// Copyright (C) 1997-2000 by SMB GmbH. All rights reserved.//// $Id: DxObjectOutputStream.java,v 1.5 2000/10/28 16:55:14 daniela Exp $package org.ozoneDB.DxLib;import java.io.*;import java.util.*;/** * Dieser Stream ist ein Ersatz fuer den Java-ObjectOutputStream. In gewissen * Situationen ist er weniger speicherintensiv. Es koennen allerdings nur * Objekte geschrieben werden, die das Externalizable-Interface implementieren. * * * @author <a href="http://www.softwarebuero.de/">SMB</a> * @version $Revision: 1.5 $Date: 2000/10/28 16:55:14 $ */public class DxObjectOutputStream extends DataOutputStream implements ObjectOutput { protected Hashtable table; protected Hashtable classes; public DxObjectOutputStream( OutputStream out ) { super( new BufferedOutputStream( out, 4096 ) ); table = new Hashtable(); classes = new Hashtable(); } public DxObjectOutputStream( OutputStream out, int bufferSize ) { super( new BufferedOutputStream( out, bufferSize ) ); table = new Hashtable(); classes = new Hashtable(); } public void reset() throws IOException { table.clear(); classes.clear(); flush(); //System.out.println ("ObjOutputStream.reset()"); } protected void writeClassName( Object obj ) throws IOException { String cName = obj.getClass().getName(); Integer index = (Integer)classes.get( cName ); if (index == null) { //neuer Klassenname writeUTF( cName ); classes.put( cName, new Integer( classes.size() ) ); } else { // Klassenname schon geschrieben writeUTF( "+" ); writeShort( index.intValue() ); } } public void writeObject( Object obj ) throws IOException { try { // falls obj nicht init., wird beim lesen wieder mit null init. if (obj == null) { writeUTF( "_" ); //System.out.println ("writeObject(): null "); return; } if (!(obj instanceof Externalizable)) { throw new IOException( "Class " + obj.getClass().getName() + " doesn't implement Externalizable" ); } Integer hc = new Integer( System.identityHashCode( obj ) ); if (!table.containsKey( hc )) { // erst registrieren, sonst endlos-rekursion table.put( hc, obj ); // klassennamen speichern writeClassName( obj ); //System.out.println ("writeObject(): hashcode " + hc); // hashCode als objID speichern writeInt( hc.intValue() ); // objekt selbst speichern ((Externalizable)obj).writeExternal( this ); } else { // obj schon gespeichert writeUTF( ">" ); // hashCode als objID speichern writeInt( hc.intValue() ); //System.out.println ("writeObject(): hashCode ref " + hc); } } catch (IOException e) { throw e; } catch (Exception e) { throw new IOException( e.toString() ); } } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -