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.PoObjectOutput;
012: import com.completex.objective.components.persistency.PersistentObject;
013:
014: import java.io.IOException;
015: import java.io.ObjectOutputStream;
016: import java.io.OutputStream;
017:
018: /**
019: * @author Gennady Krizhevsky
020: */
021: public class PoOutputStream implements PoObjectOutput {
022:
023: private ObjectOutputStream objectOutputStream;
024: private boolean preserveOriginalValues;
025: private boolean initialized;
026:
027: public PoOutputStream(OutputStream out) throws IOException {
028: objectOutputStream = new ObjectOutputStream(out);
029: }
030:
031: public void close() throws IOException {
032: objectOutputStream.close();
033: }
034:
035: public void flush() throws IOException {
036: objectOutputStream.flush();
037: }
038:
039: public void write(int b) throws IOException {
040: init();
041: objectOutputStream.write(b);
042: }
043:
044: public void write(byte b[]) throws IOException {
045: init();
046: objectOutputStream.write(b);
047: }
048:
049: public void write(byte b[], int off, int len) throws IOException {
050: init();
051: objectOutputStream.write(b, off, len);
052: }
053:
054: public void writeObject(Object obj) throws IOException {
055: init();
056: if (obj instanceof PersistentObject) {
057: PersistentObject persistent = ((PersistentObject) obj);
058: persistent.record2().setPreserveOriginalValues(
059: preserveOriginalValues);
060: }
061: objectOutputStream.writeObject(obj);
062: }
063:
064: public void writeDouble(double v) throws IOException {
065: init();
066: objectOutputStream.writeDouble(v);
067: }
068:
069: public void writeFloat(float v) throws IOException {
070: init();
071: objectOutputStream.writeFloat(v);
072: }
073:
074: public void writeByte(int v) throws IOException {
075: init();
076: objectOutputStream.writeByte(v);
077: }
078:
079: public void writeChar(int v) throws IOException {
080: init();
081: objectOutputStream.writeChar(v);
082: }
083:
084: public void writeInt(int v) throws IOException {
085: init();
086: objectOutputStream.writeInt(v);
087: }
088:
089: public void writeShort(int v) throws IOException {
090: init();
091: objectOutputStream.writeShort(v);
092: }
093:
094: public void writeLong(long v) throws IOException {
095: init();
096: objectOutputStream.writeLong(v);
097: }
098:
099: public void writeBoolean(boolean v) throws IOException {
100: init();
101: objectOutputStream.writeBoolean(v);
102: }
103:
104: public void writeBytes(String s) throws IOException {
105: init();
106: objectOutputStream.writeBytes(s);
107: }
108:
109: public void writeChars(String s) throws IOException {
110: init();
111: objectOutputStream.writeChars(s);
112: }
113:
114: public void writeUTF(String str) throws IOException {
115: init();
116: objectOutputStream.writeUTF(str);
117: }
118:
119: public boolean isPreserveOriginalValues() {
120: return preserveOriginalValues;
121: }
122:
123: public void setPreserveOriginalValues(boolean preserveOriginalValues) {
124: this .preserveOriginalValues = preserveOriginalValues;
125: }
126:
127: protected void init() throws IOException {
128: if (!initialized) {
129: objectOutputStream.writeBoolean(preserveOriginalValues);
130: initialized = true;
131: }
132: }
133: }
|