polygene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From paulmer...@apache.org
Subject [46/48] polygene-java git commit: Factorize java serialization fallback
Date Mon, 13 Mar 2017 15:29:09 GMT
Factorize java serialization fallback

POLYGENE-231


Project: http://git-wip-us.apache.org/repos/asf/polygene-java/repo
Commit: http://git-wip-us.apache.org/repos/asf/polygene-java/commit/3f3cb4a0
Tree: http://git-wip-us.apache.org/repos/asf/polygene-java/tree/3f3cb4a0
Diff: http://git-wip-us.apache.org/repos/asf/polygene-java/diff/3f3cb4a0

Branch: refs/heads/serialization-3.0
Commit: 3f3cb4a0fd03e82d7112f51fa5fe271ed74b13cd
Parents: 70b2871
Author: Paul Merlin <paulmerlin@apache.org>
Authored: Mon Mar 13 15:18:32 2017 +0100
Committer: Paul Merlin <paulmerlin@apache.org>
Committed: Mon Mar 13 16:27:47 2017 +0100

----------------------------------------------------------------------
 .../javaxjson/JavaxJsonDeserializer.java         | 15 ---------------
 .../javaxjson/JavaxJsonSerializer.java           | 19 -------------------
 .../spi/serialization/AbstractDeserializer.java  | 15 +++++++++++++++
 .../spi/serialization/AbstractSerializer.java    | 18 ++++++++++++++++++
 .../javaxxml/JavaxXmlDeserializer.java           | 15 ---------------
 .../javaxxml/JavaxXmlSerializer.java             | 18 ------------------
 .../msgpack/MessagePackDeserializer.java         | 14 --------------
 .../msgpack/MessagePackSerializer.java           | 17 -----------------
 8 files changed, 33 insertions(+), 98 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/polygene-java/blob/3f3cb4a0/core/spi/src/main/java/org/apache/polygene/serialization/javaxjson/JavaxJsonDeserializer.java
----------------------------------------------------------------------
diff --git a/core/spi/src/main/java/org/apache/polygene/serialization/javaxjson/JavaxJsonDeserializer.java
b/core/spi/src/main/java/org/apache/polygene/serialization/javaxjson/JavaxJsonDeserializer.java
index 2d8cc53..4eb7a69 100644
--- a/core/spi/src/main/java/org/apache/polygene/serialization/javaxjson/JavaxJsonDeserializer.java
+++ b/core/spi/src/main/java/org/apache/polygene/serialization/javaxjson/JavaxJsonDeserializer.java
@@ -17,9 +17,6 @@
  */
 package org.apache.polygene.serialization.javaxjson;
 
-import java.io.ByteArrayInputStream;
-import java.io.IOException;
-import java.io.ObjectInputStream;
 import java.lang.reflect.Array;
 import java.util.AbstractMap;
 import java.util.ArrayList;
@@ -286,18 +283,6 @@ public class JavaxJsonDeserializer extends AbstractTextDeserializer implements
J
         };
     }
 
-    private Object deserializeJava( byte[] bytes )
-    {
-        try( ObjectInputStream oin = new ObjectInputStream( new ByteArrayInputStream( bytes
) ) )
-        {
-            return oin.readObject();
-        }
-        catch( IOException | ClassNotFoundException ex )
-        {
-            throw new SerializationException( "Unable to deserialize using Java serialization",
ex );
-        }
-    }
-
     private String getTypeInfoPropertyName()
     {
         return JavaxJsonSettings.orDefault( descriptor.metaInfo( JavaxJsonSettings.class
) )

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/3f3cb4a0/core/spi/src/main/java/org/apache/polygene/serialization/javaxjson/JavaxJsonSerializer.java
----------------------------------------------------------------------
diff --git a/core/spi/src/main/java/org/apache/polygene/serialization/javaxjson/JavaxJsonSerializer.java
b/core/spi/src/main/java/org/apache/polygene/serialization/javaxjson/JavaxJsonSerializer.java
index 93a9077..3bf8e1e 100644
--- a/core/spi/src/main/java/org/apache/polygene/serialization/javaxjson/JavaxJsonSerializer.java
+++ b/core/spi/src/main/java/org/apache/polygene/serialization/javaxjson/JavaxJsonSerializer.java
@@ -17,9 +17,6 @@
  */
 package org.apache.polygene.serialization.javaxjson;
 
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.ObjectOutputStream;
 import java.util.Base64;
 import java.util.Map;
 import java.util.function.Function;
@@ -39,7 +36,6 @@ import org.apache.polygene.api.injection.scope.This;
 import org.apache.polygene.api.injection.scope.Uses;
 import org.apache.polygene.api.serialization.Converter;
 import org.apache.polygene.api.serialization.Converters;
-import org.apache.polygene.api.serialization.SerializationException;
 import org.apache.polygene.api.service.ServiceDescriptor;
 import org.apache.polygene.api.type.ArrayType;
 import org.apache.polygene.api.type.MapType;
@@ -218,21 +214,6 @@ public class JavaxJsonSerializer extends AbstractTextSerializer implements
JsonS
         return builder.build();
     }
 
