You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directmemory.apache.org by ol...@apache.org on 2012/10/01 22:57:52 UTC
svn commit: r1392595 [7/15] - in /directmemory/lightning/trunk: ./
lightning-api/ lightning-api/src/ lightning-api/src/main/
lightning-api/src/main/java/ lightning-api/src/main/java/org/
lightning-api/src/main/java/org/apache/ lightning-api/src/main/ja...
Added: directmemory/lightning/trunk/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/instantiator/perc/PercSerializationInstantiator.java
URL: http://svn.apache.org/viewvc/directmemory/lightning/trunk/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/instantiator/perc/PercSerializationInstantiator.java?rev=1392595&view=auto
==============================================================================
--- directmemory/lightning/trunk/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/instantiator/perc/PercSerializationInstantiator.java (added)
+++ directmemory/lightning/trunk/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/instantiator/perc/PercSerializationInstantiator.java Mon Oct 1 20:57:42 2012
@@ -0,0 +1,113 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.directmemory.lightning.internal.instantiator.perc;
+
+import java.io.ObjectInputStream;
+import java.io.Serializable;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+
+import org.apache.directmemory.lightning.instantiator.ObjectInstantiator;
+import org.apache.directmemory.lightning.internal.instantiator.ObjenesisException;
+
+/**
+ * Instantiates a class by making a call to internal Perc private methods. It is only supposed to work on Perc JVMs.
+ * This instantiator will create classes in a way compatible with serialization, calling the first non-serializable
+ * superclass' no-arg constructor.
+ * <p/>
+ * Based on code provided by Aonix but <b>doesn't work right now</b>
+ *
+ * @author Henri Tremblay
+ * @see org.apache.directmemory.lightning.instantiator.ObjectInstantiator
+ */
+public class PercSerializationInstantiator
+ implements ObjectInstantiator
+{
+
+ private Object[] typeArgs;
+
+ private final java.lang.reflect.Method newInstanceMethod;
+
+ public PercSerializationInstantiator( Class<?> type )
+ {
+
+ // Find the first unserializable parent class
+ Class<?> unserializableType = type;
+
+ while ( Serializable.class.isAssignableFrom( unserializableType ) )
+ {
+ unserializableType = unserializableType.getSuperclass();
+ }
+
+ try
+ {
+ // Get the special Perc method to call
+ Class<?> percMethodClass = Class.forName( "COM.newmonics.PercClassLoader.Method" );
+
+ newInstanceMethod =
+ ObjectInputStream.class.getDeclaredMethod( "noArgConstruct", new Class[] { Class.class, Object.class,
+ percMethodClass } );
+ newInstanceMethod.setAccessible( true );
+
+ // Create invoke params
+ Class<?> percClassClass = Class.forName( "COM.newmonics.PercClassLoader.PercClass" );
+ Method getPercClassMethod = percClassClass.getDeclaredMethod( "getPercClass", new Class[] { Class.class } );
+ Object someObject = getPercClassMethod.invoke( null, new Object[] { unserializableType } );
+ Method findMethodMethod =
+ someObject.getClass().getDeclaredMethod( "findMethod", new Class[] { String.class } );
+ Object percMethod = findMethodMethod.invoke( someObject, new Object[] { "<init>()V" } );
+
+ typeArgs = new Object[] { unserializableType, type, percMethod };
+
+ }
+ catch ( ClassNotFoundException e )
+ {
+ throw new ObjenesisException( e );
+ }
+ catch ( NoSuchMethodException e )
+ {
+ throw new ObjenesisException( e );
+ }
+ catch ( InvocationTargetException e )
+ {
+ throw new ObjenesisException( e );
+ }
+ catch ( IllegalAccessException e )
+ {
+ throw new ObjenesisException( e );
+ }
+ }
+
+ @Override
+ public Object newInstance()
+ {
+ try
+ {
+ return newInstanceMethod.invoke( null, typeArgs );
+ }
+ catch ( IllegalAccessException e )
+ {
+ throw new ObjenesisException( e );
+ }
+ catch ( InvocationTargetException e )
+ {
+ throw new ObjenesisException( e );
+ }
+ }
+}
Propchange: directmemory/lightning/trunk/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/instantiator/perc/PercSerializationInstantiator.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: directmemory/lightning/trunk/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/instantiator/perc/PercSerializationInstantiator.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: directmemory/lightning/trunk/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/instantiator/strategy/BaseInstantiatorStrategy.java
URL: http://svn.apache.org/viewvc/directmemory/lightning/trunk/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/instantiator/strategy/BaseInstantiatorStrategy.java?rev=1392595&view=auto
==============================================================================
--- directmemory/lightning/trunk/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/instantiator/strategy/BaseInstantiatorStrategy.java (added)
+++ directmemory/lightning/trunk/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/instantiator/strategy/BaseInstantiatorStrategy.java Mon Oct 1 20:57:42 2012
@@ -0,0 +1,59 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.directmemory.lightning.internal.instantiator.strategy;
+
+/**
+ * Base {@link InstantiatorStrategy} class basically containing helpful constant to sort out JVMs.
+ *
+ * @author Henri Tremblay
+ */
+public abstract class BaseInstantiatorStrategy
+ implements InstantiatorStrategy
+{
+
+ /** JVM_NAME prefix for BEA releases of JRockit */
+ protected static final String BEA_JROCKIT = "BEA";
+
+ /** JVM_NAME prefix for Oracle releases of JRockit */
+ protected static final String ORACLE_JROCKIT = "Oracle JRockit(R)";
+
+ /** JVM_NAME prefix for GCJ */
+ protected static final String GNU = "GNU libgcj";
+
+ /** JVM_NAME prefix for Sun Java HotSpot */
+ protected static final String SUN = "Java HotSpot";
+
+ /** JVM_NAME prefix for Aonix PERC */
+ protected static final String PERC = "PERC";
+
+ /** JVM version */
+ protected static final String VM_VERSION = System.getProperty( "java.runtime.version" );
+
+ /** JVM version */
+ protected static final String VM_INFO = System.getProperty( "java.vm.info" );
+
+ /** Vendor version */
+ protected static final String VENDOR_VERSION = System.getProperty( "java.vm.version" );
+
+ /** Vendor name */
+ protected static final String VENDOR = System.getProperty( "java.vm.vendor" );
+
+ /** JVM name */
+ protected static final String JVM_NAME = System.getProperty( "java.vm.name" );
+}
Propchange: directmemory/lightning/trunk/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/instantiator/strategy/BaseInstantiatorStrategy.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: directmemory/lightning/trunk/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/instantiator/strategy/BaseInstantiatorStrategy.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: directmemory/lightning/trunk/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/instantiator/strategy/InstantiatorStrategy.java
URL: http://svn.apache.org/viewvc/directmemory/lightning/trunk/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/instantiator/strategy/InstantiatorStrategy.java?rev=1392595&view=auto
==============================================================================
--- directmemory/lightning/trunk/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/instantiator/strategy/InstantiatorStrategy.java (added)
+++ directmemory/lightning/trunk/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/instantiator/strategy/InstantiatorStrategy.java Mon Oct 1 20:57:42 2012
@@ -0,0 +1,38 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.directmemory.lightning.internal.instantiator.strategy;
+
+import org.apache.directmemory.lightning.instantiator.ObjectInstantiator;
+
+/**
+ * Defines a strategy to determine the best instantiator for a class.
+ *
+ * @author Henri Tremblay
+ */
+public interface InstantiatorStrategy
+{
+
+ /**
+ * Create a dedicated instantiator for the given class
+ *
+ * @param type Class that will be instantiate
+ * @return Dedicated instantiator
+ */
+ ObjectInstantiator newInstantiatorOf( Class<?> type );
+}
Propchange: directmemory/lightning/trunk/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/instantiator/strategy/InstantiatorStrategy.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: directmemory/lightning/trunk/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/instantiator/strategy/InstantiatorStrategy.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: directmemory/lightning/trunk/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/instantiator/strategy/SerializingInstantiatorStrategy.java
URL: http://svn.apache.org/viewvc/directmemory/lightning/trunk/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/instantiator/strategy/SerializingInstantiatorStrategy.java?rev=1392595&view=auto
==============================================================================
--- directmemory/lightning/trunk/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/instantiator/strategy/SerializingInstantiatorStrategy.java (added)
+++ directmemory/lightning/trunk/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/instantiator/strategy/SerializingInstantiatorStrategy.java Mon Oct 1 20:57:42 2012
@@ -0,0 +1,78 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.directmemory.lightning.internal.instantiator.strategy;
+
+import org.apache.directmemory.lightning.instantiator.ObjectInstantiator;
+import org.apache.directmemory.lightning.internal.instantiator.basic.ObjectStreamClassInstantiator;
+import org.apache.directmemory.lightning.internal.instantiator.gcj.GCJSerializationInstantiator;
+import org.apache.directmemory.lightning.internal.instantiator.perc.PercSerializationInstantiator;
+import org.apache.directmemory.lightning.internal.instantiator.sun.Sun13SerializationInstantiator;
+import org.apache.directmemory.lightning.internal.util.InternalUtil;
+
+/**
+ * Guess the best serializing instantiator for a given class. The returned instantiator will instantiate classes like
+ * the genuine java serialization framework (the constructor of the first not serializable class will be called).
+ * Currently, the selection doesn't depend on the class. It relies on the
+ * <ul>
+ * <li>JVM version</li>
+ * <li>JVM vendor</li>
+ * <li>JVM vendor version</li>
+ * </ul>
+ * However, instantiators are stateful and so dedicated to their class.
+ *
+ * @author Henri Tremblay
+ * @see ObjectInstantiator
+ */
+public class SerializingInstantiatorStrategy
+ extends BaseInstantiatorStrategy
+{
+
+ /**
+ * Return an {@link ObjectInstantiator} allowing to create instance following the java serialization framework
+ * specifications.
+ *
+ * @param type Class to instantiate
+ * @return The ObjectInstantiator for the class
+ */
+ @Override
+ public ObjectInstantiator newInstantiatorOf( Class<?> type )
+ {
+ if ( JVM_NAME.startsWith( SUN ) )
+ {
+ if ( VM_VERSION.startsWith( "1.3" ) )
+ {
+ return new Sun13SerializationInstantiator( type );
+ }
+ else if ( InternalUtil.isUnsafeAvailable() )
+ {
+ return InternalUtil.buildSunUnsafeInstantiator( type );
+ }
+ }
+ else if ( JVM_NAME.startsWith( GNU ) )
+ {
+ return new GCJSerializationInstantiator( type );
+ }
+ else if ( JVM_NAME.startsWith( PERC ) )
+ {
+ return new PercSerializationInstantiator( type );
+ }
+
+ return new ObjectStreamClassInstantiator( type );
+ }
+}
Propchange: directmemory/lightning/trunk/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/instantiator/strategy/SerializingInstantiatorStrategy.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: directmemory/lightning/trunk/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/instantiator/strategy/SerializingInstantiatorStrategy.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: directmemory/lightning/trunk/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/instantiator/strategy/StdInstantiatorStrategy.java
URL: http://svn.apache.org/viewvc/directmemory/lightning/trunk/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/instantiator/strategy/StdInstantiatorStrategy.java?rev=1392595&view=auto
==============================================================================
--- directmemory/lightning/trunk/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/instantiator/strategy/StdInstantiatorStrategy.java (added)
+++ directmemory/lightning/trunk/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/instantiator/strategy/StdInstantiatorStrategy.java Mon Oct 1 20:57:42 2012
@@ -0,0 +1,93 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.directmemory.lightning.internal.instantiator.strategy;
+
+import org.apache.directmemory.lightning.instantiator.ObjectInstantiator;
+import org.apache.directmemory.lightning.internal.instantiator.gcj.GCJInstantiator;
+import org.apache.directmemory.lightning.internal.instantiator.perc.PercInstantiator;
+import org.apache.directmemory.lightning.internal.instantiator.sun.Sun13Instantiator;
+import org.apache.directmemory.lightning.internal.instantiator.sun.SunReflectionFactoryInstantiator;
+import org.apache.directmemory.lightning.internal.util.InternalUtil;
+
+/**
+ * Guess the best instantiator for a given class. The instantiator will instantiate the class without calling any
+ * constructor. Currently, the selection doesn't depend on the class. It relies on the
+ * <ul>
+ * <li>JVM version</li>
+ * <li>JVM vendor</li>
+ * <li>JVM vendor version</li>
+ * </ul>
+ * However, instantiators are stateful and so dedicated to their class.
+ *
+ * @author Henri Tremblay
+ * @see ObjectInstantiator
+ */
+public class StdInstantiatorStrategy
+ extends BaseInstantiatorStrategy
+{
+
+ /**
+ * Return an {@link ObjectInstantiator} allowing to create instance without any constructor being called.
+ *
+ * @param type Class to instantiate
+ * @return The ObjectInstantiator for the class
+ */
+ @Override
+ public ObjectInstantiator newInstantiatorOf( Class<?> type )
+ {
+
+ if ( JVM_NAME.startsWith( SUN ) )
+ {
+ if ( VM_VERSION.startsWith( "1.3" ) )
+ {
+ return new Sun13Instantiator( type );
+ }
+ else if ( InternalUtil.isUnsafeAvailable() )
+ {
+ return InternalUtil.buildSunUnsafeInstantiator( type );
+ }
+ }
+ else if ( JVM_NAME.startsWith( ORACLE_JROCKIT ) )
+ {
+ if ( !VENDOR_VERSION.startsWith( "R" ) )
+ {
+ // Beginning with R25.1 sun.misc.Unsafe should work.
+ if ( InternalUtil.isUnsafeAvailable() )
+ {
+ return InternalUtil.buildSunUnsafeInstantiator( type );
+ }
+ }
+ }
+ else if ( JVM_NAME.startsWith( GNU ) )
+ {
+ return new GCJInstantiator( type );
+ }
+ else if ( JVM_NAME.startsWith( PERC ) )
+ {
+ return new PercInstantiator( type );
+ }
+
+ // Fallback instantiator, should work with:
+ // - Java Hotspot version 1.4 and higher
+ // - JRockit 1.4-R26 and higher
+ // - IBM and Hitachi JVMs
+ // ... might works for others so we just give it a try
+ return new SunReflectionFactoryInstantiator( type );
+ }
+}
Propchange: directmemory/lightning/trunk/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/instantiator/strategy/StdInstantiatorStrategy.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: directmemory/lightning/trunk/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/instantiator/strategy/StdInstantiatorStrategy.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: directmemory/lightning/trunk/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/instantiator/sun/Sun13Instantiator.java
URL: http://svn.apache.org/viewvc/directmemory/lightning/trunk/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/instantiator/sun/Sun13Instantiator.java?rev=1392595&view=auto
==============================================================================
--- directmemory/lightning/trunk/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/instantiator/sun/Sun13Instantiator.java (added)
+++ directmemory/lightning/trunk/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/instantiator/sun/Sun13Instantiator.java Mon Oct 1 20:57:42 2012
@@ -0,0 +1,61 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.directmemory.lightning.internal.instantiator.sun;
+
+import java.lang.reflect.InvocationTargetException;
+
+import org.apache.directmemory.lightning.internal.instantiator.ObjenesisException;
+
+/**
+ * Instantiates a class by making a call to internal Sun private methods. It is only supposed to work on Sun HotSpot 1.3
+ * JVM. This instantiator will not call any constructors.
+ *
+ * @author Leonardo Mesquita
+ * @see org.apache.directmemory.lightning.instantiator.ObjectInstantiator
+ */
+public class Sun13Instantiator
+ extends Sun13InstantiatorBase
+{
+
+ public Sun13Instantiator( Class<?> type )
+ {
+ super( type );
+ }
+
+ @Override
+ public Object newInstance()
+ {
+ try
+ {
+ return allocateNewObjectMethod.invoke( null, new Object[] { type, Object.class } );
+ }
+ catch ( RuntimeException e )
+ {
+ throw new ObjenesisException( e );
+ }
+ catch ( IllegalAccessException e )
+ {
+ throw new ObjenesisException( e );
+ }
+ catch ( InvocationTargetException e )
+ {
+ throw new ObjenesisException( e );
+ }
+ }
+}
Propchange: directmemory/lightning/trunk/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/instantiator/sun/Sun13Instantiator.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: directmemory/lightning/trunk/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/instantiator/sun/Sun13Instantiator.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: directmemory/lightning/trunk/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/instantiator/sun/Sun13InstantiatorBase.java
URL: http://svn.apache.org/viewvc/directmemory/lightning/trunk/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/instantiator/sun/Sun13InstantiatorBase.java?rev=1392595&view=auto
==============================================================================
--- directmemory/lightning/trunk/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/instantiator/sun/Sun13InstantiatorBase.java (added)
+++ directmemory/lightning/trunk/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/instantiator/sun/Sun13InstantiatorBase.java Mon Oct 1 20:57:42 2012
@@ -0,0 +1,72 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.directmemory.lightning.internal.instantiator.sun;
+
+import java.io.ObjectInputStream;
+import java.lang.reflect.Method;
+
+import org.apache.directmemory.lightning.instantiator.ObjectInstantiator;
+import org.apache.directmemory.lightning.internal.instantiator.ObjenesisException;
+
+/**
+ * Base class for Sun 1.3 based instantiators. It initializes reflection access to static method
+ * ObjectInputStream.allocateNewObject.
+ *
+ * @author Leonardo Mesquita
+ */
+public abstract class Sun13InstantiatorBase
+ implements ObjectInstantiator
+{
+
+ protected static Method allocateNewObjectMethod = null;
+
+ private static void initialize()
+ {
+ if ( allocateNewObjectMethod == null )
+ {
+ try
+ {
+ allocateNewObjectMethod =
+ ObjectInputStream.class.getDeclaredMethod( "allocateNewObject", new Class[] { Class.class,
+ Class.class } );
+ allocateNewObjectMethod.setAccessible( true );
+ }
+ catch ( RuntimeException e )
+ {
+ throw new ObjenesisException( e );
+ }
+ catch ( NoSuchMethodException e )
+ {
+ throw new ObjenesisException( e );
+ }
+ }
+ }
+
+ protected final Class<?> type;
+
+ public Sun13InstantiatorBase( Class<?> type )
+ {
+ this.type = type;
+ initialize();
+ }
+
+ @Override
+ public abstract Object newInstance();
+
+}
Propchange: directmemory/lightning/trunk/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/instantiator/sun/Sun13InstantiatorBase.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: directmemory/lightning/trunk/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/instantiator/sun/Sun13InstantiatorBase.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: directmemory/lightning/trunk/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/instantiator/sun/Sun13SerializationInstantiator.java
URL: http://svn.apache.org/viewvc/directmemory/lightning/trunk/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/instantiator/sun/Sun13SerializationInstantiator.java?rev=1392595&view=auto
==============================================================================
--- directmemory/lightning/trunk/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/instantiator/sun/Sun13SerializationInstantiator.java (added)
+++ directmemory/lightning/trunk/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/instantiator/sun/Sun13SerializationInstantiator.java Mon Oct 1 20:57:42 2012
@@ -0,0 +1,56 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.directmemory.lightning.internal.instantiator.sun;
+
+import org.apache.directmemory.lightning.internal.instantiator.ObjenesisException;
+import org.apache.directmemory.lightning.internal.instantiator.SerializationInstantiatorHelper;
+
+/**
+ * Instantiates a class by making a call to internal Sun private methods. It is only supposed to work on Sun HotSpot 1.3
+ * JVM. This instantiator will create classes in a way compatible with serialization, calling the first non-serializable
+ * superclass' no-arg constructor.
+ *
+ * @author Leonardo Mesquita
+ * @see org.apache.directmemory.lightning.instantiator.ObjectInstantiator
+ */
+public class Sun13SerializationInstantiator
+ extends Sun13InstantiatorBase
+{
+
+ private final Class<?> superType;
+
+ public Sun13SerializationInstantiator( Class<?> type )
+ {
+ super( type );
+ this.superType = SerializationInstantiatorHelper.getNonSerializableSuperClass( type );
+ }
+
+ @Override
+ public Object newInstance()
+ {
+ try
+ {
+ return allocateNewObjectMethod.invoke( null, new Object[] { type, superType } );
+ }
+ catch ( Exception e )
+ {
+ throw new ObjenesisException( e );
+ }
+ }
+}
Propchange: directmemory/lightning/trunk/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/instantiator/sun/Sun13SerializationInstantiator.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: directmemory/lightning/trunk/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/instantiator/sun/Sun13SerializationInstantiator.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: directmemory/lightning/trunk/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/instantiator/sun/SunReflectionFactoryInstantiator.java
URL: http://svn.apache.org/viewvc/directmemory/lightning/trunk/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/instantiator/sun/SunReflectionFactoryInstantiator.java?rev=1392595&view=auto
==============================================================================
--- directmemory/lightning/trunk/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/instantiator/sun/SunReflectionFactoryInstantiator.java (added)
+++ directmemory/lightning/trunk/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/instantiator/sun/SunReflectionFactoryInstantiator.java Mon Oct 1 20:57:42 2012
@@ -0,0 +1,73 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.directmemory.lightning.internal.instantiator.sun;
+
+import java.lang.reflect.Constructor;
+
+import org.apache.directmemory.lightning.instantiator.ObjectInstantiator;
+import org.apache.directmemory.lightning.internal.instantiator.ObjenesisException;
+
+import sun.reflect.ReflectionFactory;
+
+/**
+ * Instantiates an object, WITHOUT calling it's constructor, using internal sun.reflect.ReflectionFactory - a class only
+ * available on JDK's that use Sun's 1.4 (or later) Java implementation. This is the best way to instantiate an object
+ * without any side effects caused by the constructor - however it is not available on every platform.
+ *
+ * @author Joe Walnes
+ * @see ObjectInstantiator
+ */
+@SuppressWarnings( "restriction" )
+public class SunReflectionFactoryInstantiator
+ implements ObjectInstantiator
+{
+
+ private final Constructor<?> mungedConstructor;
+
+ public SunReflectionFactoryInstantiator( Class<?> type )
+ {
+
+ ReflectionFactory reflectionFactory = ReflectionFactory.getReflectionFactory();
+ Constructor<?> javaLangObjectConstructor;
+
+ try
+ {
+ javaLangObjectConstructor = Object.class.getConstructor( (Class[]) null );
+ }
+ catch ( NoSuchMethodException e )
+ {
+ throw new Error( "Cannot find constructor for java.lang.Object!" );
+ }
+ mungedConstructor = reflectionFactory.newConstructorForSerialization( type, javaLangObjectConstructor );
+ mungedConstructor.setAccessible( true );
+ }
+
+ @Override
+ public Object newInstance()
+ {
+ try
+ {
+ return mungedConstructor.newInstance( (Object[]) null );
+ }
+ catch ( Exception e )
+ {
+ throw new ObjenesisException( e );
+ }
+ }
+}
Propchange: directmemory/lightning/trunk/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/instantiator/sun/SunReflectionFactoryInstantiator.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: directmemory/lightning/trunk/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/instantiator/sun/SunReflectionFactoryInstantiator.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: directmemory/lightning/trunk/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/instantiator/sun/SunReflectionFactorySerializationInstantiator.java
URL: http://svn.apache.org/viewvc/directmemory/lightning/trunk/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/instantiator/sun/SunReflectionFactorySerializationInstantiator.java?rev=1392595&view=auto
==============================================================================
--- directmemory/lightning/trunk/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/instantiator/sun/SunReflectionFactorySerializationInstantiator.java (added)
+++ directmemory/lightning/trunk/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/instantiator/sun/SunReflectionFactorySerializationInstantiator.java Mon Oct 1 20:57:42 2012
@@ -0,0 +1,83 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.directmemory.lightning.internal.instantiator.sun;
+
+import java.io.NotSerializableException;
+import java.lang.reflect.Constructor;
+
+import org.apache.directmemory.lightning.instantiator.ObjectInstantiator;
+import org.apache.directmemory.lightning.internal.instantiator.ObjenesisException;
+import org.apache.directmemory.lightning.internal.instantiator.SerializationInstantiatorHelper;
+
+import sun.reflect.ReflectionFactory;
+
+/**
+ * Instantiates an object using internal sun.reflect.ReflectionFactory - a class only available on JDK's that use Sun's
+ * 1.4 (or later) Java implementation. This instantiator will create classes in a way compatible with serialization,
+ * calling the first non-serializable superclass' no-arg constructor. This is the best way to instantiate an object
+ * without any side effects caused by the constructor - however it is not available on every platform.
+ *
+ * @author Leonardo Mesquita
+ * @see ObjectInstantiator
+ */
+@SuppressWarnings( "restriction" )
+public class SunReflectionFactorySerializationInstantiator
+ implements ObjectInstantiator
+{
+
+ private final Constructor<?> mungedConstructor;
+
+ public SunReflectionFactorySerializationInstantiator( Class<?> type )
+ {
+
+ Class<?> nonSerializableAncestor = SerializationInstantiatorHelper.getNonSerializableSuperClass( type );
+ ReflectionFactory reflectionFactory = ReflectionFactory.getReflectionFactory();
+ Constructor<?> nonSerializableAncestorConstructor;
+ try
+ {
+ nonSerializableAncestorConstructor = nonSerializableAncestor.getConstructor( (Class[]) null );
+ }
+ catch ( NoSuchMethodException e )
+ {
+ /**
+ * @todo (Henri) I think we should throw a NotSerializableException just to put the same message a
+ * ObjectInputStream. Otherwise, the user won't know if the null returned if a "Not serializable", a
+ * "No default constructor on ancestor" or a "Exception in constructor"
+ */
+ throw new ObjenesisException( new NotSerializableException( type
+ + " has no suitable superclass constructor" ) );
+ }
+
+ mungedConstructor = reflectionFactory.newConstructorForSerialization( type, nonSerializableAncestorConstructor );
+ mungedConstructor.setAccessible( true );
+ }
+
+ @Override
+ public Object newInstance()
+ {
+ try
+ {
+ return mungedConstructor.newInstance( (Object[]) null );
+ }
+ catch ( Exception e )
+ {
+ throw new ObjenesisException( e );
+ }
+ }
+}
Propchange: directmemory/lightning/trunk/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/instantiator/sun/SunReflectionFactorySerializationInstantiator.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: directmemory/lightning/trunk/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/instantiator/sun/SunReflectionFactorySerializationInstantiator.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: directmemory/lightning/trunk/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/instantiator/sun/SunUnsafeAllocateInstanceInstantiator.java
URL: http://svn.apache.org/viewvc/directmemory/lightning/trunk/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/instantiator/sun/SunUnsafeAllocateInstanceInstantiator.java?rev=1392595&view=auto
==============================================================================
--- directmemory/lightning/trunk/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/instantiator/sun/SunUnsafeAllocateInstanceInstantiator.java (added)
+++ directmemory/lightning/trunk/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/instantiator/sun/SunUnsafeAllocateInstanceInstantiator.java Mon Oct 1 20:57:42 2012
@@ -0,0 +1,53 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.directmemory.lightning.internal.instantiator.sun;
+
+import org.apache.directmemory.lightning.instantiator.ObjectInstantiator;
+import org.apache.directmemory.lightning.internal.util.UnsafeUtil;
+
+@SuppressWarnings( "restriction" )
+public class SunUnsafeAllocateInstanceInstantiator
+ implements ObjectInstantiator
+{
+
+ private static final sun.misc.Unsafe UNSAFE = UnsafeUtil.getUnsafe();
+
+ protected final Class<?> type;
+
+ public SunUnsafeAllocateInstanceInstantiator( Class<?> type )
+ {
+ this.type = type;
+ }
+
+ @Override
+ public Object newInstance()
+ {
+ try
+ {
+ if ( UNSAFE != null )
+ return UNSAFE.allocateInstance( type );
+ }
+ catch ( Exception e )
+ {
+ // ignore and return null
+ }
+
+ return null;
+ }
+}
Propchange: directmemory/lightning/trunk/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/instantiator/sun/SunUnsafeAllocateInstanceInstantiator.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: directmemory/lightning/trunk/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/instantiator/sun/SunUnsafeAllocateInstanceInstantiator.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: directmemory/lightning/trunk/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/io/BufferInputStream.java
URL: http://svn.apache.org/viewvc/directmemory/lightning/trunk/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/io/BufferInputStream.java?rev=1392595&view=auto
==============================================================================
--- directmemory/lightning/trunk/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/io/BufferInputStream.java (added)
+++ directmemory/lightning/trunk/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/io/BufferInputStream.java Mon Oct 1 20:57:42 2012
@@ -0,0 +1,55 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.directmemory.lightning.internal.io;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.nio.ByteBuffer;
+
+public class BufferInputStream
+ extends InputStream
+{
+
+ private final ByteBuffer byteBuffer;
+
+ public BufferInputStream( ByteBuffer byteBuffer )
+ {
+ this.byteBuffer = byteBuffer;
+ }
+
+ @Override
+ public synchronized int read()
+ throws IOException
+ {
+ if ( !byteBuffer.hasRemaining() )
+ {
+ return -1;
+ }
+ return byteBuffer.get();
+ }
+
+ @Override
+ public synchronized int read( byte[] bytes, int off, int len )
+ throws IOException
+ {
+ len = Math.min( len, byteBuffer.remaining() );
+ byteBuffer.get( bytes, off, len );
+ return len;
+ }
+}
Propchange: directmemory/lightning/trunk/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/io/BufferInputStream.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: directmemory/lightning/trunk/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/io/BufferInputStream.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: directmemory/lightning/trunk/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/io/BufferOutputStream.java
URL: http://svn.apache.org/viewvc/directmemory/lightning/trunk/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/io/BufferOutputStream.java?rev=1392595&view=auto
==============================================================================
--- directmemory/lightning/trunk/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/io/BufferOutputStream.java (added)
+++ directmemory/lightning/trunk/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/io/BufferOutputStream.java Mon Oct 1 20:57:42 2012
@@ -0,0 +1,49 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.directmemory.lightning.internal.io;
+
+import java.io.IOException;
+import java.io.OutputStream;
+import java.nio.ByteBuffer;
+
+public class BufferOutputStream
+ extends OutputStream
+{
+
+ private final ByteBuffer byteBuffer;
+
+ public BufferOutputStream( ByteBuffer byteBuffer )
+ {
+ this.byteBuffer = byteBuffer;
+ }
+
+ @Override
+ public synchronized void write( int b )
+ throws IOException
+ {
+ byteBuffer.put( (byte) b );
+ }
+
+ @Override
+ public synchronized void write( byte[] bytes, int off, int len )
+ throws IOException
+ {
+ byteBuffer.put( bytes, off, len );
+ }
+}
Propchange: directmemory/lightning/trunk/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/io/BufferOutputStream.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: directmemory/lightning/trunk/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/io/BufferOutputStream.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: directmemory/lightning/trunk/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/io/ReaderInputStream.java
URL: http://svn.apache.org/viewvc/directmemory/lightning/trunk/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/io/ReaderInputStream.java?rev=1392595&view=auto
==============================================================================
--- directmemory/lightning/trunk/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/io/ReaderInputStream.java (added)
+++ directmemory/lightning/trunk/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/io/ReaderInputStream.java Mon Oct 1 20:57:42 2012
@@ -0,0 +1,243 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.directmemory.lightning.internal.io;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.Reader;
+
+public class ReaderInputStream
+ extends InputStream
+{
+
+ /** Source Reader */
+ private Reader in;
+
+ private String encoding = System.getProperty( "file.encoding" );
+
+ private byte[] slack;
+
+ private int begin;
+
+ /**
+ * Construct a <CODE>ReaderInputStream</CODE> for the specified <CODE>Reader</CODE>.
+ *
+ * @param reader <CODE>Reader</CODE>. Must not be <code>null</code>.
+ */
+ public ReaderInputStream( Reader reader )
+ {
+ in = reader;
+ }
+
+ /**
+ * Construct a <CODE>ReaderInputStream</CODE> for the specified <CODE>Reader</CODE>, with the specified encoding.
+ *
+ * @param reader non-null <CODE>Reader</CODE>.
+ * @param encoding non-null <CODE>String</CODE> encoding.
+ */
+ public ReaderInputStream( Reader reader, String encoding )
+ {
+ this( reader );
+ if ( encoding == null )
+ {
+ throw new IllegalArgumentException( "encoding must not be null" );
+ }
+ else
+ {
+ this.encoding = encoding;
+ }
+ }
+
+ /**
+ * Reads from the <CODE>Reader</CODE>, returning the same value.
+ *
+ * @return the value of the next character in the <CODE>Reader</CODE>.
+ * @exception IOException if the original <code>Reader</code> fails to be read
+ */
+ @Override
+ public synchronized int read()
+ throws IOException
+ {
+ if ( in == null )
+ {
+ throw new IOException( "Stream Closed" );
+ }
+
+ byte result;
+ if ( slack != null && begin < slack.length )
+ {
+ result = slack[begin];
+ if ( ++begin == slack.length )
+ {
+ slack = null;
+ }
+ }
+ else
+ {
+ byte[] buf = new byte[1];
+ if ( read( buf, 0, 1 ) <= 0 )
+ {
+ result = -1;
+ }
+ result = buf[0];
+ }
+
+ if ( result < -1 )
+ {
+ result += 256;
+ }
+
+ return result;
+ }
+
+ /**
+ * Reads from the <code>Reader</code> into a byte array
+ *
+ * @param b the byte array to read into
+ * @param off the offset in the byte array
+ * @param len the length in the byte array to fill
+ * @return the actual number read into the byte array, -1 at the end of the stream
+ * @exception IOException if an error occurs
+ */
+ @Override
+ public synchronized int read( byte[] b, int off, int len )
+ throws IOException
+ {
+ if ( in == null )
+ {
+ throw new IOException( "Stream Closed" );
+ }
+
+ while ( slack == null )
+ {
+ char[] buf = new char[len]; // might read too much
+ int n = in.read( buf );
+ if ( n == -1 )
+ {
+ return -1;
+ }
+ if ( n > 0 )
+ {
+ slack = new String( buf, 0, n ).getBytes( encoding );
+ begin = 0;
+ }
+ }
+
+ if ( len > slack.length - begin )
+ {
+ len = slack.length - begin;
+ }
+
+ System.arraycopy( slack, begin, b, off, len );
+
+ if ( ( begin += len ) >= slack.length )
+ {
+ slack = null;
+ }
+
+ return len;
+ }
+
+ /**
+ * Marks the read limit of the StringReader.
+ *
+ * @param limit the maximum limit of bytes that can be read before the mark position becomes invalid
+ */
+ @Override
+ public synchronized void mark( final int limit )
+ {
+ try
+ {
+ in.mark( limit );
+ }
+ catch ( IOException ioe )
+ {
+ throw new RuntimeException( ioe.getMessage() );
+ }
+ }
+
+ /**
+ * @return the current number of bytes ready for reading
+ * @exception IOException if an error occurs
+ */
+ @Override
+ public synchronized int available()
+ throws IOException
+ {
+ if ( in == null )
+ {
+ throw new IOException( "Stream Closed" );
+ }
+ if ( slack != null )
+ {
+ return slack.length - begin;
+ }
+ if ( in.ready() )
+ {
+ return 1;
+ }
+ else
+ {
+ return 0;
+ }
+ }
+
+ /**
+ * @return false - mark is not supported
+ */
+ @Override
+ public boolean markSupported()
+ {
+ return false; // would be imprecise
+ }
+
+ /**
+ * Resets the StringReader.
+ *
+ * @exception IOException if the StringReader fails to be reset
+ */
+ @Override
+ public synchronized void reset()
+ throws IOException
+ {
+ if ( in == null )
+ {
+ throw new IOException( "Stream Closed" );
+ }
+ slack = null;
+ in.reset();
+ }
+
+ /**
+ * Closes the Stringreader.
+ *
+ * @exception IOException if the original StringReader fails to be closed
+ */
+ @Override
+ public synchronized void close()
+ throws IOException
+ {
+ if ( in != null )
+ {
+ in.close();
+ slack = null;
+ in = null;
+ }
+ }
+}
Propchange: directmemory/lightning/trunk/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/io/ReaderInputStream.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: directmemory/lightning/trunk/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/io/ReaderInputStream.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: directmemory/lightning/trunk/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/io/WriterOutputStream.java
URL: http://svn.apache.org/viewvc/directmemory/lightning/trunk/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/io/WriterOutputStream.java?rev=1392595&view=auto
==============================================================================
--- directmemory/lightning/trunk/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/io/WriterOutputStream.java (added)
+++ directmemory/lightning/trunk/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/io/WriterOutputStream.java Mon Oct 1 20:57:42 2012
@@ -0,0 +1,103 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.directmemory.lightning.internal.io;
+
+import java.io.IOException;
+import java.io.OutputStream;
+import java.io.Writer;
+
+/* ------------------------------------------------------------ */
+/**
+ * Wrap a Writer as an OutputStream. When all you have is a Writer and only an OutputStream will do. Try not to use this
+ * as it indicates that your design is a dogs breakfast (JSP made me write it).
+ *
+ * @author Greg Wilkins (gregw) - Mort Bay Consulting Pty. Ltd.
+ */
+public class WriterOutputStream
+ extends OutputStream
+{
+
+ protected Writer _writer;
+
+ protected String _encoding;
+
+ private byte[] _buf = new byte[1];
+
+ /* ------------------------------------------------------------ */
+ public WriterOutputStream( Writer writer, String encoding )
+ {
+ _writer = writer;
+ _encoding = encoding;
+ }
+
+ /* ------------------------------------------------------------ */
+ public WriterOutputStream( Writer writer )
+ {
+ _writer = writer;
+ }
+
+ /* ------------------------------------------------------------ */
+ @Override
+ public void close()
+ throws IOException
+ {
+ _writer.close();
+ _writer = null;
+ _encoding = null;
+ }
+
+ /* ------------------------------------------------------------ */
+ @Override
+ public void flush()
+ throws IOException
+ {
+ _writer.flush();
+ }
+
+ /* ------------------------------------------------------------ */
+ @Override
+ public void write( byte[] b )
+ throws IOException
+ {
+ if ( _encoding == null )
+ _writer.write( new String( b ) );
+ else
+ _writer.write( new String( b, _encoding ) );
+ }
+
+ /* ------------------------------------------------------------ */
+ @Override
+ public void write( byte[] b, int off, int len )
+ throws IOException
+ {
+ if ( _encoding == null )
+ _writer.write( new String( b, off, len ) );
+ else
+ _writer.write( new String( b, off, len, _encoding ) );
+ }
+
+ /* ------------------------------------------------------------ */
+ @Override
+ public synchronized void write( int b )
+ throws IOException
+ {
+ _buf[0] = (byte) b;
+ write( _buf );
+ }
+}
Propchange: directmemory/lightning/trunk/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/io/WriterOutputStream.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: directmemory/lightning/trunk/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/io/WriterOutputStream.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: directmemory/lightning/trunk/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/marshaller/BigDecimalMarshaller.java
URL: http://svn.apache.org/viewvc/directmemory/lightning/trunk/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/marshaller/BigDecimalMarshaller.java?rev=1392595&view=auto
==============================================================================
--- directmemory/lightning/trunk/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/marshaller/BigDecimalMarshaller.java (added)
+++ directmemory/lightning/trunk/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/marshaller/BigDecimalMarshaller.java Mon Oct 1 20:57:42 2012
@@ -0,0 +1,77 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.directmemory.lightning.internal.marshaller;
+
+import java.io.DataInput;
+import java.io.DataOutput;
+import java.io.IOException;
+import java.math.BigDecimal;
+import java.nio.charset.Charset;
+
+import org.apache.directmemory.lightning.SerializationContext;
+import org.apache.directmemory.lightning.base.AbstractMarshaller;
+import org.apache.directmemory.lightning.metadata.PropertyDescriptor;
+
+public class BigDecimalMarshaller
+ extends AbstractMarshaller
+{
+
+ private static final Charset CHARSET = Charset.forName( "ASCII" );
+
+ @Override
+ public boolean acceptType( Class<?> type )
+ {
+ return BigDecimal.class == type;
+ }
+
+ @Override
+ public void marshall( Object value, PropertyDescriptor propertyDescriptor, DataOutput dataOutput,
+ SerializationContext serializationContext )
+ throws IOException
+ {
+
+ if ( !writePossibleNull( value, dataOutput ) )
+ {
+ return;
+ }
+
+ String representation = ( (BigDecimal) value ).toString();
+ byte[] data = representation.getBytes( CHARSET );
+ dataOutput.writeInt( data.length );
+ dataOutput.write( data );
+ }
+
+ @Override
+ @SuppressWarnings( "unchecked" )
+ public <V> V unmarshall( PropertyDescriptor propertyDescriptor, DataInput dataInput,
+ SerializationContext serializationContext )
+ throws IOException
+ {
+ if ( isNull( dataInput ) )
+ {
+ return null;
+ }
+
+ int length = dataInput.readInt();
+ byte[] data = new byte[length];
+ dataInput.readFully( data );
+
+ return (V) new BigDecimal( new String( data, CHARSET ) );
+ }
+}
Propchange: directmemory/lightning/trunk/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/marshaller/BigDecimalMarshaller.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: directmemory/lightning/trunk/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/marshaller/BigDecimalMarshaller.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: directmemory/lightning/trunk/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/marshaller/BigIntegerMarshaller.java
URL: http://svn.apache.org/viewvc/directmemory/lightning/trunk/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/marshaller/BigIntegerMarshaller.java?rev=1392595&view=auto
==============================================================================
--- directmemory/lightning/trunk/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/marshaller/BigIntegerMarshaller.java (added)
+++ directmemory/lightning/trunk/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/marshaller/BigIntegerMarshaller.java Mon Oct 1 20:57:42 2012
@@ -0,0 +1,73 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.directmemory.lightning.internal.marshaller;
+
+import java.io.DataInput;
+import java.io.DataOutput;
+import java.io.IOException;
+import java.math.BigInteger;
+
+import org.apache.directmemory.lightning.SerializationContext;
+import org.apache.directmemory.lightning.base.AbstractMarshaller;
+import org.apache.directmemory.lightning.metadata.PropertyDescriptor;
+
+public class BigIntegerMarshaller
+ extends AbstractMarshaller
+{
+
+ @Override
+ public boolean acceptType( Class<?> type )
+ {
+ return BigInteger.class == type;
+ }
+
+ @Override
+ public void marshall( Object value, PropertyDescriptor propertyDescriptor, DataOutput dataOutput,
+ SerializationContext serializationContext )
+ throws IOException
+ {
+
+ if ( !writePossibleNull( value, dataOutput ) )
+ {
+ return;
+ }
+
+ byte[] data = ( (BigInteger) value ).toByteArray();
+ dataOutput.writeInt( data.length );
+ dataOutput.write( data );
+ }
+
+ @Override
+ @SuppressWarnings( "unchecked" )
+ public <V> V unmarshall( PropertyDescriptor propertyDescriptor, DataInput dataInput,
+ SerializationContext serializationContext )
+ throws IOException
+ {
+ if ( isNull( dataInput ) )
+ {
+ return null;
+ }
+
+ int length = dataInput.readInt();
+ byte[] data = new byte[length];
+ dataInput.readFully( data );
+
+ return (V) new BigInteger( data );
+ }
+}
Propchange: directmemory/lightning/trunk/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/marshaller/BigIntegerMarshaller.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: directmemory/lightning/trunk/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/marshaller/BigIntegerMarshaller.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: directmemory/lightning/trunk/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/marshaller/BooleanArrayMarshaller.java
URL: http://svn.apache.org/viewvc/directmemory/lightning/trunk/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/marshaller/BooleanArrayMarshaller.java?rev=1392595&view=auto
==============================================================================
--- directmemory/lightning/trunk/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/marshaller/BooleanArrayMarshaller.java (added)
+++ directmemory/lightning/trunk/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/marshaller/BooleanArrayMarshaller.java Mon Oct 1 20:57:42 2012
@@ -0,0 +1,105 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.directmemory.lightning.internal.marshaller;
+
+import java.io.DataInput;
+import java.io.DataOutput;
+import java.io.IOException;
+
+import org.apache.directmemory.lightning.SerializationContext;
+import org.apache.directmemory.lightning.base.AbstractMarshaller;
+import org.apache.directmemory.lightning.metadata.PropertyDescriptor;
+
+public class BooleanArrayMarshaller
+ extends AbstractMarshaller
+{
+
+ @Override
+ public boolean acceptType( Class<?> type )
+ {
+ return boolean[].class == type || Boolean[].class == type;
+ }
+
+ @Override
+ public void marshall( Object value, PropertyDescriptor propertyDescriptor, DataOutput dataOutput,
+ SerializationContext serializationContext )
+ throws IOException
+ {
+
+ if ( !writePossibleNull( value, dataOutput ) )
+ {
+ return;
+ }
+
+ if ( boolean[].class == propertyDescriptor.getType() )
+ {
+ boolean[] array = (boolean[]) value;
+ dataOutput.writeInt( array.length );
+
+ for ( boolean arrayValue : array )
+ {
+ dataOutput.writeBoolean( arrayValue );
+ }
+ }
+ else
+ {
+ Boolean[] array = (Boolean[]) value;
+ dataOutput.writeInt( array.length );
+
+ for ( boolean arrayValue : array )
+ {
+ dataOutput.writeBoolean( arrayValue );
+ }
+ }
+ }
+
+ @Override
+ @SuppressWarnings( "unchecked" )
+ public <V> V unmarshall( PropertyDescriptor propertyDescriptor, DataInput dataInput,
+ SerializationContext serializationContext )
+ throws IOException
+ {
+ if ( isNull( dataInput ) )
+ {
+ return null;
+ }
+
+ int size = dataInput.readInt();
+ if ( boolean[].class == propertyDescriptor.getType() )
+ {
+ boolean[] array = new boolean[size];
+ for ( int i = 0; i < size; i++ )
+ {
+ array[i] = dataInput.readBoolean();
+ }
+
+ return (V) array;
+ }
+ else
+ {
+ Boolean[] array = new Boolean[size];
+ for ( int i = 0; i < size; i++ )
+ {
+ array[i] = dataInput.readBoolean();
+ }
+
+ return (V) array;
+ }
+ }
+}
Propchange: directmemory/lightning/trunk/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/marshaller/BooleanArrayMarshaller.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: directmemory/lightning/trunk/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/marshaller/BooleanArrayMarshaller.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: directmemory/lightning/trunk/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/marshaller/BooleanMarshaller.java
URL: http://svn.apache.org/viewvc/directmemory/lightning/trunk/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/marshaller/BooleanMarshaller.java?rev=1392595&view=auto
==============================================================================
--- directmemory/lightning/trunk/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/marshaller/BooleanMarshaller.java (added)
+++ directmemory/lightning/trunk/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/marshaller/BooleanMarshaller.java Mon Oct 1 20:57:42 2012
@@ -0,0 +1,72 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.directmemory.lightning.internal.marshaller;
+
+import java.io.DataInput;
+import java.io.DataOutput;
+import java.io.IOException;
+
+import org.apache.directmemory.lightning.SerializationContext;
+import org.apache.directmemory.lightning.base.AbstractMarshaller;
+import org.apache.directmemory.lightning.metadata.PropertyDescriptor;
+
+public class BooleanMarshaller
+ extends AbstractMarshaller
+{
+
+ @Override
+ public boolean acceptType( Class<?> type )
+ {
+ return boolean.class == type || Boolean.class == type;
+ }
+
+ @Override
+ public void marshall( Object value, PropertyDescriptor propertyDescriptor, DataOutput dataOutput,
+ SerializationContext serializationContext )
+ throws IOException
+ {
+
+ if ( Boolean.class == propertyDescriptor.getType() )
+ {
+ if ( !writePossibleNull( value, dataOutput ) )
+ {
+ return;
+ }
+ }
+
+ dataOutput.writeBoolean( (Boolean) value );
+ }
+
+ @Override
+ @SuppressWarnings( "unchecked" )
+ public <V> V unmarshall( PropertyDescriptor propertyDescriptor, DataInput dataInput,
+ SerializationContext serializationContext )
+ throws IOException
+ {
+ if ( Boolean.class == propertyDescriptor.getType() )
+ {
+ if ( isNull( dataInput ) )
+ {
+ return null;
+ }
+ }
+
+ return (V) Boolean.valueOf( dataInput.readBoolean() );
+ }
+}
Propchange: directmemory/lightning/trunk/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/marshaller/BooleanMarshaller.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: directmemory/lightning/trunk/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/marshaller/BooleanMarshaller.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: directmemory/lightning/trunk/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/marshaller/ByteArrayMarshaller.java
URL: http://svn.apache.org/viewvc/directmemory/lightning/trunk/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/marshaller/ByteArrayMarshaller.java?rev=1392595&view=auto
==============================================================================
--- directmemory/lightning/trunk/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/marshaller/ByteArrayMarshaller.java (added)
+++ directmemory/lightning/trunk/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/marshaller/ByteArrayMarshaller.java Mon Oct 1 20:57:42 2012
@@ -0,0 +1,105 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.directmemory.lightning.internal.marshaller;
+
+import java.io.DataInput;
+import java.io.DataOutput;
+import java.io.IOException;
+
+import org.apache.directmemory.lightning.SerializationContext;
+import org.apache.directmemory.lightning.base.AbstractMarshaller;
+import org.apache.directmemory.lightning.metadata.PropertyDescriptor;
+
+public class ByteArrayMarshaller
+ extends AbstractMarshaller
+{
+
+ @Override
+ public boolean acceptType( Class<?> type )
+ {
+ return byte[].class == type || Byte[].class == type;
+ }
+
+ @Override
+ public void marshall( Object value, PropertyDescriptor propertyDescriptor, DataOutput dataOutput,
+ SerializationContext serializationContext )
+ throws IOException
+ {
+
+ if ( !writePossibleNull( value, dataOutput ) )
+ {
+ return;
+ }
+
+ if ( byte[].class == propertyDescriptor.getType() )
+ {
+ byte[] array = (byte[]) value;
+ dataOutput.writeInt( array.length );
+
+ for ( byte arrayValue : array )
+ {
+ dataOutput.writeByte( arrayValue );
+ }
+ }
+ else
+ {
+ Byte[] array = (Byte[]) value;
+ dataOutput.writeInt( array.length );
+
+ for ( byte arrayValue : array )
+ {
+ dataOutput.writeByte( arrayValue );
+ }
+ }
+ }
+
+ @Override
+ @SuppressWarnings( "unchecked" )
+ public <V> V unmarshall( PropertyDescriptor propertyDescriptor, DataInput dataInput,
+ SerializationContext serializationContext )
+ throws IOException
+ {
+ if ( isNull( dataInput ) )
+ {
+ return null;
+ }
+
+ int size = dataInput.readInt();
+ if ( byte[].class == propertyDescriptor.getType() )
+ {
+ byte[] array = new byte[size];
+ for ( int i = 0; i < size; i++ )
+ {
+ array[i] = dataInput.readByte();
+ }
+
+ return (V) array;
+ }
+ else
+ {
+ Byte[] array = new Byte[size];
+ for ( int i = 0; i < size; i++ )
+ {
+ array[i] = dataInput.readByte();
+ }
+
+ return (V) array;
+ }
+ }
+}
Propchange: directmemory/lightning/trunk/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/marshaller/ByteArrayMarshaller.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: directmemory/lightning/trunk/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/marshaller/ByteArrayMarshaller.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: directmemory/lightning/trunk/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/marshaller/ByteMarshaller.java
URL: http://svn.apache.org/viewvc/directmemory/lightning/trunk/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/marshaller/ByteMarshaller.java?rev=1392595&view=auto
==============================================================================
--- directmemory/lightning/trunk/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/marshaller/ByteMarshaller.java (added)
+++ directmemory/lightning/trunk/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/marshaller/ByteMarshaller.java Mon Oct 1 20:57:42 2012
@@ -0,0 +1,72 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.directmemory.lightning.internal.marshaller;
+
+import java.io.DataInput;
+import java.io.DataOutput;
+import java.io.IOException;
+
+import org.apache.directmemory.lightning.SerializationContext;
+import org.apache.directmemory.lightning.base.AbstractMarshaller;
+import org.apache.directmemory.lightning.metadata.PropertyDescriptor;
+
+public class ByteMarshaller
+ extends AbstractMarshaller
+{
+
+ @Override
+ public boolean acceptType( Class<?> type )
+ {
+ return byte.class == type || Byte.class == type;
+ }
+
+ @Override
+ public void marshall( Object value, PropertyDescriptor propertyDescriptor, DataOutput dataOutput,
+ SerializationContext serializationContext )
+ throws IOException
+ {
+
+ if ( Byte.class == propertyDescriptor.getType() )
+ {
+ if ( !writePossibleNull( value, dataOutput ) )
+ {
+ return;
+ }
+ }
+
+ dataOutput.writeByte( (Byte) value );
+ }
+
+ @Override
+ @SuppressWarnings( "unchecked" )
+ public <V> V unmarshall( PropertyDescriptor propertyDescriptor, DataInput dataInput,
+ SerializationContext serializationContext )
+ throws IOException
+ {
+ if ( Byte.class == propertyDescriptor.getType() )
+ {
+ if ( isNull( dataInput ) )
+ {
+ return null;
+ }
+ }
+
+ return (V) Byte.valueOf( dataInput.readByte() );
+ }
+}
Propchange: directmemory/lightning/trunk/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/marshaller/ByteMarshaller.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: directmemory/lightning/trunk/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/marshaller/ByteMarshaller.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: directmemory/lightning/trunk/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/marshaller/CharacterArrayMarshaller.java
URL: http://svn.apache.org/viewvc/directmemory/lightning/trunk/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/marshaller/CharacterArrayMarshaller.java?rev=1392595&view=auto
==============================================================================
--- directmemory/lightning/trunk/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/marshaller/CharacterArrayMarshaller.java (added)
+++ directmemory/lightning/trunk/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/marshaller/CharacterArrayMarshaller.java Mon Oct 1 20:57:42 2012
@@ -0,0 +1,105 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.directmemory.lightning.internal.marshaller;
+
+import java.io.DataInput;
+import java.io.DataOutput;
+import java.io.IOException;
+
+import org.apache.directmemory.lightning.SerializationContext;
+import org.apache.directmemory.lightning.base.AbstractMarshaller;
+import org.apache.directmemory.lightning.metadata.PropertyDescriptor;
+
+public class CharacterArrayMarshaller
+ extends AbstractMarshaller
+{
+
+ @Override
+ public boolean acceptType( Class<?> type )
+ {
+ return char[].class == type || Character[].class == type;
+ }
+
+ @Override
+ public void marshall( Object value, PropertyDescriptor propertyDescriptor, DataOutput dataOutput,
+ SerializationContext serializationContext )
+ throws IOException
+ {
+
+ if ( !writePossibleNull( value, dataOutput ) )
+ {
+ return;
+ }
+
+ if ( char[].class == propertyDescriptor.getType() )
+ {
+ char[] array = (char[]) value;
+ dataOutput.writeInt( array.length );
+
+ for ( char arrayValue : array )
+ {
+ dataOutput.writeChar( arrayValue );
+ }
+ }
+ else
+ {
+ Character[] array = (Character[]) value;
+ dataOutput.writeInt( array.length );
+
+ for ( char arrayValue : array )
+ {
+ dataOutput.writeChar( arrayValue );
+ }
+ }
+ }
+
+ @Override
+ @SuppressWarnings( "unchecked" )
+ public <V> V unmarshall( PropertyDescriptor propertyDescriptor, DataInput dataInput,
+ SerializationContext serializationContext )
+ throws IOException
+ {
+ if ( isNull( dataInput ) )
+ {
+ return null;
+ }
+
+ int size = dataInput.readInt();
+ if ( char[].class == propertyDescriptor.getType() )
+ {
+ char[] array = new char[size];
+ for ( int i = 0; i < size; i++ )
+ {
+ array[i] = dataInput.readChar();
+ }
+
+ return (V) array;
+ }
+ else
+ {
+ Character[] array = new Character[size];
+ for ( int i = 0; i < size; i++ )
+ {
+ array[i] = dataInput.readChar();
+ }
+
+ return (V) array;
+ }
+ }
+}