01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: *
15: * See the License for the specific language governing permissions and
16: * limitations under the License.
17: */
18:
19: /**
20: * @author Mikhail A. Markov
21: * @version $Revision: 1.1.2.1 $
22: */package org.apache.harmony.rmi;
23:
24: import java.io.IOException;
25: import java.io.OutputStream;
26: import java.io.ObjectOutputStream;
27: import java.io.ByteArrayOutputStream;
28:
29: import org.apache.harmony.rmi.transport.RMIObjectOutputStream;
30:
31: /**
32: * The MarshalledObjectOutputStream uses the same serialization rules as it's
33: * predecessor RMIObjectOutputStream, but it holds annotations for classes
34: * separately from the main stream. It is intended to be used by
35: * java.rmi.MarshalledObject class.
36: *
37: * @author Mikhail A. Markov
38: * @version $Revision: 1.1.2.1 $
39: *
40: * @see RMIObjectOutputStream
41: */
42: public class MarshalledObjectOutputStream extends RMIObjectOutputStream {
43:
44: // ByteArrayOutputStream to write annotations.
45: private ByteArrayOutputStream locStream;
46:
47: /**
48: * Constructs a MarshalledObjectOutputStream that writes to the specified
49: * OutputStream.
50: *
51: * @param out underlying OutputStream
52: *
53: * @throws IOException if an I/O error occurred during stream initialization
54: */
55: public MarshalledObjectOutputStream(OutputStream out)
56: throws IOException {
57: super (out);
58: locStream = new ByteArrayOutputStream();
59: setLocStream(new ObjectOutputStream(locStream));
60: }
61:
62: /**
63: * Returns location annotations.
64: *
65: * @return location annotations.
66: */
67: public byte[] getLocBytes() {
68: return hasAnnotations() ? locStream.toByteArray() : null;
69: }
70: }
|