-    private byte[] serializeJava( Object object )
-    {
-        ByteArrayOutputStream bout = new ByteArrayOutputStream();
-        try( ObjectOutputStream out = new ObjectOutputStream( bout ) )
-        {
-            out.writeUnshared( object );
-            out.flush();
-            return bout.toByteArray();
-        }
-        catch( IOException ex )
-        {
-            throw new SerializationException( "Unable to serialize using Java serialization",
ex );
-        }
-    }
-
     private String getTypeInfoPropertyName()
     {
         return JavaxJsonSettings.orDefault( descriptor.metaInfo( JavaxJsonSettings.class
) )

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/3f3cb4a0/core/spi/src/main/java/org/apache/polygene/spi/serialization/AbstractDeserializer.java
----------------------------------------------------------------------
diff --git a/core/spi/src/main/java/org/apache/polygene/spi/serialization/AbstractDeserializer.java
b/core/spi/src/main/java/org/apache/polygene/spi/serialization/AbstractDeserializer.java
index b373160..4edd044 100644
--- a/core/spi/src/main/java/org/apache/polygene/spi/serialization/AbstractDeserializer.java
+++ b/core/spi/src/main/java/org/apache/polygene/spi/serialization/AbstractDeserializer.java
@@ -18,7 +18,9 @@
 package org.apache.polygene.spi.serialization;
 
 import java.io.ByteArrayInputStream;
+import java.io.IOException;
 import java.io.InputStream;
+import java.io.ObjectInputStream;
 import java.io.Reader;
 import java.io.StringReader;
 import java.util.function.Function;
@@ -26,6 +28,7 @@ import java.util.stream.Stream;
 import java.util.stream.StreamSupport;
 import org.apache.polygene.api.entity.EntityReference;
 import org.apache.polygene.api.serialization.Deserializer;
+import org.apache.polygene.api.serialization.SerializationException;
 import org.apache.polygene.api.structure.ModuleDescriptor;
 import org.apache.polygene.api.type.CollectionType;
 import org.apache.polygene.api.type.MapType;
@@ -159,4 +162,16 @@ public abstract class AbstractDeserializer implements Deserializer
         // TODO Remove (ModuleSpi) cast
         return ( (ModuleSpi) module.instance() ).valueTypeFactory().valueTypeOf( module,
type );
     }
+
+    protected Object deserializeJava( byte[] bytes )
+    {
+        try( ObjectInputStream oin = new ObjectInputStream( new ByteArrayInputStream( bytes
) ) )
+        {
+            return oin.readObject();
+        }
+        catch( IOException | ClassNotFoundException ex )
+        {
+            throw new SerializationException( "Unable to deserialize using Java serialization",
ex );
+        }
+    }
 }

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/3f3cb4a0/core/spi/src/main/java/org/apache/polygene/spi/serialization/AbstractSerializer.java
----------------------------------------------------------------------
diff --git a/core/spi/src/main/java/org/apache/polygene/spi/serialization/AbstractSerializer.java
b/core/spi/src/main/java/org/apache/polygene/spi/serialization/AbstractSerializer.java
index 3269adb..4db3548 100644
--- a/core/spi/src/main/java/org/apache/polygene/spi/serialization/AbstractSerializer.java
+++ b/core/spi/src/main/java/org/apache/polygene/spi/serialization/AbstractSerializer.java
@@ -18,6 +18,8 @@
 package org.apache.polygene.spi.serialization;
 
 import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.ObjectOutputStream;
 import java.io.OutputStream;
 import java.io.StringWriter;
 import java.io.Writer;
