1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package io.netty.handler.codec.serialization;
17
18 import io.netty.util.internal.ObjectUtil;
19
20 import java.io.BufferedReader;
21 import java.io.DataInputStream;
22 import java.io.IOException;
23 import java.io.InputStream;
24 import java.io.ObjectInput;
25 import java.io.StreamCorruptedException;
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41 @Deprecated
42 public class ObjectDecoderInputStream extends InputStream implements
43 ObjectInput {
44
45 private final DataInputStream in;
46 private final int maxObjectSize;
47 private final ClassResolver classResolver;
48
49
50
51
52
53
54
55
56 public ObjectDecoderInputStream(InputStream in) {
57 this(in, null);
58 }
59
60
61
62
63
64
65
66
67
68
69
70 public ObjectDecoderInputStream(InputStream in, ClassLoader classLoader) {
71 this(in, classLoader, 1048576);
72 }
73
74
75
76
77
78
79
80
81
82
83
84
85 public ObjectDecoderInputStream(InputStream in, int maxObjectSize) {
86 this(in, null, maxObjectSize);
87 }
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103 public ObjectDecoderInputStream(InputStream in, ClassLoader classLoader, int maxObjectSize) {
104 ObjectUtil.checkNotNull(in, "in");
105 ObjectUtil.checkPositive(maxObjectSize, "maxObjectSize");
106
107 if (in instanceof DataInputStream) {
108 this.in = (DataInputStream) in;
109 } else {
110 this.in = new DataInputStream(in);
111 }
112 classResolver = ClassResolvers.weakCachingResolver(classLoader);
113 this.maxObjectSize = maxObjectSize;
114 }
115
116 @Override
117 public Object readObject() throws ClassNotFoundException, IOException {
118 int dataLen = readInt();
119 if (dataLen <= 0) {
120 throw new StreamCorruptedException("invalid data length: " + dataLen);
121 }
122 if (dataLen > maxObjectSize) {
123 throw new StreamCorruptedException(
124 "data length too big: " + dataLen + " (max: " + maxObjectSize + ')');
125 }
126
127 return new CompactObjectInputStream(in, classResolver).readObject();
128 }
129
130 @Override
131 public int available() throws IOException {
132 return in.available();
133 }
134
135 @Override
136 public void close() throws IOException {
137 in.close();
138 }
139
140
141 @Override
142 public void mark(int readlimit) {
143 in.mark(readlimit);
144 }
145
146 @Override
147 public boolean markSupported() {
148 return in.markSupported();
149 }
150
151
152 @Override
153 public int read() throws IOException {
154 return in.read();
155 }
156
157 @Override
158 public final int read(byte[] b, int off, int len) throws IOException {
159 return in.read(b, off, len);
160 }
161
162 @Override
163 public final int read(byte[] b) throws IOException {
164 return in.read(b);
165 }
166
167 @Override
168 public final boolean readBoolean() throws IOException {
169 return in.readBoolean();
170 }
171
172 @Override
173 public final byte readByte() throws IOException {
174 return in.readByte();
175 }
176
177 @Override
178 public final char readChar() throws IOException {
179 return in.readChar();
180 }
181
182 @Override
183 public final double readDouble() throws IOException {
184 return in.readDouble();
185 }
186
187 @Override
188 public final float readFloat() throws IOException {
189 return in.readFloat();
190 }
191
192 @Override
193 public final void readFully(byte[] b, int off, int len) throws IOException {
194 in.readFully(b, off, len);
195 }
196
197 @Override
198 public final void readFully(byte[] b) throws IOException {
199 in.readFully(b);
200 }
201
202 @Override
203 public final int readInt() throws IOException {
204 return in.readInt();
205 }
206
207
208
209
210 @Override
211 @Deprecated
212 public final String readLine() throws IOException {
213 return in.readLine();
214 }
215
216 @Override
217 public final long readLong() throws IOException {
218 return in.readLong();
219 }
220
221 @Override
222 public final short readShort() throws IOException {
223 return in.readShort();
224 }
225
226 @Override
227 public final int readUnsignedByte() throws IOException {
228 return in.readUnsignedByte();
229 }
230
231 @Override
232 public final int readUnsignedShort() throws IOException {
233 return in.readUnsignedShort();
234 }
235
236 @Override
237 public final String readUTF() throws IOException {
238 return in.readUTF();
239 }
240
241 @Override
242 public void reset() throws IOException {
243 in.reset();
244 }
245
246 @Override
247 public long skip(long n) throws IOException {
248 return in.skip(n);
249 }
250
251 @Override
252 public final int skipBytes(int n) throws IOException {
253 return in.skipBytes(n);
254 }
255 }