34
34
import java .math .BigDecimal ;
35
35
import java .math .BigInteger ;
36
36
import java .net .MalformedURLException ;
37
+ import java .net .URI ;
38
+ import java .net .URISyntaxException ;
37
39
import java .net .URL ;
38
40
import java .nio .charset .Charset ;
39
41
import java .sql .Time ;
58
60
import java .util .TimeZone ;
59
61
import java .util .TreeMap ;
60
62
import java .util .TreeSet ;
63
+ import java .util .UUID ;
61
64
import java .util .concurrent .ConcurrentSkipListMap ;
65
+ import java .util .concurrent .atomic .AtomicBoolean ;
66
+ import java .util .concurrent .atomic .AtomicInteger ;
67
+ import java .util .concurrent .atomic .AtomicLong ;
68
+ import java .util .concurrent .atomic .AtomicReference ;
69
+ import java .util .regex .Pattern ;
62
70
63
71
/** Contains many serializer classes that are provided by {@link Kryo#addDefaultSerializer(Class, Class) default}.
64
72
* @author Nathan Sweet */
@@ -900,6 +908,7 @@ public List copy (Kryo kryo, List original) {
900
908
}
901
909
}
902
910
911
+ /** Serializer for {@link BitSet} */
903
912
public static class BitSetSerializer extends Serializer <BitSet > {
904
913
public void write (Kryo kryo , Output output , BitSet set ) {
905
914
long [] values = set .toLongArray ();
@@ -910,12 +919,113 @@ public void write (Kryo kryo, Output output, BitSet set) {
910
919
public BitSet read (Kryo kryo , Input input , Class type ) {
911
920
int length = input .readVarInt (true );
912
921
long [] values = input .readLongs (length );
913
- BitSet set = BitSet .valueOf (values );
914
- return set ;
922
+ return BitSet .valueOf (values );
915
923
}
916
924
917
925
public BitSet copy (Kryo kryo , BitSet original ) {
918
926
return BitSet .valueOf (original .toLongArray ());
919
927
}
920
928
}
929
+
930
+ /** Serializer for {@link Pattern} */
931
+ public static class PatternSerializer extends ImmutableSerializer <Pattern > {
932
+ public void write (final Kryo kryo , final Output output , final Pattern pattern ) {
933
+ output .writeString (pattern .pattern ());
934
+ output .writeInt (pattern .flags (), true );
935
+ }
936
+
937
+ public Pattern read (final Kryo kryo , final Input input , final Class <? extends Pattern > patternClass ) {
938
+ String regex = input .readString ();
939
+ int flags = input .readInt (true );
940
+ return Pattern .compile (regex , flags );
941
+ }
942
+ }
943
+
944
+ /** Serializer for {@link URI} */
945
+ public static class URISerializer extends ImmutableSerializer <java .net .URI > {
946
+ public void write (Kryo kryo , Output output , URI uri ) {
947
+ output .writeString (uri .toString ());
948
+ }
949
+
950
+ public URI read (Kryo kryo , Input input , Class <? extends URI > uriClass ) {
951
+ try {
952
+ return new URI (input .readString ());
953
+ } catch (URISyntaxException ex ) {
954
+ throw new KryoException (ex );
955
+ }
956
+ }
957
+ }
958
+
959
+ /** Serializer for {@link UUID} */
960
+ public static class UUIDSerializer extends ImmutableSerializer <UUID > {
961
+ public void write (Kryo kryo , Output output , UUID uuid ) {
962
+ output .writeLong (uuid .getMostSignificantBits ());
963
+ output .writeLong (uuid .getLeastSignificantBits ());
964
+ }
965
+
966
+ public UUID read (final Kryo kryo , final Input input , final Class <? extends UUID > uuidClass ) {
967
+ return new UUID (input .readLong (), input .readLong ());
968
+ }
969
+ }
970
+
971
+ /** Serializer for {@link AtomicBoolean} */
972
+ public static class AtomicBooleanSerializer extends Serializer <AtomicBoolean > {
973
+ public void write (Kryo kryo , Output output , AtomicBoolean object ) {
974
+ output .writeBoolean (object .get ());
975
+ }
976
+
977
+ public AtomicBoolean read (Kryo kryo , Input input , Class <? extends AtomicBoolean > type ) {
978
+ return new AtomicBoolean (input .readBoolean ());
979
+ }
980
+
981
+ public AtomicBoolean copy (Kryo kryo , AtomicBoolean original ) {
982
+ return new AtomicBoolean (original .get ());
983
+ }
984
+ }
985
+
986
+ /** Serializer for {@link AtomicInteger} */
987
+ public static class AtomicIntegerSerializer extends Serializer <AtomicInteger > {
988
+ public void write (Kryo kryo , Output output , AtomicInteger object ) {
989
+ output .writeInt (object .get ());
990
+ }
991
+
992
+ public AtomicInteger read (Kryo kryo , Input input , Class <? extends AtomicInteger > type ) {
993
+ return new AtomicInteger (input .readInt ());
994
+ }
995
+
996
+ public AtomicInteger copy (Kryo kryo , AtomicInteger original ) {
997
+ return new AtomicInteger (original .get ());
998
+ }
999
+ }
1000
+
1001
+ /** Serializer for {@link AtomicLong} */
1002
+ public static class AtomicLongSerializer extends Serializer <AtomicLong > {
1003
+ public void write (Kryo kryo , Output output , AtomicLong object ) {
1004
+ output .writeLong (object .get ());
1005
+ }
1006
+
1007
+ public AtomicLong read (Kryo kryo , Input input , Class <? extends AtomicLong > type ) {
1008
+ return new AtomicLong (input .readLong ());
1009
+ }
1010
+
1011
+ public AtomicLong copy (Kryo kryo , AtomicLong original ) {
1012
+ return new AtomicLong (original .get ());
1013
+ }
1014
+ }
1015
+
1016
+ /** Serializer for {@link AtomicReference} */
1017
+ public static class AtomicReferenceSerializer extends Serializer <AtomicReference > {
1018
+ public void write (Kryo kryo , Output output , AtomicReference object ) {
1019
+ kryo .writeClassAndObject (output , object .get ());
1020
+ }
1021
+
1022
+ public AtomicReference read (Kryo kryo , Input input , Class <? extends AtomicReference > type ) {
1023
+ final Object value = kryo .readClassAndObject (input );
1024
+ return new AtomicReference (value );
1025
+ }
1026
+
1027
+ public AtomicReference copy (Kryo kryo , AtomicReference original ) {
1028
+ return new AtomicReference <>(kryo .copy (original .get ()));
1029
+ }
1030
+ }
921
1031
}
0 commit comments