@@ -25,6 +27,7 @@ import java.util.function.Function;
 import java.util.stream.Stream;
 import java.util.stream.StreamSupport;
 import org.apache.polygene.api.common.Optional;
+import org.apache.polygene.api.serialization.SerializationException;
 import org.apache.polygene.api.serialization.Serializer;
 
 /**
@@ -151,4 +154,19 @@ public abstract class AbstractSerializer implements Serializer
     {
         return Stream.of( objects ).map( object -> toBytes( Options.DEFAULT, object )
);
     }
+
+    protected byte[] serializeJava( Object object )
+    {
+        ByteArrayOutputStream bout = new ByteArrayOutputStream();
+        try( ObjectOutputStream out = new ObjectOutputStream( bout ) )
+        {
+            out.writeUnshared( object );
+            out.flush();
+            return bout.toByteArray();
+        }
+        catch( IOException ex )
+        {
+            throw new SerializationException( "Unable to serialize using Java serialization",
ex );
+        }
+    }
 }

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/3f3cb4a0/extensions/serialization-javaxxml/src/main/java/org/apache/polygene/serialization/javaxxml/JavaxXmlDeserializer.java
----------------------------------------------------------------------
diff --git a/extensions/serialization-javaxxml/src/main/java/org/apache/polygene/serialization/javaxxml/JavaxXmlDeserializer.java
b/extensions/serialization-javaxxml/src/main/java/org/apache/polygene/serialization/javaxxml/JavaxXmlDeserializer.java
index 146d763..95da377 100644
--- a/extensions/serialization-javaxxml/src/main/java/org/apache/polygene/serialization/javaxxml/JavaxXmlDeserializer.java
+++ b/extensions/serialization-javaxxml/src/main/java/org/apache/polygene/serialization/javaxxml/JavaxXmlDeserializer.java
@@ -17,9 +17,6 @@
  */
 package org.apache.polygene.serialization.javaxxml;
 
-import java.io.ByteArrayInputStream;
-import java.io.IOException;
-import java.io.ObjectInputStream;
 import java.lang.reflect.Array;
 import java.util.ArrayList;
 import java.util.Base64;
@@ -321,18 +318,6 @@ public class JavaxXmlDeserializer extends AbstractTextDeserializer implements
Xm
         throw new SerializationException( "Don't know how to deserialize " + valueType +
" from " + xml );
     }
 
-    private Object deserializeJava( byte[] bytes )
-    {
-        try( ObjectInputStream oin = new ObjectInputStream( new ByteArrayInputStream( bytes
) ) )
-        {
-            return oin.readObject();
-        }
-        catch( IOException | ClassNotFoundException ex )
-        {
-            throw new SerializationException( "Unable to deserialize using Java serialization",
ex );
-        }
-    }
-
     private Optional<String> getTypeInfo( Node xml )
     {
         if( xml.getNodeType() != Node.ELEMENT_NODE )

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/3f3cb4a0/extensions/serialization-javaxxml/src/main/java/org/apache/polygene/serialization/javaxxml/JavaxXmlSerializer.java
----------------------------------------------------------------------
diff --git a/extensions/serialization-javaxxml/src/main/java/org/apache/polygene/serialization/javaxxml/JavaxXmlSerializer.java
b/extensions/serialization-javaxxml/src/main/java/org/apache/polygene/serialization/javaxxml/JavaxXmlSerializer.java
index 576647b..3c49699 100644
--- a/extensions/serialization-javaxxml/src/main/java/org/apache/polygene/serialization/javaxxml/JavaxXmlSerializer.java
+++ b/extensions/serialization-javaxxml/src/main/java/org/apache/polygene/serialization/javaxxml/JavaxXmlSerializer.java
@@ -17,9 +17,6 @@
  */
 package org.apache.polygene.serialization.javaxxml;
 
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.ObjectOutputStream;
 import java.util.Base64;
 import java.util.Map;
 import java.util.function.Function;
@@ -279,21 +276,6 @@ public class JavaxXmlSerializer extends AbstractTextSerializer implements
XmlSer
         return collectionElement;
     }
 
