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 java.io.IOException;
19 import java.io.ObjectOutputStream;
20 import java.io.ObjectStreamClass;
21 import java.io.OutputStream;
22
23 class CompactObjectOutputStream extends ObjectOutputStream {
24
25 static final int TYPE_FAT_DESCRIPTOR = 0;
26 static final int TYPE_THIN_DESCRIPTOR = 1;
27
28 CompactObjectOutputStream(OutputStream out) throws IOException {
29 super(out);
30 }
31
32 @Override
33 protected void writeStreamHeader() throws IOException {
34 writeByte(STREAM_VERSION);
35 }
36
37 @Override
38 protected void writeClassDescriptor(ObjectStreamClass desc) throws IOException {
39 Class<?> clazz = desc.forClass();
40 if (clazz.isPrimitive() || clazz.isArray() || clazz.isInterface() ||
41 desc.getSerialVersionUID() == 0) {
42 write(TYPE_FAT_DESCRIPTOR);
43 super.writeClassDescriptor(desc);
44 } else {
45 write(TYPE_THIN_DESCRIPTOR);
46 writeUTF(desc.getName());
47 }
48 }
49 }