001: /*
002: * <copyright>
003: *
004: * Copyright 1997-2004 BBNT Solutions, LLC
005: * under sponsorship of the Defense Advanced Research Projects
006: * Agency (DARPA).
007: *
008: * You can redistribute this software and/or modify it under the
009: * terms of the Cougaar Open Source License as published on the
010: * Cougaar Open Source Website (www.cougaar.org).
011: *
012: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
013: * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
014: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
015: * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
016: * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
017: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
018: * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
019: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
020: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
021: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
022: * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
023: *
024: * </copyright>
025: */
026:
027: package org.cougaar.mts.base;
028:
029: import java.io.InputStream;
030: import java.io.ObjectInput;
031: import java.io.ObjectInputStream;
032:
033: import org.cougaar.mts.std.AttributedMessage;
034:
035: /**
036: * Default implementatiom of {@link MessageReader} that uses a trivial
037: * {@link ObjectInputStream} extension to delegate calls to the
038: * original {@link ObjectInput}.
039: */
040: public class MessageReaderImpl implements MessageReader {
041:
042: static class SimpleObjectInputStream extends ObjectInputStream {
043: private ObjectInput in;
044:
045: SimpleObjectInputStream(ObjectInput in)
046: throws java.io.IOException {
047: this .in = in;
048: }
049:
050: public int available() throws java.io.IOException {
051: return in.available();
052: }
053:
054: public void close() throws java.io.IOException {
055: in.close();
056: }
057:
058: public boolean markSupported() {
059: return false;
060: }
061:
062: public int read() throws java.io.IOException {
063: return in.read();
064: }
065:
066: public int read(byte[] b) throws java.io.IOException {
067: return in.read(b);
068: }
069:
070: public int read(byte[] b, int off, int len)
071: throws java.io.IOException {
072: return in.read(b, off, len);
073: }
074:
075: public synchronized void reset() throws java.io.IOException {
076: }
077:
078: public long skip(long n) throws java.io.IOException {
079: return in.skip(n);
080: }
081:
082: }
083:
084: public void finalizeAttributes(AttributedMessage msg) {
085: }
086:
087: public void preProcess() {
088: }
089:
090: public InputStream getObjectInputStream(ObjectInput in)
091: throws java.io.IOException, ClassNotFoundException {
092: if (in instanceof ObjectInputStream) {
093: return (InputStream) in;
094: } else {
095: return new SimpleObjectInputStream(in);
096: }
097: }
098:
099: public void finishInput() {
100: }
101:
102: public void postProcess() {
103: }
104:
105: }
|