This repository has been archived by the owner on Mar 8, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 153
/
XObjectInputStream.java
328 lines (284 loc) · 11.3 KB
/
XObjectInputStream.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
/*
* Copyright (c) 1998, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
import java.io.*;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.lang.reflect.InvocationTargetException;
import java.security.*;
class XObjectInputStream extends AbstractObjectInputStream {
XObjectInputStream(InputStream in)
throws IOException, StreamCorruptedException
{
super(in);
dis = new DataInputStream(in);
}
final public void defaultReadObject()
throws IOException, ClassNotFoundException, NotActiveException
{
}
final protected Object readObjectOverride()
throws OptionalDataException, ClassNotFoundException, IOException {
Object readResult = null;
Object prevObject = currentObject;
Class prevDesc = currentClassDescriptor;
boolean NotImplemented = true;
if (NotImplemented)
throw new IOException("readObjectOverride not implemented");
try {
currentObject = null;
//Read in class of object to currentDescriptor
String className = dis.readUTF();
currentClassDescriptor = Class.forName(className);
try {
//currentObject = Allocate a new instance of the class
currentObject =
allocateNewObject(currentClassDescriptor,
currentClassDescriptor);
} catch (InstantiationException e) {
throw new InvalidClassException(currentClassDescriptor.getName(),
e.getMessage());
} catch (IllegalAccessException e) {
throw new InvalidClassException(currentClassDescriptor.getName(),
e.getMessage());
}
//if currentDescriptor.isAssignable(Externalizable.class) {
// Object[] argList = {this};
// InvokeMethod(currentObject, readExternalMethod, argList);
//} else {
// Does currentDescriptor have a readObject method
// if it does
// invokeMethod(this, readObjectMethod, {this});
// else
// defaultReadObject();
//}
// check for replacement on currentObject.
// if toplevel readobject
// doObjectValidations.
} finally {
readResult = currentObject;
currentObject = prevObject;
}
return readResult;
}
public ObjectInputStream.GetField readFields()
throws IOException, ClassNotFoundException, NotActiveException {
throw new Error("not implememted");
}
public synchronized void registerValidation(ObjectInputValidation obj,
int prio)
throws NotActiveException, InvalidObjectException {
}
public int read() throws IOException {
return dis.read();
}
public int read(byte[] data, int offset, int length) throws IOException {
return dis.read(data, offset, length);
}
public int available() throws IOException {
return in.available();
}
public boolean readBoolean() throws IOException {
throw new IOException("Not Implemented");
}
public byte readByte() throws IOException {
throw new IOException("Not Implemented");
}
public int readUnsignedByte() throws IOException {
throw new IOException("Not Implemented");
}
public short readShort() throws IOException {
throw new IOException("Not Implemented");
}
public int readUnsignedShort() throws IOException {
throw new IOException("Not Implemented");
}
public char readChar() throws IOException {
throw new IOException("Not Implemented");
}
public int readInt() throws IOException {
throw new IOException("Not Implemented");
}
public long readLong() throws IOException {
throw new IOException("Not Implemented");
}
public float readFloat() throws IOException {
throw new IOException("Not Implemented");
}
public double readDouble() throws IOException {
throw new IOException("Not Implemented");
}
public void readFully(byte[] data) throws IOException {
throw new IOException("Not Implemented");
}
public void readFully(byte[] data, int offset, int size) throws IOException {
throw new IOException("Not Implemented");
}
public int skipBytes(int len) throws IOException {
throw new IOException("Not Implemented");
}
public String readLine() throws IOException {
throw new IOException("Not Implemented");
}
public String readUTF() throws IOException {
throw new IOException("Not Implemented");
}
public void close() throws IOException {
in.close();
}
/**********************************************************/
/**
* Provide access to the persistent fields read from the input stream.
*/
public static class InternalGetField extends ObjectInputStream.GetField {
/**
* Get the ObjectStreamClass that describes the fields in the stream.
*/
public ObjectStreamClass getObjectStreamClass() {
throw new Error("not implemented");
}
/**
* Return true if the named field is defaulted and has no value
* in this stream.
*/
public boolean defaulted(String name)
throws IOException, IllegalArgumentException
{
throw new Error("not implemented");
//ObjectStreamField field = checkField(name, null);
}
public boolean get(String name, boolean defvalue)
throws IOException, IllegalArgumentException {
throw new Error("not implemented");
}
public char get(String name, char defvalue)
throws IOException, IllegalArgumentException {
throw new Error("not implemented");
}
public byte get(String name, byte defvalue)
throws IOException, IllegalArgumentException {
throw new Error("not implemented");
}
public short get(String name, short defvalue)
throws IOException, IllegalArgumentException {
throw new Error("not implemented");
}
public int get(String name, int defvalue)
throws IOException, IllegalArgumentException {
throw new Error("not implemented");
}
public long get(String name, long defvalue)
throws IOException, IllegalArgumentException {
throw new Error("not implemented");
}
public float get(String name, float defvalue)
throws IOException, IllegalArgumentException {
throw new Error("not implemented");
}
public double get(String name, double defvalue)
throws IOException, IllegalArgumentException {
throw new Error("not implemented");
}
public Object get(String name, Object defvalue)
throws IOException, IllegalArgumentException {
throw new Error("not implemented");
}
public void read(ObjectInputStream in)
throws IOException, ClassNotFoundException {
}
}
private Object currentObject;
private Class currentClassDescriptor;
/****************************************************************/
/* CODE LIFTED FROM ObjectStreamClass constuctor.
* ObjectStreamClass.readObjectMethod is private.
*
* Look for the readObject method
* Set the accessible flag on it here. ObjectOutputStream
* will call it as necessary.
*/
static public Method getReadObjectMethod(final Class cl) {
Method readObjectMethod = (Method)
java.security.AccessController.doPrivileged
(new java.security.PrivilegedAction() {
public Object run() {
Method m = null;
try {
Class[] args = {ObjectInputStream.class};
m = cl.getDeclaredMethod("readObject", args);
int mods = m.getModifiers();
// Method must be private and non-static
if (!Modifier.isPrivate(mods) ||
Modifier.isStatic(mods)) {
m = null;
} else {
m.setAccessible(true);
}
} catch (NoSuchMethodException e) {
m = null;
}
return m;
}
});
return readObjectMethod;
}
/*************************************************************/
/* taken verbatim from ObjectInputStream. */
static private void invokeMethod(final Object obj, final Method m,
final Object[] argList)
throws IOException
{
try {
java.security.AccessController.doPrivileged
(new java.security.PrivilegedExceptionAction() {
public Object run() throws InvocationTargetException,
java.lang.IllegalAccessException {
m.invoke(obj, argList);
return null;
}
});
} catch (java.security.PrivilegedActionException e) {
Exception ex = e.getException();
if (ex instanceof InvocationTargetException) {
Throwable t =
((InvocationTargetException)ex).getTargetException();
if (t instanceof IOException)
throw (IOException)t;
else if (t instanceof RuntimeException)
throw (RuntimeException) t;
else if (t instanceof Error)
throw (Error) t;
else
throw new Error("interal error");
} else {
// IllegalAccessException cannot happen
}
}
}
protected boolean enableResolveObject(boolean enable)
throws SecurityException
{
throw new Error("To be implemented");
}
private DataInputStream dis;
};