01: /*
02: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
03: */
04: package com.tc.io.serializer.impl;
05:
06: import com.tc.io.serializer.api.Serializer;
07: import com.tc.io.serializer.api.StringIndex;
08:
09: import java.io.IOException;
10: import java.io.ObjectInput;
11: import java.io.ObjectOutput;
12:
13: /**
14: * Strings
15: */
16: public final class StringSerializer implements Serializer {
17:
18: private final StringIndex stringIndex;
19:
20: public StringSerializer(StringIndex stringIndex) {
21: this .stringIndex = stringIndex;
22: }
23:
24: public void serializeTo(Object o, ObjectOutput out)
25: throws IOException {
26: out.writeLong(this .stringIndex.getOrCreateIndexFor((String) o));
27: }
28:
29: public Object deserializeFrom(ObjectInput in) throws IOException {
30: return this .stringIndex.getStringFor(in.readLong());
31: }
32:
33: public byte getSerializerID() {
34: return STRING_INDEX;
35: }
36: }
|