⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dxobjectinputstream.java

📁 用Java写的面相对象的数据库管理系统
💻 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: DxObjectInputStream.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-ObjectInputStream. In * gewissen Situationen ist er weniger speicherintensiv. Es koennen * allerdings nur Objekte gelesen 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 DxObjectInputStream extends DataInputStream implements ObjectInput {    protected Hashtable table;    protected Hashtable classes;            public DxObjectInputStream( InputStream in ) {        super( in );        table = new Hashtable();        classes = new Hashtable();    }            public DxObjectInputStream( InputStream in, int bufferSize ) {        super( new BufferedInputStream( in, bufferSize ) );        table = new Hashtable();        classes = new Hashtable();    }            public void reset() {        table.clear();        classes.clear();    //System.out.println ("ObjInputStream.reset()");    }             public String readClassName() throws IOException {        String cName = readUTF();                // _R_ und _N_ wird kein Index zugeordnet        if (cName.equals( ">" ) || cName.equals( "_" )) {            return cName;        }                 // klassennamen-referenz aufloesen        if (cName.equals( "+" )) {            Integer index = new Integer( readShort() );            cName = (String)classes.get( index );        } else {            classes.put( new Integer( classes.size() ), cName );        }                 return cName;    }             public Object readObject() throws IOException {        try {            // classenanmen lesen            String cName = readClassName();            //System.out.println ("readObject(): className: " + cName);            Object newObj = null;                        if (cName.equals( "_" )) {                // null - referenz wurde gespeichert                //System.out.println ("readObject(): null");                return null;            } else if (cName.equals( ">" )) {                // ist Referenz, wurde also schon geladen, entspr. Wert aus table lesen                Integer hc = new Integer( readInt() );                newObj = table.get( hc );                //System.out.println ("readObject(): hashCode ref " + hc + " from " + table.size());                if (newObj == null) {                    throw new IOException( "Object not found in referenz table !!" );                }             } else {                // neues objekt erzeugen                newObj = Class.forName( cName ).newInstance();                // hashcode lesen                Integer hc = new Integer( readInt() );                //System.out.println ("readObject(): class " + cName + " hashCode " + hc);                // objekt registrieren                table.put( hc, newObj );                // objektdaten lesen                if (newObj instanceof Externalizable) {                    ((Externalizable)newObj).readExternal( this );                } else {                    throw new IOException( "Object doesn't implement Externalizable" );                }             }             return newObj;        } catch (IOException e) {            throw e;        } catch (Exception e) {            throw new IOException( e.toString() );        }     } }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -