1 4 package com.tc.io.serializer.impl; 5 6 import com.tc.io.serializer.api.Serializer; 7 import com.tc.io.serializer.api.StringIndex; 8 9 import java.io.IOException ; 10 import java.io.ObjectInput ; 11 import java.io.ObjectOutput ; 12 13 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) throws IOException { 25 out.writeLong(this.stringIndex.getOrCreateIndexFor((String ) o)); 26 } 27 28 public Object deserializeFrom(ObjectInput in) throws IOException { 29 return this.stringIndex.getStringFor(in.readLong()); 30 } 31 32 public byte getSerializerID() { 33 return STRING_INDEX; 34 } 35 } 36 | Popular Tags |