diff --git a/src/dorkbox/util/serialization/ArraysAsListSerializer.java b/src/dorkbox/util/serialization/ArraysAsListSerializer.java
index 8a0b760..78833c9 100644
--- a/src/dorkbox/util/serialization/ArraysAsListSerializer.java
+++ b/src/dorkbox/util/serialization/ArraysAsListSerializer.java
@@ -15,16 +15,16 @@
*/
package dorkbox.util.serialization;
-import com.esotericsoftware.kryo.Kryo;
-import com.esotericsoftware.kryo.Serializer;
-import com.esotericsoftware.kryo.io.Input;
-import com.esotericsoftware.kryo.io.Output;
-
import java.lang.reflect.Array;
import java.lang.reflect.Field;
import java.util.Arrays;
import java.util.List;
+import com.esotericsoftware.kryo.Kryo;
+import com.esotericsoftware.kryo.Serializer;
+import com.esotericsoftware.kryo.io.Input;
+import com.esotericsoftware.kryo.io.Output;
+
/**
* A kryo {@link Serializer} for lists created via {@link Arrays#asList(Object...)}.
*
@@ -34,78 +34,92 @@ import java.util.List;
*
* @author Martin Grotzke
*/
-public class ArraysAsListSerializer extends Serializer> {
+public
+class ArraysAsListSerializer extends Serializer> {
+ private static
+ Class> getPrimitiveWrapperClass(final Class> c) {
+ if (c.isPrimitive()) {
+ if (c.equals(Long.TYPE)) {
+ return Long.class;
+ }
+ else if (c.equals(Integer.TYPE)) {
+ return Integer.class;
+ }
+ else if (c.equals(Double.TYPE)) {
+ return Double.class;
+ }
+ else if (c.equals(Float.TYPE)) {
+ return Float.class;
+ }
+ else if (c.equals(Boolean.TYPE)) {
+ return Boolean.class;
+ }
+ else if (c.equals(Character.TYPE)) {
+ return Character.class;
+ }
+ else if (c.equals(Short.TYPE)) {
+ return Short.class;
+ }
+ else if (c.equals(Byte.TYPE)) {
+ return Byte.class;
+ }
+ }
+ return c;
+ }
private Field _arrayField;
- public ArraysAsListSerializer() {
+ public
+ ArraysAsListSerializer() {
try {
- _arrayField = Class.forName( "java.util.Arrays$ArrayList" ).getDeclaredField( "a" );
- _arrayField.setAccessible( true );
- } catch ( final Exception e ) {
- throw new RuntimeException( e );
+ _arrayField = Class.forName("java.util.Arrays$ArrayList")
+ .getDeclaredField("a");
+ _arrayField.setAccessible(true);
+ } catch (final Exception e) {
+ throw new RuntimeException(e);
}
// Immutable causes #copy(obj) to return the original object
setImmutable(true);
}
@Override
- public List> read(final Kryo kryo, final Input input, final Class> type) {
- final int length = input.readInt(true);
- Class> componentType = kryo.readClass( input ).getType();
- if (componentType.isPrimitive()) {
- componentType = getPrimitiveWrapperClass(componentType);
- }
+ public
+ void write(final Kryo kryo, final Output output, final List> obj) {
try {
- final Object items = Array.newInstance( componentType, length );
- for( int i = 0; i < length; i++ ) {
- Array.set(items, i, kryo.readClassAndObject( input ));
+ final Object[] array = (Object[]) _arrayField.get(obj);
+ output.writeInt(array.length, true);
+ final Class> componentType = array.getClass()
+ .getComponentType();
+ kryo.writeClass(output, componentType);
+ for (final Object item : array) {
+ kryo.writeClassAndObject(output, item);
}
- return Arrays.asList( (Object[])items );
- } catch ( final Exception e ) {
- throw new RuntimeException( e );
+ } catch (final RuntimeException e) {
+ // Don't eat and wrap RuntimeExceptions because the ObjectBuffer.write...
+ // handles SerializationException specifically (resizing the buffer)...
+ throw e;
+ } catch (final Exception e) {
+ throw new RuntimeException(e);
}
}
@Override
- public void write(final Kryo kryo, final Output output, final List> obj) {
+ public
+ List> read(final Kryo kryo, final Input input, final Class> type) {
+ final int length = input.readInt(true);
+ Class> componentType = kryo.readClass(input)
+ .getType();
+ if (componentType.isPrimitive()) {
+ componentType = getPrimitiveWrapperClass(componentType);
+ }
try {
- final Object[] array = (Object[]) _arrayField.get( obj );
- output.writeInt(array.length, true);
- final Class> componentType = array.getClass().getComponentType();
- kryo.writeClass( output, componentType );
- for( final Object item : array ) {
- kryo.writeClassAndObject( output, item );
+ final Object items = Array.newInstance(componentType, length);
+ for (int i = 0; i < length; i++) {
+ Array.set(items, i, kryo.readClassAndObject(input));
}
- } catch ( final RuntimeException e ) {
- // Don't eat and wrap RuntimeExceptions because the ObjectBuffer.write...
- // handles SerializationException specifically (resizing the buffer)...
- throw e;
- } catch ( final Exception e ) {
- throw new RuntimeException( e );
+ return Arrays.asList((Object[]) items);
+ } catch (final Exception e) {
+ throw new RuntimeException(e);
}
}
-
- private static Class> getPrimitiveWrapperClass(final Class> c) {
- if (c.isPrimitive()) {
- if (c.equals(Long.TYPE)) {
- return Long.class;
- } else if (c.equals(Integer.TYPE)) {
- return Integer.class;
- } else if (c.equals(Double.TYPE)) {
- return Double.class;
- } else if (c.equals(Float.TYPE)) {
- return Float.class;
- } else if (c.equals(Boolean.TYPE)) {
- return Boolean.class;
- } else if (c.equals(Character.TYPE)) {
- return Character.class;
- } else if (c.equals(Short.TYPE)) {
- return Short.class;
- } else if (c.equals(Byte.TYPE)) {
- return Byte.class;
- }
- }
- return c;
- }
}
diff --git a/src/dorkbox/util/serialization/EccPrivateKeySerializer.java b/src/dorkbox/util/serialization/EccPrivateKeySerializer.java
index 30bbc31..ec0bc0b 100644
--- a/src/dorkbox/util/serialization/EccPrivateKeySerializer.java
+++ b/src/dorkbox/util/serialization/EccPrivateKeySerializer.java
@@ -15,11 +15,8 @@
*/
package dorkbox.util.serialization;
-import com.esotericsoftware.kryo.Kryo;
-import com.esotericsoftware.kryo.Serializer;
-import com.esotericsoftware.kryo.io.Input;
-import com.esotericsoftware.kryo.io.Output;
-import com.esotericsoftware.reflectasm.FieldAccess;
+import java.math.BigInteger;
+
import org.bouncycastle.asn1.ASN1ObjectIdentifier;
import org.bouncycastle.asn1.x9.X9ECParameters;
import org.bouncycastle.crypto.ec.CustomNamedCurves;
@@ -28,7 +25,11 @@ import org.bouncycastle.crypto.params.ECPrivateKeyParameters;
import org.bouncycastle.math.ec.ECCurve;
import org.bouncycastle.math.ec.ECPoint;
-import java.math.BigInteger;
+import com.esotericsoftware.kryo.Kryo;
+import com.esotericsoftware.kryo.Serializer;
+import com.esotericsoftware.kryo.io.Input;
+import com.esotericsoftware.kryo.io.Output;
+import com.esotericsoftware.reflectasm.FieldAccess;
/**
* Only public keys are ever sent across the wire.
diff --git a/src/dorkbox/util/serialization/EccPublicKeySerializer.java b/src/dorkbox/util/serialization/EccPublicKeySerializer.java
index aa42408..abcead2 100644
--- a/src/dorkbox/util/serialization/EccPublicKeySerializer.java
+++ b/src/dorkbox/util/serialization/EccPublicKeySerializer.java
@@ -15,16 +15,17 @@
*/
package dorkbox.util.serialization;
-import com.esotericsoftware.kryo.Kryo;
-import com.esotericsoftware.kryo.Serializer;
-import com.esotericsoftware.kryo.io.Input;
-import com.esotericsoftware.kryo.io.Output;
+import java.math.BigInteger;
+
import org.bouncycastle.crypto.params.ECDomainParameters;
import org.bouncycastle.crypto.params.ECPublicKeyParameters;
import org.bouncycastle.math.ec.ECCurve;
import org.bouncycastle.math.ec.ECPoint;
-import java.math.BigInteger;
+import com.esotericsoftware.kryo.Kryo;
+import com.esotericsoftware.kryo.Serializer;
+import com.esotericsoftware.kryo.io.Input;
+import com.esotericsoftware.kryo.io.Output;
/**
* Only public keys are ever sent across the wire.
diff --git a/src/dorkbox/util/serialization/FieldAnnotationAwareSerializer.java b/src/dorkbox/util/serialization/FieldAnnotationAwareSerializer.java
index c6ef7d4..89767cc 100644
--- a/src/dorkbox/util/serialization/FieldAnnotationAwareSerializer.java
+++ b/src/dorkbox/util/serialization/FieldAnnotationAwareSerializer.java
@@ -16,17 +16,17 @@
*/
package dorkbox.util.serialization;
-import com.esotericsoftware.kryo.Kryo;
-import com.esotericsoftware.kryo.Serializer;
-import com.esotericsoftware.kryo.factories.SerializerFactory;
-import com.esotericsoftware.kryo.serializers.FieldSerializer;
-
import java.lang.annotation.Annotation;
import java.lang.reflect.Field;
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
+import com.esotericsoftware.kryo.Kryo;
+import com.esotericsoftware.kryo.Serializer;
+import com.esotericsoftware.kryo.factories.SerializerFactory;
+import com.esotericsoftware.kryo.serializers.FieldSerializer;
+
/**
* A kryo {@link FieldSerializer} that allows to exclusively include or exclude fields that
* are attributed with user-specific annotations. This can be for example useful when serializing beans that carry
@@ -51,12 +51,14 @@ import java.util.Set;
* @author Rafael Winterhalter
* @author Martin Grotzke
*/
-public class FieldAnnotationAwareSerializer extends FieldSerializer {
+public
+class FieldAnnotationAwareSerializer extends FieldSerializer {
/**
* A factory for creating instances of {@link FieldAnnotationAwareSerializer}.
*/
- public static class Factory implements SerializerFactory {
+ public static
+ class Factory implements SerializerFactory {
private final Collection> marked;
private final boolean disregarding;
@@ -66,21 +68,24 @@ public class FieldAnnotationAwareSerializer extends FieldSerializer {
*com.esotericsoftware.kryo.Kryo, Class, java.util.Collection, boolean)}
* for additional information on the constructor parameters.
*
- * @param marked The annotations that will be considered of the resulting converter.
+ * @param marked The annotations that will be considered of the resulting converter.
* @param disregarding If {@code true}, the serializer will ignore all annotated fields,
- * if set to {@code false} it will exclusively look at annotated fields.
+ * if set to {@code false} it will exclusively look at annotated fields.
*/
- public Factory(final Collection> marked, final boolean disregarding) {
+ public
+ Factory(final Collection> marked, final boolean disregarding) {
this.marked = marked;
this.disregarding = disregarding;
}
@Override
- public Serializer> makeSerializer(final Kryo kryo, final Class> type) {
+ public
+ Serializer> makeSerializer(final Kryo kryo, final Class> type) {
return new FieldAnnotationAwareSerializer