-    private byte[] serializeJava( Object object )
-    {
-        ByteArrayOutputStream bout = new ByteArrayOutputStream();
-        try( ObjectOutputStream out = new ObjectOutputStream( bout ) )
-        {
-            out.writeUnshared( object );
-            out.flush();
-            return bout.toByteArray();
-        }
-        catch( IOException ex )
-        {
-            throw new SerializationException( "Unable to serialize using Java serialization",
ex );
-        }
-    }
-
     private JavaxXmlSettings getSettings()
     {
         return JavaxXmlSettings.orDefault( descriptor.metaInfo( JavaxXmlSettings.class )
);

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/3f3cb4a0/extensions/serialization-msgpack/src/main/java/org/apache/polygene/serialization/msgpack/MessagePackDeserializer.java
----------------------------------------------------------------------
diff --git a/extensions/serialization-msgpack/src/main/java/org/apache/polygene/serialization/msgpack/MessagePackDeserializer.java
b/extensions/serialization-msgpack/src/main/java/org/apache/polygene/serialization/msgpack/MessagePackDeserializer.java
index 9d5c9df..9afe450 100644
--- a/extensions/serialization-msgpack/src/main/java/org/apache/polygene/serialization/msgpack/MessagePackDeserializer.java
+++ b/extensions/serialization-msgpack/src/main/java/org/apache/polygene/serialization/msgpack/MessagePackDeserializer.java
@@ -17,10 +17,8 @@
  */
 package org.apache.polygene.serialization.msgpack;
 
-import java.io.ByteArrayInputStream;
 import java.io.IOException;
 import java.io.InputStream;
-import java.io.ObjectInputStream;
 import java.lang.reflect.Array;
 import java.util.AbstractMap;
 import java.util.ArrayList;
@@ -311,17 +309,5 @@ public interface MessagePackDeserializer extends Deserializer
                                                       + " (" + value.getValueType() + ")"
);
             }
         }
-
-        private Object deserializeJava( byte[] bytes )
-        {
-            try( ObjectInputStream oin = new ObjectInputStream( new ByteArrayInputStream(
bytes ) ) )
-            {
-                return oin.readObject();
-            }
-            catch( IOException | ClassNotFoundException ex )
-            {
-                throw new SerializationException( "Unable to deserialize using Java serialization",
ex );
-            }
-        }
     }
 }

http://git-wip-us.apache.org/repos/asf/polygene-java/blob/3f3cb4a0/extensions/serialization-msgpack/src/main/java/org/apache/polygene/serialization/msgpack/MessagePackSerializer.java
----------------------------------------------------------------------
diff --git a/extensions/serialization-msgpack/src/main/java/org/apache/polygene/serialization/msgpack/MessagePackSerializer.java
b/extensions/serialization-msgpack/src/main/java/org/apache/polygene/serialization/msgpack/MessagePackSerializer.java
index ea66ad0..cdbbf5a 100644
--- a/extensions/serialization-msgpack/src/main/java/org/apache/polygene/serialization/msgpack/MessagePackSerializer.java
+++ b/extensions/serialization-msgpack/src/main/java/org/apache/polygene/serialization/msgpack/MessagePackSerializer.java
@@ -17,9 +17,7 @@
  */
 package org.apache.polygene.serialization.msgpack;
 
-import java.io.ByteArrayOutputStream;
 import java.io.IOException;
-import java.io.ObjectOutputStream;
 import java.io.OutputStream;
 import java.util.Map;
 import java.util.stream.Stream;
@@ -200,20 +198,5 @@ public interface MessagePackSerializer extends Serializer
             return ValueFactory.newArray( stream.map( element -> doSerialize( options,
element, false ) )
                                                 .collect( toList() ) );
         }
-
-        private byte[] serializeJava( Object object )
-        {
-            ByteArrayOutputStream bout = new ByteArrayOutputStream();
-            try( ObjectOutputStream out = new ObjectOutputStream( bout ) )
-            {
-                out.writeUnshared( object );
-                out.flush();
-                return bout.toByteArray();
-            }
-            catch( IOException ex )
-            {
-                throw new SerializationException( "Unable to serialize using Java serialization",
ex );
-            }
-        }
     }
 }


Mime
View raw message