01: /*
02: * All content copyright (c) 2003-2007 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
03: */
04: package com.tc.object.dna.api;
05:
06: import com.tc.io.TCDataInput;
07: import com.tc.io.TCDataOutput;
08:
09: import java.io.IOException;
10:
11: /**
12: * Defines how to encode DNA onto a stream or decode data from a stream, with some different policies for encoding.
13: */
14: public interface DNAEncoding {
15:
16: /**
17: * When the policy is set to SERIALIZER then the DNAEncoding.decode() will return the exact Objects that where
18: * encoded. For Example if UTF8ByteDataHolder is serialized to a stream, then when it is deserialized, you get an
19: * UTF8ByteDataHolder object. Same goes for String or ClassHolder etc.
20: * <p>
21: * You may want such a policy in TCObjectInputStream, for example.
22: */
23: public static final byte SERIALIZER = 0x00;
24: /**
25: * When the policy is set to STORAGE then the DNAEncoding.decode() may return Objects that represent the original
26: * objects for performance/memory. For Example if String is serialized to a stream, then when it is deserialized, you
27: * may get UTF8ByteDataHolder instead.
28: * <p>
29: * As the name says, you may want such a policy for storage in the L2.
30: */
31: public static final byte STORAGE = 0x01;
32: /**
33: * When the policy is set to APPLICATOR then the DNAEncoding.decode() will return the original Objects that were
34: * encoded in the original stream. For Example if UTF8ByteDataHolder is serialized to a stream, then when it is
35: * deserialized, you get a String object.
36: * <p>
37: * You may want such a policy in TCObjectInputStream, for example.
38: */
39: public static final byte APPLICATOR = 0x02;
40:
41: /**
42: * Get the policy in use for this encoding, as defined by constants in this class.
43: * @return The policy
44: */
45: public abstract byte getPolicy();
46:
47: /**
48: * Encode a classloader object onto an output stream
49: * @param value The classloader
50: * @param output The output
51: */
52: public abstract void encodeClassLoader(Object value,
53: TCDataOutput output);
54:
55: /**
56: * Encode an object onto an output stream
57: * @param value The object
58: * @param output The output
59: */
60: public abstract void encode(Object value, TCDataOutput output);
61:
62: /**
63: * Decode an object from an input stream
64: * @param input The input stream
65: */
66: public abstract Object decode(TCDataInput input)
67: throws IOException, ClassNotFoundException;
68:
69: /**
70: * Encode an array onto an output stream, automatically determine array length
71: * @param value The array
72: * @param output The output
73: */
74: public abstract void encodeArray(Object value, TCDataOutput output);
75:
76: /**
77: * Encode an array onto an output stream
78: * @param value The array
79: * @param output The output
80: * @param length The length of the array to encode
81: */
82: public abstract void encodeArray(Object value, TCDataOutput output,
83: int length);
84:
85: }
|