001: /**
002: * Objective Database Abstraction Layer (ODAL)
003: * Copyright (c) 2004, The ODAL Development Group
004: * All rights reserved.
005: * For definition of the ODAL Development Group please refer to LICENCE.txt file
006: *
007: * Distributable under LGPL license.
008: * See terms of license at gnu.org.
009: */package com.completex.objective.components.persistency.io.obj.impl;
010:
011: import com.completex.objective.components.persistency.io.PoObjectInput;
012: import com.completex.objective.components.persistency.PersistentObject;
013:
014: import java.io.IOException;
015: import java.io.InputStream;
016: import java.io.ObjectInputStream;
017:
018: /**
019: * @author Gennady Krizhevsky
020: */
021: public class PoInputStream implements PoObjectInput {
022:
023: private ObjectInputStream objectInputStream;
024: private boolean preserveOriginalValues;
025: private boolean initialized;
026:
027: public PoInputStream(InputStream inputStream) throws IOException {
028: this .objectInputStream = new ObjectInputStream(inputStream);
029: }
030:
031: public int available() throws IOException {
032: return objectInputStream.available();
033: }
034:
035: public int read() throws IOException {
036: init();
037: return objectInputStream.read();
038: }
039:
040: public void close() throws IOException {
041: objectInputStream.close();
042: }
043:
044: public long skip(long n) throws IOException {
045: return objectInputStream.skip(n);
046: }
047:
048: public int read(byte b[]) throws IOException {
049: init();
050: return objectInputStream.read(b);
051: }
052:
053: public int read(byte b[], int off, int len) throws IOException {
054: init();
055: return objectInputStream.read(b, off, len);
056: }
057:
058: public Object readObject() throws ClassNotFoundException,
059: IOException {
060: init();
061: Object obj = objectInputStream.readObject();
062: if (obj instanceof PersistentObject) {
063: PersistentObject persistent = ((PersistentObject) obj);
064: persistent.record2().setPreserveOriginalValues(
065: preserveOriginalValues);
066: }
067: return obj;
068: }
069:
070: public byte readByte() throws IOException {
071: init();
072: return objectInputStream.readByte();
073: }
074:
075: public char readChar() throws IOException {
076: init();
077: return objectInputStream.readChar();
078: }
079:
080: public double readDouble() throws IOException {
081: init();
082: return objectInputStream.readDouble();
083: }
084:
085: public float readFloat() throws IOException {
086: init();
087: return objectInputStream.readFloat();
088: }
089:
090: public int readInt() throws IOException {
091: init();
092: return objectInputStream.readInt();
093: }
094:
095: public int readUnsignedByte() throws IOException {
096: init();
097: return objectInputStream.readUnsignedByte();
098: }
099:
100: public int readUnsignedShort() throws IOException {
101: init();
102: return objectInputStream.readUnsignedShort();
103: }
104:
105: public long readLong() throws IOException {
106: init();
107: return objectInputStream.readLong();
108: }
109:
110: public short readShort() throws IOException {
111: init();
112: return objectInputStream.readShort();
113: }
114:
115: public boolean readBoolean() throws IOException {
116: init();
117: return objectInputStream.readBoolean();
118: }
119:
120: public int skipBytes(int n) throws IOException {
121: return objectInputStream.skipBytes(n);
122: }
123:
124: public void readFully(byte b[]) throws IOException {
125: init();
126: objectInputStream.readFully(b);
127: }
128:
129: public void readFully(byte b[], int off, int len)
130: throws IOException {
131: init();
132: objectInputStream.readFully(b, off, len);
133: }
134:
135: public String readLine() throws IOException {
136: init();
137: return objectInputStream.readLine();
138: }
139:
140: public String readUTF() throws IOException {
141: init();
142: return objectInputStream.readUTF();
143: }
144:
145: public boolean isPreserveOriginalValues() {
146: return preserveOriginalValues;
147: }
148:
149: protected void init() throws IOException {
150: if (!initialized) {
151: preserveOriginalValues = objectInputStream.readBoolean();
152: initialized = true;
153: }
154: }
155:
156: }
|