Started exchanging the old DataInput / DataOutput classes with Source / Target
git-svn-id: https://svn.apache.org/repos/asf/directmemory/lightning/trunk@1405125 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/lightning-core/src/main/java/org/apache/directmemory/lightning/Marshaller.java b/lightning-core/src/main/java/org/apache/directmemory/lightning/Marshaller.java
index 5d20379..1efd164 100644
--- a/lightning-core/src/main/java/org/apache/directmemory/lightning/Marshaller.java
+++ b/lightning-core/src/main/java/org/apache/directmemory/lightning/Marshaller.java
@@ -18,10 +18,9 @@
*/
package org.apache.directmemory.lightning;
-import java.io.DataInput;
-import java.io.DataOutput;
import java.io.IOException;
+import org.apache.directmemory.lightning.base.AbstractSerializerDefinition;
import org.apache.directmemory.lightning.metadata.PropertyDescriptor;
/**
@@ -44,25 +43,24 @@
*
* @param value Object instance to serialize
* @param propertyDescriptor The {@link PropertyDescriptor} of this object
- * @param dataOutput The {@link DataOutput} implementation to write to
+ * @param target The {@link Target} implementation to write to
* @param serializationContext The {@link SerializationContext} used to serialize this object graph
- * @throws IOException Throws {@link IOException} if any exception occurs while writing to the {@link DataOutput}
+ * @throws IOException Throws {@link IOException} if any exception occurs while writing to the {@link Target}
*/
- void marshall( Object value, PropertyDescriptor propertyDescriptor, DataOutput dataOutput,
+ void marshall( Object value, PropertyDescriptor propertyDescriptor, Target target,
SerializationContext serializationContext )
throws IOException;
/**
- * Unmarshalls (deserializes) an object from the given {@link DataInput}.
+ * Unmarshalls (deserializes) an object from the given {@link Source}.
*
* @param propertyDescriptor The {@link PropertyDescriptor} of this object
- * @param dataInput The {@link DataInput} implementation to read from
+ * @param source The {@link Source} implementation to read from
* @param serializationContext The {@link SerializationContext} used to deserialize this object graph
- * @return An object read from the given {@link DataInput}
- * @throws IOException Throws {@link IOException} if any exception occurs while reading from the {@link DataInput}
+ * @return An object read from the given {@link Source}
+ * @throws IOException Throws {@link IOException} if any exception occurs while reading from the {@link Source}
*/
- <V> V unmarshall( PropertyDescriptor propertyDescriptor, DataInput dataInput,
- SerializationContext serializationContext )
+ <V> V unmarshall( PropertyDescriptor propertyDescriptor, Source source, SerializationContext serializationContext )
throws IOException;
}
diff --git a/lightning-core/src/main/java/org/apache/directmemory/lightning/Serializer.java b/lightning-core/src/main/java/org/apache/directmemory/lightning/Serializer.java
index 0826c3d..74f4e57 100644
--- a/lightning-core/src/main/java/org/apache/directmemory/lightning/Serializer.java
+++ b/lightning-core/src/main/java/org/apache/directmemory/lightning/Serializer.java
@@ -18,14 +18,6 @@
*/
package org.apache.directmemory.lightning;
-import java.io.DataInput;
-import java.io.DataOutput;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.io.Reader;
-import java.io.Writer;
-import java.nio.ByteBuffer;
-
import org.apache.directmemory.lightning.metadata.ClassDefinitionContainer;
public interface Serializer
@@ -35,20 +27,8 @@
void setClassDefinitionContainer( ClassDefinitionContainer classDefinitionContainer );
- <V> void serialize( V value, DataOutput dataOutput );
+ <V> void serialize( V value, Target target );
- <V> void serialize( V value, OutputStream outputStream );
-
- <V> void serialize( V value, Writer writer );
-
- <V> void serialize( V value, ByteBuffer buffer );
-
- <V> V deserialize( DataInput dataInput );
-
- <V> V deserialize( InputStream inputStream );
-
- <V> V deserialize( Reader reader );
-
- <V> V deserialize( ByteBuffer buffer );
+ <V> V deserialize( Source source );
}
diff --git a/lightning-core/src/main/java/org/apache/directmemory/lightning/Source.java b/lightning-core/src/main/java/org/apache/directmemory/lightning/Source.java
index ba7f3a2..74096f6 100644
--- a/lightning-core/src/main/java/org/apache/directmemory/lightning/Source.java
+++ b/lightning-core/src/main/java/org/apache/directmemory/lightning/Source.java
@@ -28,6 +28,9 @@
long readableBytes();
+ boolean readBoolean()
+ throws IOException;
+
int readBytes( byte[] bytes )
throws IOException;
diff --git a/lightning-core/src/main/java/org/apache/directmemory/lightning/Streamed.java b/lightning-core/src/main/java/org/apache/directmemory/lightning/Streamed.java
index 18ce20f..a27f4e0 100644
--- a/lightning-core/src/main/java/org/apache/directmemory/lightning/Streamed.java
+++ b/lightning-core/src/main/java/org/apache/directmemory/lightning/Streamed.java
@@ -18,17 +18,15 @@
*/
package org.apache.directmemory.lightning;
-import java.io.DataInput;
-import java.io.DataOutput;
import java.io.IOException;
public interface Streamed
{
- void writeTo( DataOutput dataOutput )
+ void writeTo( Target target )
throws IOException;
- void readFrom( DataInput dataInput )
+ void readFrom( Source source )
throws IOException;
}
diff --git a/lightning-core/src/main/java/org/apache/directmemory/lightning/Target.java b/lightning-core/src/main/java/org/apache/directmemory/lightning/Target.java
index 0e66489..dda4067 100644
--- a/lightning-core/src/main/java/org/apache/directmemory/lightning/Target.java
+++ b/lightning-core/src/main/java/org/apache/directmemory/lightning/Target.java
@@ -28,6 +28,9 @@
long writtenBytes();
+ void writeBoolean( boolean value )
+ throws IOException;
+
void writeBytes( byte[] bytes )
throws IOException;
diff --git a/lightning-core/src/main/java/org/apache/directmemory/lightning/base/AbstractMarshaller.java b/lightning-core/src/main/java/org/apache/directmemory/lightning/base/AbstractMarshaller.java
index 7e91f86..2ec9cb7 100644
--- a/lightning-core/src/main/java/org/apache/directmemory/lightning/base/AbstractMarshaller.java
+++ b/lightning-core/src/main/java/org/apache/directmemory/lightning/base/AbstractMarshaller.java
@@ -18,12 +18,12 @@
*/
package org.apache.directmemory.lightning.base;
-import java.io.DataInput;
-import java.io.DataOutput;
import java.io.IOException;
import org.apache.directmemory.lightning.Marshaller;
import org.apache.directmemory.lightning.SerializationContext;
+import org.apache.directmemory.lightning.Source;
+import org.apache.directmemory.lightning.Target;
import org.apache.directmemory.lightning.metadata.PropertyDescriptor;
public abstract class AbstractMarshaller
@@ -31,24 +31,24 @@
{
@Override
- public <V> V unmarshall( PropertyDescriptor propertyDescriptor, DataInput dataInput,
+ public <V> V unmarshall( PropertyDescriptor propertyDescriptor, Source source,
SerializationContext serializationContext )
throws IOException
{
return null;
}
- protected boolean writePossibleNull( Object value, DataOutput dataOutput )
+ protected boolean writePossibleNull( Object value, Target target )
throws IOException
{
- dataOutput.writeByte( value == null ? 1 : 0 );
+ target.writeByte( (byte) ( value == null ? 1 : 0 ) );
return value != null;
}
- protected boolean isNull( DataInput dataInput )
+ protected boolean isNull( Source source )
throws IOException
{
- byte isNull = dataInput.readByte();
+ byte isNull = source.readByte();
return isNull == 1 ? true : false;
}
}
diff --git a/lightning-core/src/main/java/org/apache/directmemory/lightning/base/AbstractObjectMarshaller.java b/lightning-core/src/main/java/org/apache/directmemory/lightning/base/AbstractObjectMarshaller.java
index 1344edf..fa3bf5f 100644
--- a/lightning-core/src/main/java/org/apache/directmemory/lightning/base/AbstractObjectMarshaller.java
+++ b/lightning-core/src/main/java/org/apache/directmemory/lightning/base/AbstractObjectMarshaller.java
@@ -18,10 +18,10 @@
*/
package org.apache.directmemory.lightning.base;
-import java.io.DataInput;
import java.io.IOException;
import org.apache.directmemory.lightning.SerializationContext;
+import org.apache.directmemory.lightning.Source;
import org.apache.directmemory.lightning.metadata.PropertyDescriptor;
public abstract class AbstractObjectMarshaller
@@ -30,16 +30,16 @@
@Override
@SuppressWarnings( "unchecked" )
- public final <V> V unmarshall( PropertyDescriptor propertyDescriptor, DataInput dataInput,
+ public final <V> V unmarshall( PropertyDescriptor propertyDescriptor, Source source,
SerializationContext serializationContext )
throws IOException
{
Object value =
serializationContext.getObjectInstantiatorFactory().getInstantiatorOf( propertyDescriptor.getType() );
- return unmarshall( (V) value, propertyDescriptor, dataInput, serializationContext );
+ return unmarshall( (V) value, propertyDescriptor, source, serializationContext );
}
- public abstract <V> V unmarshall( V value, PropertyDescriptor propertyDescriptor, DataInput dataInput,
+ public abstract <V> V unmarshall( V value, PropertyDescriptor propertyDescriptor, Source source,
SerializationContext serializationContext )
throws IOException;
}
diff --git a/lightning-core/src/main/java/org/apache/directmemory/lightning/base/ObjenesisDelegatingMarshaller.java b/lightning-core/src/main/java/org/apache/directmemory/lightning/base/ObjenesisDelegatingMarshaller.java
index f3596a9..e2d3fa0 100644
--- a/lightning-core/src/main/java/org/apache/directmemory/lightning/base/ObjenesisDelegatingMarshaller.java
+++ b/lightning-core/src/main/java/org/apache/directmemory/lightning/base/ObjenesisDelegatingMarshaller.java
@@ -18,12 +18,12 @@
*/
package org.apache.directmemory.lightning.base;
-import java.io.DataInput;
-import java.io.DataOutput;
import java.io.IOException;
import org.apache.directmemory.lightning.Marshaller;
import org.apache.directmemory.lightning.SerializationContext;
+import org.apache.directmemory.lightning.Source;
+import org.apache.directmemory.lightning.Target;
import org.apache.directmemory.lightning.instantiator.ObjectInstantiatorFactory;
import org.apache.directmemory.lightning.metadata.PropertyDescriptor;
@@ -49,22 +49,22 @@
}
@Override
- public void marshall( Object value, PropertyDescriptor propertyDescriptor, DataOutput dataOutput,
+ public void marshall( Object value, PropertyDescriptor propertyDescriptor, Target target,
SerializationContext serializationContext )
throws IOException
{
- delegatedMarshaller.marshall( value, propertyDescriptor, dataOutput, serializationContext );
+ delegatedMarshaller.marshall( value, propertyDescriptor, target, serializationContext );
}
@Override
@SuppressWarnings( "unchecked" )
- public <V> V unmarshall( PropertyDescriptor propertyDescriptor, DataInput dataInput,
+ public <V> V unmarshall( PropertyDescriptor propertyDescriptor, Source source,
SerializationContext serializationContext )
throws IOException
{
V value = (V) objectInstantiatorFactory.newInstance( propertyDescriptor.getType() );
- return delegatedMarshaller.unmarshall( value, propertyDescriptor, dataInput, serializationContext );
+ return delegatedMarshaller.unmarshall( value, propertyDescriptor, source, serializationContext );
}
}
diff --git a/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/InternalSerializer.java b/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/InternalSerializer.java
index dbea74e..03f00b7 100644
--- a/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/InternalSerializer.java
+++ b/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/InternalSerializer.java
@@ -18,17 +18,8 @@
*/
package org.apache.directmemory.lightning.internal;
-import java.io.DataInput;
-import java.io.DataInputStream;
-import java.io.DataOutput;
-import java.io.DataOutputStream;
import java.io.File;
import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.io.Reader;
-import java.io.Writer;
-import java.nio.ByteBuffer;
import java.util.Arrays;
import java.util.Collections;
import java.util.Map;
@@ -39,15 +30,13 @@
import org.apache.directmemory.lightning.MarshallerStrategy;
import org.apache.directmemory.lightning.SerializationContext;
import org.apache.directmemory.lightning.SerializationStrategy;
+import org.apache.directmemory.lightning.Source;
+import org.apache.directmemory.lightning.Target;
import org.apache.directmemory.lightning.exceptions.ClassDefinitionInconsistentException;
import org.apache.directmemory.lightning.exceptions.SerializerExecutionException;
import org.apache.directmemory.lightning.instantiator.ObjectInstantiatorFactory;
import org.apache.directmemory.lightning.internal.generator.BytecodeMarshallerGenerator;
import org.apache.directmemory.lightning.internal.generator.MarshallerGenerator;
-import org.apache.directmemory.lightning.internal.io.BufferInputStream;
-import org.apache.directmemory.lightning.internal.io.BufferOutputStream;
-import org.apache.directmemory.lightning.internal.io.ReaderInputStream;
-import org.apache.directmemory.lightning.internal.io.WriterOutputStream;
import org.apache.directmemory.lightning.logging.Logger;
import org.apache.directmemory.lightning.metadata.ClassDefinition;
import org.apache.directmemory.lightning.metadata.ClassDefinitionContainer;
@@ -130,7 +119,7 @@
}
@Override
- public <V> void serialize( V value, DataOutput dataOutput )
+ public <V> void serialize( V value, Target target )
{
try
{
@@ -144,8 +133,8 @@
Marshaller marshaller = classDescriptor.getMarshaller();
PropertyDescriptor pd = new CheatPropertyDescriptor( "serialize", classDescriptor.getType(), marshaller );
- dataOutput.writeLong( classDescriptor.getClassDefinition().getId() );
- marshaller.marshall( value, pd, dataOutput, serializationContext );
+ target.writeLong( classDescriptor.getClassDefinition().getId() );
+ marshaller.marshall( value, pd, target, serializationContext );
}
catch ( IOException e )
{
@@ -154,29 +143,8 @@
}
@Override
- public <V> void serialize( V value, OutputStream outputStream )
- {
- if ( outputStream instanceof DataOutput )
- serialize( value, (DataOutput) outputStream );
- else
- serialize( value, (DataOutput) new DataOutputStream( outputStream ) );
- }
-
- @Override
- public <V> void serialize( V value, Writer writer )
- {
- serialize( value, (DataOutput) new DataOutputStream( new WriterOutputStream( writer, "UTF-8" ) ) );
- }
-
- @Override
- public <V> void serialize( V value, ByteBuffer buffer )
- {
- serialize( value, (DataOutput) new DataOutputStream( new BufferOutputStream( buffer ) ) );
- }
-
- @Override
@SuppressWarnings( "unchecked" )
- public <V> V deserialize( DataInput dataInput )
+ public <V> V deserialize( Source source )
{
try
{
@@ -185,13 +153,13 @@
marshallerStrategy, objectInstantiatorFactory,
valueNullableEvaluator, definedMarshallers );
- long typeId = dataInput.readLong();
+ long typeId = source.readLong();
Class<?> clazz = classDefinitionContainer.get().getTypeById( typeId );
ClassDescriptor classDescriptor = findClassDescriptor( clazz );
Marshaller marshaller = classDescriptor.getMarshaller();
PropertyDescriptor pd = new CheatPropertyDescriptor( "serialize", classDescriptor.getType(), marshaller );
- return (V) marshaller.unmarshall( pd, dataInput, serializationContext );
+ return (V) marshaller.unmarshall( pd, source, serializationContext );
}
catch ( IOException e )
{
@@ -200,29 +168,6 @@
}
@Override
- public <V> V deserialize( InputStream inputStream )
- {
- if ( inputStream instanceof DataInput )
- {
- return deserialize( (DataInput) inputStream );
- }
-
- return deserialize( (DataInput) new DataInputStream( inputStream ) );
- }
-
- @Override
- public <V> V deserialize( Reader reader )
- {
- return deserialize( (DataInput) new DataInputStream( new ReaderInputStream( reader, "UTF-8" ) ) );
- }
-
- @Override
- public <V> V deserialize( ByteBuffer buffer )
- {
- return deserialize( (DataInput) new DataInputStream( new BufferInputStream( buffer ) ) );
- }
-
- @Override
public ClassDescriptor findClassDescriptor( Class<?> type )
{
return classDescriptors.get( type );
diff --git a/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/generator/AbstractGeneratedMarshaller.java b/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/generator/AbstractGeneratedMarshaller.java
index ab8b9bb..85eb4eb 100644
--- a/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/generator/AbstractGeneratedMarshaller.java
+++ b/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/generator/AbstractGeneratedMarshaller.java
@@ -18,7 +18,6 @@
*/
package org.apache.directmemory.lightning.internal.generator;
-import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import java.util.Collections;
@@ -28,6 +27,8 @@
import org.apache.directmemory.lightning.Marshaller;
import org.apache.directmemory.lightning.SerializationContext;
import org.apache.directmemory.lightning.SerializationStrategy;
+import org.apache.directmemory.lightning.Source;
+import org.apache.directmemory.lightning.Target;
import org.apache.directmemory.lightning.exceptions.SerializerDefinitionException;
import org.apache.directmemory.lightning.instantiator.ObjectInstantiator;
import org.apache.directmemory.lightning.instantiator.ObjectInstantiatorFactory;
@@ -71,7 +72,7 @@
@Override
@SuppressWarnings( "unchecked" )
- public <V> V unmarshall( PropertyDescriptor propertyDescriptor, DataInput dataInput,
+ public <V> V unmarshall( PropertyDescriptor propertyDescriptor, Source source,
SerializationContext serializationContext )
throws IOException
{
@@ -79,7 +80,7 @@
{
if ( ClassUtil.isReferenceCapable( propertyDescriptor.getType() ) )
{
- long referenceId = dataInput.readLong();
+ long referenceId = source.readLong();
V instance;
if ( containsReferenceId( referenceId, serializationContext ) )
{
@@ -88,7 +89,7 @@
else
{
// Instance not yet received, for first time deserialize it
- instance = unmarshall( (V) newInstance(), propertyDescriptor, dataInput, serializationContext );
+ instance = unmarshall( (V) newInstance(), propertyDescriptor, source, serializationContext );
cacheObjectForUnmarshall( referenceId, instance, serializationContext );
}
@@ -102,10 +103,10 @@
value = (V) newInstance();
}
- return unmarshall( value, propertyDescriptor, dataInput, serializationContext );
+ return unmarshall( value, propertyDescriptor, source, serializationContext );
}
- protected abstract <V> V unmarshall( V value, PropertyDescriptor propertyDescriptor, DataInput dataInput,
+ protected abstract <V> V unmarshall( V value, PropertyDescriptor propertyDescriptor, Source source,
SerializationContext serializationContext )
throws IOException;
@@ -226,7 +227,7 @@
}
@Override
- public void marshall( Object value, PropertyDescriptor propertyDescriptor, DataOutput dataOutput,
+ public void marshall( Object value, PropertyDescriptor propertyDescriptor, Target target,
SerializationContext serializationContext )
throws IOException
{
@@ -242,11 +243,11 @@
throw new SerializerDefinitionException( "No marshaller for property " + marshalledProperty + " found" );
}
- marshaller.marshall( value, propertyDescriptor, dataOutput, serializationContext );
+ marshaller.marshall( value, propertyDescriptor, target, serializationContext );
}
@Override
- public <V> V unmarshall( PropertyDescriptor propertyDescriptor, DataInput dataInput,
+ public <V> V unmarshall( PropertyDescriptor propertyDescriptor, Source source,
SerializationContext serializationContext )
throws IOException
{
@@ -261,7 +262,7 @@
throw new SerializerDefinitionException( "No marshaller for property " + marshalledProperty + " found" );
}
- return marshaller.unmarshall( propertyDescriptor, dataInput, serializationContext );
+ return marshaller.unmarshall( propertyDescriptor, source, serializationContext );
}
private synchronized Marshaller getMarshaller()
diff --git a/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/io/ReaderInputStream.java b/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/io/ReaderInputStream.java
deleted file mode 100644
index f8431fc..0000000
--- a/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/io/ReaderInputStream.java
+++ /dev/null
@@ -1,243 +0,0 @@
-/*
- * 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;
- }
- }
-}
diff --git a/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/io/WriterOutputStream.java b/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/io/WriterOutputStream.java
deleted file mode 100644
index 2120bb9..0000000
--- a/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/io/WriterOutputStream.java
+++ /dev/null
@@ -1,103 +0,0 @@
-/*
- * 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 );
- }
-}
diff --git a/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/marshaller/BigDecimalMarshaller.java b/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/marshaller/BigDecimalMarshaller.java
index 7a4acc6..c70a9d6 100644
--- a/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/marshaller/BigDecimalMarshaller.java
+++ b/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/marshaller/BigDecimalMarshaller.java
@@ -18,13 +18,13 @@
*/
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.Source;
+import org.apache.directmemory.lightning.Target;
import org.apache.directmemory.lightning.base.AbstractMarshaller;
import org.apache.directmemory.lightning.metadata.PropertyDescriptor;
@@ -41,36 +41,36 @@
}
@Override
- public void marshall( Object value, PropertyDescriptor propertyDescriptor, DataOutput dataOutput,
+ public void marshall( Object value, PropertyDescriptor propertyDescriptor, Target target,
SerializationContext serializationContext )
throws IOException
{
- if ( !writePossibleNull( value, dataOutput ) )
+ if ( !writePossibleNull( value, target ) )
{
return;
}
String representation = ( (BigDecimal) value ).toString();
byte[] data = representation.getBytes( CHARSET );
- dataOutput.writeInt( data.length );
- dataOutput.write( data );
+ target.writeInt( data.length );
+ target.writeBytes( data );
}
@Override
@SuppressWarnings( "unchecked" )
- public <V> V unmarshall( PropertyDescriptor propertyDescriptor, DataInput dataInput,
+ public <V> V unmarshall( PropertyDescriptor propertyDescriptor, Source source,
SerializationContext serializationContext )
throws IOException
{
- if ( isNull( dataInput ) )
+ if ( isNull( source ) )
{
return null;
}
- int length = dataInput.readInt();
+ int length = source.readInt();
byte[] data = new byte[length];
- dataInput.readFully( data );
+ source.readBytes( data );
return (V) new BigDecimal( new String( data, CHARSET ) );
}
diff --git a/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/marshaller/BigIntegerMarshaller.java b/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/marshaller/BigIntegerMarshaller.java
index f71f21f..85d52e6 100644
--- a/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/marshaller/BigIntegerMarshaller.java
+++ b/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/marshaller/BigIntegerMarshaller.java
@@ -18,12 +18,12 @@
*/
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.Source;
+import org.apache.directmemory.lightning.Target;
import org.apache.directmemory.lightning.base.AbstractMarshaller;
import org.apache.directmemory.lightning.metadata.PropertyDescriptor;
@@ -38,35 +38,35 @@
}
@Override
- public void marshall( Object value, PropertyDescriptor propertyDescriptor, DataOutput dataOutput,
+ public void marshall( Object value, PropertyDescriptor propertyDescriptor, Target target,
SerializationContext serializationContext )
throws IOException
{
- if ( !writePossibleNull( value, dataOutput ) )
+ if ( !writePossibleNull( value, target ) )
{
return;
}
byte[] data = ( (BigInteger) value ).toByteArray();
- dataOutput.writeInt( data.length );
- dataOutput.write( data );
+ target.writeInt( data.length );
+ target.writeBytes( data );
}
@Override
@SuppressWarnings( "unchecked" )
- public <V> V unmarshall( PropertyDescriptor propertyDescriptor, DataInput dataInput,
+ public <V> V unmarshall( PropertyDescriptor propertyDescriptor, Source source,
SerializationContext serializationContext )
throws IOException
{
- if ( isNull( dataInput ) )
+ if ( isNull( source ) )
{
return null;
}
- int length = dataInput.readInt();
+ int length = source.readInt();
byte[] data = new byte[length];
- dataInput.readFully( data );
+ source.readBytes( data );
return (V) new BigInteger( data );
}
diff --git a/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/marshaller/BooleanArrayMarshaller.java b/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/marshaller/BooleanArrayMarshaller.java
index ea696bd..f190d51 100644
--- a/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/marshaller/BooleanArrayMarshaller.java
+++ b/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/marshaller/BooleanArrayMarshaller.java
@@ -18,11 +18,11 @@
*/
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.Source;
+import org.apache.directmemory.lightning.Target;
import org.apache.directmemory.lightning.base.AbstractMarshaller;
import org.apache.directmemory.lightning.metadata.PropertyDescriptor;
@@ -37,12 +37,12 @@
}
@Override
- public void marshall( Object value, PropertyDescriptor propertyDescriptor, DataOutput dataOutput,
+ public void marshall( Object value, PropertyDescriptor propertyDescriptor, Target target,
SerializationContext serializationContext )
throws IOException
{
- if ( !writePossibleNull( value, dataOutput ) )
+ if ( !writePossibleNull( value, target ) )
{
return;
}
@@ -50,43 +50,43 @@
if ( boolean[].class == propertyDescriptor.getType() )
{
boolean[] array = (boolean[]) value;
- dataOutput.writeInt( array.length );
+ target.writeInt( array.length );
for ( boolean arrayValue : array )
{
- dataOutput.writeBoolean( arrayValue );
+ target.writeBoolean( arrayValue );
}
}
else
{
Boolean[] array = (Boolean[]) value;
- dataOutput.writeInt( array.length );
+ target.writeInt( array.length );
for ( boolean arrayValue : array )
{
- dataOutput.writeBoolean( arrayValue );
+ target.writeBoolean( arrayValue );
}
}
}
@Override
@SuppressWarnings( "unchecked" )
- public <V> V unmarshall( PropertyDescriptor propertyDescriptor, DataInput dataInput,
+ public <V> V unmarshall( PropertyDescriptor propertyDescriptor, Source source,
SerializationContext serializationContext )
throws IOException
{
- if ( isNull( dataInput ) )
+ if ( isNull( source ) )
{
return null;
}
- int size = dataInput.readInt();
+ int size = source.readInt();
if ( boolean[].class == propertyDescriptor.getType() )
{
boolean[] array = new boolean[size];
for ( int i = 0; i < size; i++ )
{
- array[i] = dataInput.readBoolean();
+ array[i] = source.readBoolean();
}
return (V) array;
@@ -96,7 +96,7 @@
Boolean[] array = new Boolean[size];
for ( int i = 0; i < size; i++ )
{
- array[i] = dataInput.readBoolean();
+ array[i] = source.readBoolean();
}
return (V) array;
diff --git a/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/marshaller/BooleanMarshaller.java b/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/marshaller/BooleanMarshaller.java
index 061ac0f..757c985 100644
--- a/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/marshaller/BooleanMarshaller.java
+++ b/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/marshaller/BooleanMarshaller.java
@@ -18,11 +18,11 @@
*/
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.Source;
+import org.apache.directmemory.lightning.Target;
import org.apache.directmemory.lightning.base.AbstractMarshaller;
import org.apache.directmemory.lightning.metadata.PropertyDescriptor;
@@ -37,36 +37,36 @@
}
@Override
- public void marshall( Object value, PropertyDescriptor propertyDescriptor, DataOutput dataOutput,
+ public void marshall( Object value, PropertyDescriptor propertyDescriptor, Target target,
SerializationContext serializationContext )
throws IOException
{
if ( Boolean.class == propertyDescriptor.getType() )
{
- if ( !writePossibleNull( value, dataOutput ) )
+ if ( !writePossibleNull( value, target ) )
{
return;
}
}
- dataOutput.writeBoolean( (Boolean) value );
+ target.writeBoolean( (Boolean) value );
}
@Override
@SuppressWarnings( "unchecked" )
- public <V> V unmarshall( PropertyDescriptor propertyDescriptor, DataInput dataInput,
+ public <V> V unmarshall( PropertyDescriptor propertyDescriptor, Source source,
SerializationContext serializationContext )
throws IOException
{
if ( Boolean.class == propertyDescriptor.getType() )
{
- if ( isNull( dataInput ) )
+ if ( isNull( source ) )
{
return null;
}
}
- return (V) Boolean.valueOf( dataInput.readBoolean() );
+ return (V) Boolean.valueOf( source.readBoolean() );
}
}
diff --git a/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/marshaller/ByteArrayMarshaller.java b/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/marshaller/ByteArrayMarshaller.java
index a3e5c8a..2c480dd 100644
--- a/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/marshaller/ByteArrayMarshaller.java
+++ b/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/marshaller/ByteArrayMarshaller.java
@@ -18,11 +18,11 @@
*/
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.Source;
+import org.apache.directmemory.lightning.Target;
import org.apache.directmemory.lightning.base.AbstractMarshaller;
import org.apache.directmemory.lightning.metadata.PropertyDescriptor;
@@ -37,12 +37,12 @@
}
@Override
- public void marshall( Object value, PropertyDescriptor propertyDescriptor, DataOutput dataOutput,
+ public void marshall( Object value, PropertyDescriptor propertyDescriptor, Target target,
SerializationContext serializationContext )
throws IOException
{
- if ( !writePossibleNull( value, dataOutput ) )
+ if ( !writePossibleNull( value, target ) )
{
return;
}
@@ -50,43 +50,43 @@
if ( byte[].class == propertyDescriptor.getType() )
{
byte[] array = (byte[]) value;
- dataOutput.writeInt( array.length );
+ target.writeInt( array.length );
for ( byte arrayValue : array )
{
- dataOutput.writeByte( arrayValue );
+ target.writeByte( arrayValue );
}
}
else
{
Byte[] array = (Byte[]) value;
- dataOutput.writeInt( array.length );
+ target.writeInt( array.length );
for ( byte arrayValue : array )
{
- dataOutput.writeByte( arrayValue );
+ target.writeByte( arrayValue );
}
}
}
@Override
@SuppressWarnings( "unchecked" )
- public <V> V unmarshall( PropertyDescriptor propertyDescriptor, DataInput dataInput,
+ public <V> V unmarshall( PropertyDescriptor propertyDescriptor, Source source,
SerializationContext serializationContext )
throws IOException
{
- if ( isNull( dataInput ) )
+ if ( isNull( source ) )
{
return null;
}
- int size = dataInput.readInt();
+ int size = source.readInt();
if ( byte[].class == propertyDescriptor.getType() )
{
byte[] array = new byte[size];
for ( int i = 0; i < size; i++ )
{
- array[i] = dataInput.readByte();
+ array[i] = source.readByte();
}
return (V) array;
@@ -96,7 +96,7 @@
Byte[] array = new Byte[size];
for ( int i = 0; i < size; i++ )
{
- array[i] = dataInput.readByte();
+ array[i] = source.readByte();
}
return (V) array;
diff --git a/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/marshaller/ByteMarshaller.java b/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/marshaller/ByteMarshaller.java
index 0e112cf..dca31ff 100644
--- a/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/marshaller/ByteMarshaller.java
+++ b/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/marshaller/ByteMarshaller.java
@@ -18,11 +18,11 @@
*/
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.Source;
+import org.apache.directmemory.lightning.Target;
import org.apache.directmemory.lightning.base.AbstractMarshaller;
import org.apache.directmemory.lightning.metadata.PropertyDescriptor;
@@ -37,36 +37,36 @@
}
@Override
- public void marshall( Object value, PropertyDescriptor propertyDescriptor, DataOutput dataOutput,
+ public void marshall( Object value, PropertyDescriptor propertyDescriptor, Target target,
SerializationContext serializationContext )
throws IOException
{
if ( Byte.class == propertyDescriptor.getType() )
{
- if ( !writePossibleNull( value, dataOutput ) )
+ if ( !writePossibleNull( value, target ) )
{
return;
}
}
- dataOutput.writeByte( (Byte) value );
+ target.writeByte( (Byte) value );
}
@Override
@SuppressWarnings( "unchecked" )
- public <V> V unmarshall( PropertyDescriptor propertyDescriptor, DataInput dataInput,
+ public <V> V unmarshall( PropertyDescriptor propertyDescriptor, Source source,
SerializationContext serializationContext )
throws IOException
{
if ( Byte.class == propertyDescriptor.getType() )
{
- if ( isNull( dataInput ) )
+ if ( isNull( source ) )
{
return null;
}
}
- return (V) Byte.valueOf( dataInput.readByte() );
+ return (V) Byte.valueOf( source.readByte() );
}
}
diff --git a/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/marshaller/CharacterArrayMarshaller.java b/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/marshaller/CharacterArrayMarshaller.java
index bb19e74..c4682a7 100644
--- a/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/marshaller/CharacterArrayMarshaller.java
+++ b/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/marshaller/CharacterArrayMarshaller.java
@@ -18,11 +18,11 @@
*/
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.Source;
+import org.apache.directmemory.lightning.Target;
import org.apache.directmemory.lightning.base.AbstractMarshaller;
import org.apache.directmemory.lightning.metadata.PropertyDescriptor;
@@ -37,12 +37,12 @@
}
@Override
- public void marshall( Object value, PropertyDescriptor propertyDescriptor, DataOutput dataOutput,
+ public void marshall( Object value, PropertyDescriptor propertyDescriptor, Target target,
SerializationContext serializationContext )
throws IOException
{
- if ( !writePossibleNull( value, dataOutput ) )
+ if ( !writePossibleNull( value, target ) )
{
return;
}
@@ -50,43 +50,43 @@
if ( char[].class == propertyDescriptor.getType() )
{
char[] array = (char[]) value;
- dataOutput.writeInt( array.length );
+ target.writeInt( array.length );
for ( char arrayValue : array )
{
- dataOutput.writeChar( arrayValue );
+ target.writeChar( arrayValue );
}
}
else
{
Character[] array = (Character[]) value;
- dataOutput.writeInt( array.length );
+ target.writeInt( array.length );
for ( char arrayValue : array )
{
- dataOutput.writeChar( arrayValue );
+ target.writeChar( arrayValue );
}
}
}
@Override
@SuppressWarnings( "unchecked" )
- public <V> V unmarshall( PropertyDescriptor propertyDescriptor, DataInput dataInput,
+ public <V> V unmarshall( PropertyDescriptor propertyDescriptor, Source source,
SerializationContext serializationContext )
throws IOException
{
- if ( isNull( dataInput ) )
+ if ( isNull( source ) )
{
return null;
}
- int size = dataInput.readInt();
+ int size = source.readInt();
if ( char[].class == propertyDescriptor.getType() )
{
char[] array = new char[size];
for ( int i = 0; i < size; i++ )
{
- array[i] = dataInput.readChar();
+ array[i] = source.readChar();
}
return (V) array;
@@ -96,7 +96,7 @@
Character[] array = new Character[size];
for ( int i = 0; i < size; i++ )
{
- array[i] = dataInput.readChar();
+ array[i] = source.readChar();
}
return (V) array;
diff --git a/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/marshaller/CharacterMarshaller.java b/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/marshaller/CharacterMarshaller.java
index 337bdff..37ac467 100644
--- a/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/marshaller/CharacterMarshaller.java
+++ b/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/marshaller/CharacterMarshaller.java
@@ -18,11 +18,11 @@
*/
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.Source;
+import org.apache.directmemory.lightning.Target;
import org.apache.directmemory.lightning.base.AbstractMarshaller;
import org.apache.directmemory.lightning.metadata.PropertyDescriptor;
@@ -37,36 +37,36 @@
}
@Override
- public void marshall( Object value, PropertyDescriptor propertyDescriptor, DataOutput dataOutput,
+ public void marshall( Object value, PropertyDescriptor propertyDescriptor, Target target,
SerializationContext serializationContext )
throws IOException
{
if ( Character.class == propertyDescriptor.getType() )
{
- if ( !writePossibleNull( value, dataOutput ) )
+ if ( !writePossibleNull( value, target ) )
{
return;
}
}
- dataOutput.writeChar( (Character) value );
+ target.writeChar( (Character) value );
}
@Override
@SuppressWarnings( "unchecked" )
- public <V> V unmarshall( PropertyDescriptor propertyDescriptor, DataInput dataInput,
+ public <V> V unmarshall( PropertyDescriptor propertyDescriptor, Source source,
SerializationContext serializationContext )
throws IOException
{
if ( Character.class == propertyDescriptor.getType() )
{
- if ( isNull( dataInput ) )
+ if ( isNull( source ) )
{
return null;
}
}
- return (V) Character.valueOf( dataInput.readChar() );
+ return (V) Character.valueOf( source.readChar() );
}
}
diff --git a/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/marshaller/DoubleArrayMarshaller.java b/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/marshaller/DoubleArrayMarshaller.java
index 7acdaec..02cfb5c 100644
--- a/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/marshaller/DoubleArrayMarshaller.java
+++ b/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/marshaller/DoubleArrayMarshaller.java
@@ -18,11 +18,11 @@
*/
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.Source;
+import org.apache.directmemory.lightning.Target;
import org.apache.directmemory.lightning.base.AbstractMarshaller;
import org.apache.directmemory.lightning.metadata.PropertyDescriptor;
@@ -37,12 +37,12 @@
}
@Override
- public void marshall( Object value, PropertyDescriptor propertyDescriptor, DataOutput dataOutput,
+ public void marshall( Object value, PropertyDescriptor propertyDescriptor, Target target,
SerializationContext serializationContext )
throws IOException
{
- if ( !writePossibleNull( value, dataOutput ) )
+ if ( !writePossibleNull( value, target ) )
{
return;
}
@@ -50,43 +50,43 @@
if ( double[].class == propertyDescriptor.getType() )
{
double[] array = (double[]) value;
- dataOutput.writeInt( array.length );
+ target.writeInt( array.length );
for ( double arrayValue : array )
{
- dataOutput.writeDouble( arrayValue );
+ target.writeDouble( arrayValue );
}
}
else
{
Double[] array = (Double[]) value;
- dataOutput.writeInt( array.length );
+ target.writeInt( array.length );
for ( double arrayValue : array )
{
- dataOutput.writeDouble( arrayValue );
+ target.writeDouble( arrayValue );
}
}
}
@Override
@SuppressWarnings( "unchecked" )
- public <V> V unmarshall( PropertyDescriptor propertyDescriptor, DataInput dataInput,
+ public <V> V unmarshall( PropertyDescriptor propertyDescriptor, Source source,
SerializationContext serializationContext )
throws IOException
{
- if ( isNull( dataInput ) )
+ if ( isNull( source ) )
{
return null;
}
- int size = dataInput.readInt();
+ int size = source.readInt();
if ( double[].class == propertyDescriptor.getType() )
{
double[] array = new double[size];
for ( int i = 0; i < size; i++ )
{
- array[i] = dataInput.readDouble();
+ array[i] = source.readDouble();
}
return (V) array;
@@ -96,7 +96,7 @@
Double[] array = new Double[size];
for ( int i = 0; i < size; i++ )
{
- array[i] = dataInput.readDouble();
+ array[i] = source.readDouble();
}
return (V) array;
diff --git a/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/marshaller/DoubleMarshaller.java b/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/marshaller/DoubleMarshaller.java
index a668f70..22c6327 100644
--- a/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/marshaller/DoubleMarshaller.java
+++ b/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/marshaller/DoubleMarshaller.java
@@ -18,11 +18,11 @@
*/
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.Source;
+import org.apache.directmemory.lightning.Target;
import org.apache.directmemory.lightning.base.AbstractMarshaller;
import org.apache.directmemory.lightning.metadata.PropertyDescriptor;
@@ -37,36 +37,36 @@
}
@Override
- public void marshall( Object value, PropertyDescriptor propertyDescriptor, DataOutput dataOutput,
+ public void marshall( Object value, PropertyDescriptor propertyDescriptor, Target target,
SerializationContext serializationContext )
throws IOException
{
if ( Double.class == propertyDescriptor.getType() )
{
- if ( !writePossibleNull( value, dataOutput ) )
+ if ( !writePossibleNull( value, target ) )
{
return;
}
}
- dataOutput.writeDouble( (Double) value );
+ target.writeDouble( (Double) value );
}
@Override
@SuppressWarnings( "unchecked" )
- public <V> V unmarshall( PropertyDescriptor propertyDescriptor, DataInput dataInput,
+ public <V> V unmarshall( PropertyDescriptor propertyDescriptor, Source source,
SerializationContext serializationContext )
throws IOException
{
if ( Double.class == propertyDescriptor.getType() )
{
- if ( isNull( dataInput ) )
+ if ( isNull( source ) )
{
return null;
}
}
- return (V) Double.valueOf( dataInput.readDouble() );
+ return (V) Double.valueOf( source.readDouble() );
}
}
diff --git a/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/marshaller/EnumMarshaller.java b/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/marshaller/EnumMarshaller.java
index 907dc79..047567e 100644
--- a/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/marshaller/EnumMarshaller.java
+++ b/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/marshaller/EnumMarshaller.java
@@ -18,11 +18,11 @@
*/
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.Source;
+import org.apache.directmemory.lightning.Target;
import org.apache.directmemory.lightning.base.AbstractMarshaller;
import org.apache.directmemory.lightning.metadata.PropertyDescriptor;
@@ -37,35 +37,35 @@
}
@Override
- public void marshall( Object value, PropertyDescriptor propertyDescriptor, DataOutput dataOutput,
+ public void marshall( Object value, PropertyDescriptor propertyDescriptor, Target target,
SerializationContext serializationContext )
throws IOException
{
- if ( !writePossibleNull( value, dataOutput ) )
+ if ( !writePossibleNull( value, target ) )
{
return;
}
- dataOutput.writeLong( serializationContext.getClassDefinitionContainer().getClassDefinitionByType( propertyDescriptor.getType() ).getId() );
- dataOutput.writeInt( ( (Enum<?>) value ).ordinal() );
+ target.writeLong( serializationContext.getClassDefinitionContainer().getClassDefinitionByType( propertyDescriptor.getType() ).getId() );
+ target.writeInt( ( (Enum<?>) value ).ordinal() );
}
@Override
@SuppressWarnings( "unchecked" )
- public <V> V unmarshall( PropertyDescriptor propertyDescriptor, DataInput dataInput,
+ public <V> V unmarshall( PropertyDescriptor propertyDescriptor, Source source,
SerializationContext serializationContext )
throws IOException
{
- if ( isNull( dataInput ) )
+ if ( isNull( source ) )
{
return null;
}
- long typeId = dataInput.readLong();
+ long typeId = source.readLong();
Class<?> propertyType = serializationContext.getClassDefinitionContainer().getTypeById( typeId );
- int ordinal = dataInput.readInt();
+ int ordinal = source.readInt();
Enum<?>[] values = ( (Class<Enum<?>>) propertyType ).getEnumConstants();
for ( Enum<?> value : values )
{
diff --git a/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/marshaller/ExternalizableMarshaller.java b/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/marshaller/ExternalizableMarshaller.java
index cb59667..ce6f8af 100644
--- a/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/marshaller/ExternalizableMarshaller.java
+++ b/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/marshaller/ExternalizableMarshaller.java
@@ -18,14 +18,16 @@
*/
package org.apache.directmemory.lightning.internal.marshaller;
-import java.io.DataInput;
-import java.io.DataOutput;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
import java.io.Externalizable;
import java.io.IOException;
-import java.io.ObjectInput;
-import java.io.ObjectOutput;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
import org.apache.directmemory.lightning.SerializationContext;
+import org.apache.directmemory.lightning.Source;
+import org.apache.directmemory.lightning.Target;
import org.apache.directmemory.lightning.base.AbstractObjectMarshaller;
import org.apache.directmemory.lightning.metadata.PropertyDescriptor;
@@ -40,22 +42,31 @@
}
@Override
- public void marshall( Object value, PropertyDescriptor propertyDescriptor, DataOutput dataOutput,
+ public void marshall( Object value, PropertyDescriptor propertyDescriptor, Target target,
SerializationContext serializationContext )
throws IOException
{
-
- ( (Externalizable) value ).writeExternal( (ObjectOutput) dataOutput );
+ ByteArrayOutputStream stream = new ByteArrayOutputStream( 1024 );
+ ObjectOutputStream oos = new ObjectOutputStream( stream );
+ ( (Externalizable) value ).writeExternal( oos );
+ byte[] data = stream.toByteArray();
+ target.writeInt( data.length );
+ target.writeBytes( data );
}
@Override
- public <V> V unmarshall( V value, PropertyDescriptor propertyDescriptor, DataInput dataInput,
+ public <V> V unmarshall( V value, PropertyDescriptor propertyDescriptor, Source source,
SerializationContext serializationContext )
throws IOException
{
try
{
- ( (Externalizable) value ).readExternal( (ObjectInput) dataInput );
+ int length = source.readInt();
+ byte[] data = new byte[length];
+ source.readBytes( data );
+ ByteArrayInputStream stream = new ByteArrayInputStream( data );
+ ObjectInputStream ois = new ObjectInputStream( stream );
+ ( (Externalizable) value ).readExternal( ois );
return value;
}
catch ( ClassNotFoundException e )
diff --git a/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/marshaller/FloatArrayMarshaller.java b/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/marshaller/FloatArrayMarshaller.java
index 826345d..79825b3 100644
--- a/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/marshaller/FloatArrayMarshaller.java
+++ b/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/marshaller/FloatArrayMarshaller.java
@@ -18,11 +18,11 @@
*/
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.Source;
+import org.apache.directmemory.lightning.Target;
import org.apache.directmemory.lightning.base.AbstractMarshaller;
import org.apache.directmemory.lightning.metadata.PropertyDescriptor;
@@ -37,12 +37,12 @@
}
@Override
- public void marshall( Object value, PropertyDescriptor propertyDescriptor, DataOutput dataOutput,
+ public void marshall( Object value, PropertyDescriptor propertyDescriptor, Target target,
SerializationContext serializationContext )
throws IOException
{
- if ( !writePossibleNull( value, dataOutput ) )
+ if ( !writePossibleNull( value, target ) )
{
return;
}
@@ -50,43 +50,43 @@
if ( float[].class == propertyDescriptor.getType() )
{
float[] array = (float[]) value;
- dataOutput.writeInt( array.length );
+ target.writeInt( array.length );
for ( float arrayValue : array )
{
- dataOutput.writeFloat( arrayValue );
+ target.writeFloat( arrayValue );
}
}
else
{
Float[] array = (Float[]) value;
- dataOutput.writeInt( array.length );
+ target.writeInt( array.length );
for ( float arrayValue : array )
{
- dataOutput.writeFloat( arrayValue );
+ target.writeFloat( arrayValue );
}
}
}
@Override
@SuppressWarnings( "unchecked" )
- public <V> V unmarshall( PropertyDescriptor propertyDescriptor, DataInput dataInput,
+ public <V> V unmarshall( PropertyDescriptor propertyDescriptor, Source source,
SerializationContext serializationContext )
throws IOException
{
- if ( isNull( dataInput ) )
+ if ( isNull( source ) )
{
return null;
}
- int size = dataInput.readInt();
+ int size = source.readInt();
if ( float[].class == propertyDescriptor.getType() )
{
float[] array = new float[size];
for ( int i = 0; i < size; i++ )
{
- array[i] = dataInput.readFloat();
+ array[i] = source.readFloat();
}
return (V) array;
@@ -96,7 +96,7 @@
Float[] array = new Float[size];
for ( int i = 0; i < size; i++ )
{
- array[i] = dataInput.readFloat();
+ array[i] = source.readFloat();
}
return (V) array;
diff --git a/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/marshaller/FloatMarshaller.java b/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/marshaller/FloatMarshaller.java
index 0004096..ddd52b8 100644
--- a/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/marshaller/FloatMarshaller.java
+++ b/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/marshaller/FloatMarshaller.java
@@ -18,11 +18,11 @@
*/
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.Source;
+import org.apache.directmemory.lightning.Target;
import org.apache.directmemory.lightning.base.AbstractMarshaller;
import org.apache.directmemory.lightning.metadata.PropertyDescriptor;
@@ -37,36 +37,36 @@
}
@Override
- public void marshall( Object value, PropertyDescriptor propertyDescriptor, DataOutput dataOutput,
+ public void marshall( Object value, PropertyDescriptor propertyDescriptor, Target target,
SerializationContext serializationContext )
throws IOException
{
if ( Float.class == propertyDescriptor.getType() )
{
- if ( !writePossibleNull( value, dataOutput ) )
+ if ( !writePossibleNull( value, target ) )
{
return;
}
}
- dataOutput.writeFloat( (Float) value );
+ target.writeFloat( (Float) value );
}
@Override
@SuppressWarnings( "unchecked" )
- public <V> V unmarshall( PropertyDescriptor propertyDescriptor, DataInput dataInput,
+ public <V> V unmarshall( PropertyDescriptor propertyDescriptor, Source source,
SerializationContext serializationContext )
throws IOException
{
if ( Float.class == propertyDescriptor.getType() )
{
- if ( isNull( dataInput ) )
+ if ( isNull( source ) )
{
return null;
}
}
- return (V) Float.valueOf( dataInput.readFloat() );
+ return (V) Float.valueOf( source.readFloat() );
}
}
diff --git a/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/marshaller/IntegerArrayMarshaller.java b/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/marshaller/IntegerArrayMarshaller.java
index 17d0cd7..8a321f0 100644
--- a/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/marshaller/IntegerArrayMarshaller.java
+++ b/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/marshaller/IntegerArrayMarshaller.java
@@ -18,11 +18,11 @@
*/
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.Source;
+import org.apache.directmemory.lightning.Target;
import org.apache.directmemory.lightning.base.AbstractMarshaller;
import org.apache.directmemory.lightning.metadata.PropertyDescriptor;
@@ -37,12 +37,12 @@
}
@Override
- public void marshall( Object value, PropertyDescriptor propertyDescriptor, DataOutput dataOutput,
+ public void marshall( Object value, PropertyDescriptor propertyDescriptor, Target target,
SerializationContext serializationContext )
throws IOException
{
- if ( !writePossibleNull( value, dataOutput ) )
+ if ( !writePossibleNull( value, target ) )
{
return;
}
@@ -50,43 +50,43 @@
if ( int[].class == propertyDescriptor.getType() )
{
int[] array = (int[]) value;
- dataOutput.writeInt( array.length );
+ target.writeInt( array.length );
for ( int arrayValue : array )
{
- dataOutput.writeInt( arrayValue );
+ target.writeInt( arrayValue );
}
}
else
{
Integer[] array = (Integer[]) value;
- dataOutput.writeInt( array.length );
+ target.writeInt( array.length );
for ( int arrayValue : array )
{
- dataOutput.writeInt( arrayValue );
+ target.writeInt( arrayValue );
}
}
}
@Override
@SuppressWarnings( "unchecked" )
- public <V> V unmarshall( PropertyDescriptor propertyDescriptor, DataInput dataInput,
+ public <V> V unmarshall( PropertyDescriptor propertyDescriptor, Source source,
SerializationContext serializationContext )
throws IOException
{
- if ( isNull( dataInput ) )
+ if ( isNull( source ) )
{
return null;
}
- int size = dataInput.readInt();
+ int size = source.readInt();
if ( int[].class == propertyDescriptor.getType() )
{
int[] array = new int[size];
for ( int i = 0; i < size; i++ )
{
- array[i] = dataInput.readInt();
+ array[i] = source.readInt();
}
return (V) array;
@@ -96,7 +96,7 @@
Integer[] array = new Integer[size];
for ( int i = 0; i < size; i++ )
{
- array[i] = dataInput.readInt();
+ array[i] = source.readInt();
}
return (V) array;
diff --git a/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/marshaller/IntegerMarshaller.java b/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/marshaller/IntegerMarshaller.java
index 1975e9d..475d009 100644
--- a/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/marshaller/IntegerMarshaller.java
+++ b/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/marshaller/IntegerMarshaller.java
@@ -18,11 +18,11 @@
*/
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.Source;
+import org.apache.directmemory.lightning.Target;
import org.apache.directmemory.lightning.base.AbstractMarshaller;
import org.apache.directmemory.lightning.metadata.PropertyDescriptor;
@@ -37,36 +37,36 @@
}
@Override
- public void marshall( Object value, PropertyDescriptor propertyDescriptor, DataOutput dataOutput,
+ public void marshall( Object value, PropertyDescriptor propertyDescriptor, Target target,
SerializationContext serializationContext )
throws IOException
{
if ( Integer.class == propertyDescriptor.getType() )
{
- if ( !writePossibleNull( value, dataOutput ) )
+ if ( !writePossibleNull( value, target ) )
{
return;
}
}
- dataOutput.writeInt( (Integer) value );
+ target.writeInt( (Integer) value );
}
@Override
@SuppressWarnings( "unchecked" )
- public <V> V unmarshall( PropertyDescriptor propertyDescriptor, DataInput dataInput,
+ public <V> V unmarshall( PropertyDescriptor propertyDescriptor, Source source,
SerializationContext serializationContext )
throws IOException
{
if ( Integer.class == propertyDescriptor.getType() )
{
- if ( isNull( dataInput ) )
+ if ( isNull( source ) )
{
return null;
}
}
- return (V) Integer.valueOf( dataInput.readInt() );
+ return (V) Integer.valueOf( source.readInt() );
}
}
diff --git a/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/marshaller/ListMarshaller.java b/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/marshaller/ListMarshaller.java
index ff5a9c4..2e1bceb 100644
--- a/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/marshaller/ListMarshaller.java
+++ b/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/marshaller/ListMarshaller.java
@@ -18,8 +18,6 @@
*/
package org.apache.directmemory.lightning.internal.marshaller;
-import java.io.DataInput;
-import java.io.DataOutput;
import java.io.IOException;
import java.lang.reflect.Type;
import java.util.ArrayList;
@@ -28,6 +26,8 @@
import org.apache.directmemory.lightning.Marshaller;
import org.apache.directmemory.lightning.SerializationContext;
+import org.apache.directmemory.lightning.Source;
+import org.apache.directmemory.lightning.Target;
import org.apache.directmemory.lightning.TypeBindableMarshaller;
import org.apache.directmemory.lightning.base.AbstractMarshaller;
import org.apache.directmemory.lightning.exceptions.SerializerExecutionException;
@@ -62,15 +62,15 @@
}
@Override
- public void marshall( Object value, PropertyDescriptor propertyDescriptor, DataOutput dataOutput,
+ public void marshall( Object value, PropertyDescriptor propertyDescriptor, Target target,
SerializationContext serializationContext )
throws IOException
{
- if ( writePossibleNull( value, dataOutput ) )
+ if ( writePossibleNull( value, target ) )
{
List<?> list = (List<?>) value;
- dataOutput.writeInt( list.size() );
+ target.writeInt( list.size() );
Marshaller marshaller = null;
ClassDefinition classDefinition = null;
@@ -87,7 +87,7 @@
for ( Object entry : list )
{
- if ( writePossibleNull( entry, dataOutput ) )
+ if ( writePossibleNull( entry, target ) )
{
if ( listType == null )
{
@@ -104,8 +104,8 @@
throw new SerializerExecutionException( "No ClassDefinition found for type " + entry.getClass() );
}
- dataOutput.writeLong( classDefinition.getId() );
- marshaller.marshall( entry, pd, dataOutput, serializationContext );
+ target.writeLong( classDefinition.getId() );
+ marshaller.marshall( entry, pd, target, serializationContext );
}
}
}
@@ -113,28 +113,28 @@
@Override
@SuppressWarnings( { "rawtypes", "unchecked" } )
- public <V> V unmarshall( PropertyDescriptor propertyDescriptor, DataInput dataInput,
+ public <V> V unmarshall( PropertyDescriptor propertyDescriptor, Source source,
SerializationContext serializationContext )
throws IOException
{
- if ( isNull( dataInput ) )
+ if ( isNull( source ) )
{
return null;
}
- int size = dataInput.readInt();
+ int size = source.readInt();
List list = new ArrayList( size );
if ( size > 0 )
{
for ( int i = 0; i < size; i++ )
{
- if ( isNull( dataInput ) )
+ if ( isNull( source ) )
{
list.add( null );
}
else
{
- long classId = dataInput.readLong();
+ long classId = source.readLong();
ClassDefinition classDefinition =
serializationContext.getClassDefinitionContainer().getClassDefinitionById( classId );
@@ -152,7 +152,7 @@
PropertyDescriptor pd =
new CheatPropertyDescriptor( propertyDescriptor.getPropertyName() + "List",
classDefinition.getType(), marshaller );
- list.add( marshaller.unmarshall( pd, dataInput, serializationContext ) );
+ list.add( marshaller.unmarshall( pd, source, serializationContext ) );
}
}
}
diff --git a/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/marshaller/LongArrayMarshaller.java b/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/marshaller/LongArrayMarshaller.java
index 8594aaf..59f91e8 100644
--- a/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/marshaller/LongArrayMarshaller.java
+++ b/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/marshaller/LongArrayMarshaller.java
@@ -18,11 +18,11 @@
*/
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.Source;
+import org.apache.directmemory.lightning.Target;
import org.apache.directmemory.lightning.base.AbstractMarshaller;
import org.apache.directmemory.lightning.metadata.PropertyDescriptor;
@@ -37,12 +37,12 @@
}
@Override
- public void marshall( Object value, PropertyDescriptor propertyDescriptor, DataOutput dataOutput,
+ public void marshall( Object value, PropertyDescriptor propertyDescriptor, Target target,
SerializationContext serializationContext )
throws IOException
{
- if ( !writePossibleNull( value, dataOutput ) )
+ if ( !writePossibleNull( value, target ) )
{
return;
}
@@ -50,43 +50,43 @@
if ( long[].class == propertyDescriptor.getType() )
{
long[] array = (long[]) value;
- dataOutput.writeInt( array.length );
+ target.writeInt( array.length );
for ( long arrayValue : array )
{
- dataOutput.writeLong( arrayValue );
+ target.writeLong( arrayValue );
}
}
else
{
Long[] array = (Long[]) value;
- dataOutput.writeInt( array.length );
+ target.writeInt( array.length );
for ( long arrayValue : array )
{
- dataOutput.writeLong( arrayValue );
+ target.writeLong( arrayValue );
}
}
}
@Override
@SuppressWarnings( "unchecked" )
- public <V> V unmarshall( PropertyDescriptor propertyDescriptor, DataInput dataInput,
+ public <V> V unmarshall( PropertyDescriptor propertyDescriptor, Source source,
SerializationContext serializationContext )
throws IOException
{
- if ( isNull( dataInput ) )
+ if ( isNull( source ) )
{
return null;
}
- int size = dataInput.readInt();
+ int size = source.readInt();
if ( long[].class == propertyDescriptor.getType() )
{
long[] array = new long[size];
for ( int i = 0; i < size; i++ )
{
- array[i] = dataInput.readLong();
+ array[i] = source.readLong();
}
return (V) array;
@@ -96,7 +96,7 @@
Long[] array = new Long[size];
for ( int i = 0; i < size; i++ )
{
- array[i] = dataInput.readLong();
+ array[i] = source.readLong();
}
return (V) array;
diff --git a/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/marshaller/LongMarshaller.java b/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/marshaller/LongMarshaller.java
index cf53a49..199e21b 100644
--- a/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/marshaller/LongMarshaller.java
+++ b/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/marshaller/LongMarshaller.java
@@ -18,11 +18,11 @@
*/
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.Source;
+import org.apache.directmemory.lightning.Target;
import org.apache.directmemory.lightning.base.AbstractMarshaller;
import org.apache.directmemory.lightning.metadata.PropertyDescriptor;
@@ -37,36 +37,36 @@
}
@Override
- public void marshall( Object value, PropertyDescriptor propertyDescriptor, DataOutput dataOutput,
+ public void marshall( Object value, PropertyDescriptor propertyDescriptor, Target target,
SerializationContext serializationContext )
throws IOException
{
if ( Long.class == propertyDescriptor.getType() )
{
- if ( !writePossibleNull( value, dataOutput ) )
+ if ( !writePossibleNull( value, target ) )
{
return;
}
}
- dataOutput.writeLong( (Long) value );
+ target.writeLong( (Long) value );
}
@Override
@SuppressWarnings( "unchecked" )
- public <V> V unmarshall( PropertyDescriptor propertyDescriptor, DataInput dataInput,
+ public <V> V unmarshall( PropertyDescriptor propertyDescriptor, Source source,
SerializationContext serializationContext )
throws IOException
{
if ( Long.class == propertyDescriptor.getType() )
{
- if ( isNull( dataInput ) )
+ if ( isNull( source ) )
{
return null;
}
}
- return (V) Long.valueOf( dataInput.readLong() );
+ return (V) Long.valueOf( source.readLong() );
}
}
diff --git a/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/marshaller/MapMarshaller.java b/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/marshaller/MapMarshaller.java
index 8d6c2a7..9aca41b 100644
--- a/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/marshaller/MapMarshaller.java
+++ b/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/marshaller/MapMarshaller.java
@@ -18,8 +18,6 @@
*/
package org.apache.directmemory.lightning.internal.marshaller;
-import java.io.DataInput;
-import java.io.DataOutput;
import java.io.IOException;
import java.lang.reflect.Type;
import java.util.Arrays;
@@ -29,6 +27,8 @@
import org.apache.directmemory.lightning.Marshaller;
import org.apache.directmemory.lightning.SerializationContext;
+import org.apache.directmemory.lightning.Source;
+import org.apache.directmemory.lightning.Target;
import org.apache.directmemory.lightning.TypeBindableMarshaller;
import org.apache.directmemory.lightning.base.AbstractMarshaller;
import org.apache.directmemory.lightning.exceptions.SerializerExecutionException;
@@ -68,15 +68,15 @@
}
@Override
- public void marshall( Object value, PropertyDescriptor propertyDescriptor, DataOutput dataOutput,
+ public void marshall( Object value, PropertyDescriptor propertyDescriptor, Target target,
SerializationContext serializationContext )
throws IOException
{
- if ( writePossibleNull( value, dataOutput ) )
+ if ( writePossibleNull( value, target ) )
{
Map<?, ?> map = (Map<?, ?>) value;
- dataOutput.writeInt( map.size() );
+ target.writeInt( map.size() );
Marshaller keyMarshaller = null;
ClassDefinition keyClassDefinition = null;
@@ -129,16 +129,16 @@
}
}
- if ( writePossibleNull( entry.getKey(), dataOutput ) )
+ if ( writePossibleNull( entry.getKey(), target ) )
{
- dataOutput.writeLong( keyClassDefinition.getId() );
- keyMarshaller.marshall( entry.getKey(), keyPd, dataOutput, serializationContext );
+ target.writeLong( keyClassDefinition.getId() );
+ keyMarshaller.marshall( entry.getKey(), keyPd, target, serializationContext );
}
- if ( writePossibleNull( entry.getValue(), dataOutput ) )
+ if ( writePossibleNull( entry.getValue(), target ) )
{
- dataOutput.writeLong( valueClassDefinition.getId() );
- valueMarshaller.marshall( entry.getValue(), valuePd, dataOutput, serializationContext );
+ target.writeLong( valueClassDefinition.getId() );
+ valueMarshaller.marshall( entry.getValue(), valuePd, target, serializationContext );
}
}
}
@@ -146,25 +146,25 @@
@Override
@SuppressWarnings( { "rawtypes", "unchecked" } )
- public <V> V unmarshall( PropertyDescriptor propertyDescriptor, DataInput dataInput,
+ public <V> V unmarshall( PropertyDescriptor propertyDescriptor, Source source,
SerializationContext serializationContext )
throws IOException
{
- if ( isNull( dataInput ) )
+ if ( isNull( source ) )
{
return null;
}
- int size = dataInput.readInt();
+ int size = source.readInt();
Map map = new LinkedHashMap( size );
if ( size > 0 )
{
for ( int i = 0; i < size; i++ )
{
Object key = null;
- if ( !isNull( dataInput ) )
+ if ( !isNull( source ) )
{
- long keyClassId = dataInput.readLong();
+ long keyClassId = source.readLong();
ClassDefinition keyClassDefinition =
serializationContext.getClassDefinitionContainer().getClassDefinitionById( keyClassId );
@@ -182,13 +182,13 @@
PropertyDescriptor pd =
new CheatPropertyDescriptor( propertyDescriptor.getPropertyName() + "Key",
keyClassDefinition.getType(), keyMarshaller );
- key = keyMarshaller.unmarshall( pd, dataInput, serializationContext );
+ key = keyMarshaller.unmarshall( pd, source, serializationContext );
}
Object value = null;
- if ( !isNull( dataInput ) )
+ if ( !isNull( source ) )
{
- long valueClassId = dataInput.readLong();
+ long valueClassId = source.readLong();
ClassDefinition valueClassDefinition =
serializationContext.getClassDefinitionContainer().getClassDefinitionById( valueClassId );
@@ -206,7 +206,7 @@
PropertyDescriptor pd =
new CheatPropertyDescriptor( propertyDescriptor.getPropertyName() + "Value",
valueClassDefinition.getType(), valueMarshaller );
- value = valueMarshaller.unmarshall( pd, dataInput, serializationContext );
+ value = valueMarshaller.unmarshall( pd, source, serializationContext );
}
map.put( key, value );
diff --git a/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/marshaller/SerializableMarshaller.java b/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/marshaller/SerializableMarshaller.java
index 41f4205..344a2f6 100644
--- a/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/marshaller/SerializableMarshaller.java
+++ b/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/marshaller/SerializableMarshaller.java
@@ -18,16 +18,16 @@
*/
package org.apache.directmemory.lightning.internal.marshaller;
-import java.io.DataInput;
-import java.io.DataOutput;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
import java.io.IOException;
-import java.io.InputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
-import java.io.OutputStream;
import java.io.Serializable;
import org.apache.directmemory.lightning.SerializationContext;
+import org.apache.directmemory.lightning.Source;
+import org.apache.directmemory.lightning.Target;
import org.apache.directmemory.lightning.base.AbstractObjectMarshaller;
import org.apache.directmemory.lightning.metadata.PropertyDescriptor;
@@ -42,25 +42,33 @@
}
@Override
- public void marshall( Object value, PropertyDescriptor propertyDescriptor, DataOutput dataOutput,
+ public void marshall( Object value, PropertyDescriptor propertyDescriptor, Target target,
SerializationContext serializationContext )
throws IOException
{
- ObjectOutputStream stream = new ObjectOutputStream( (OutputStream) dataOutput );
- stream.writeObject( value );
+ ByteArrayOutputStream stream = new ByteArrayOutputStream( 1024 );
+ ObjectOutputStream oos = new ObjectOutputStream( stream );
+ oos.writeObject( value );
+ byte[] data = stream.toByteArray();
+ target.writeInt( data.length );
+ target.writeBytes( data );
}
@Override
@SuppressWarnings( "unchecked" )
- public <V> V unmarshall( V value, PropertyDescriptor propertyDescriptor, DataInput dataInput,
+ public <V> V unmarshall( V value, PropertyDescriptor propertyDescriptor, Source source,
SerializationContext serializationContext )
throws IOException
{
- ObjectInputStream stream = new ObjectInputStream( (InputStream) dataInput );
try
{
- return (V) stream.readObject();
+ int length = source.readInt();
+ byte[] data = new byte[length];
+ source.readBytes( data );
+ ByteArrayInputStream stream = new ByteArrayInputStream( data );
+ ObjectInputStream ois = new ObjectInputStream( stream );
+ return (V) ois.readObject();
}
catch ( ClassNotFoundException e )
{
diff --git a/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/marshaller/SetMarshaller.java b/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/marshaller/SetMarshaller.java
index 8341514..1ee1880 100644
--- a/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/marshaller/SetMarshaller.java
+++ b/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/marshaller/SetMarshaller.java
@@ -18,8 +18,6 @@
*/
package org.apache.directmemory.lightning.internal.marshaller;
-import java.io.DataInput;
-import java.io.DataOutput;
import java.io.IOException;
import java.lang.reflect.Type;
import java.util.Arrays;
@@ -28,6 +26,8 @@
import org.apache.directmemory.lightning.Marshaller;
import org.apache.directmemory.lightning.SerializationContext;
+import org.apache.directmemory.lightning.Source;
+import org.apache.directmemory.lightning.Target;
import org.apache.directmemory.lightning.TypeBindableMarshaller;
import org.apache.directmemory.lightning.base.AbstractMarshaller;
import org.apache.directmemory.lightning.exceptions.SerializerExecutionException;
@@ -62,15 +62,15 @@
}
@Override
- public void marshall( Object value, PropertyDescriptor propertyDescriptor, DataOutput dataOutput,
+ public void marshall( Object value, PropertyDescriptor propertyDescriptor, Target target,
SerializationContext serializationContext )
throws IOException
{
- if ( writePossibleNull( value, dataOutput ) )
+ if ( writePossibleNull( value, target ) )
{
Set<?> set = (Set<?>) value;
- dataOutput.writeInt( set.size() );
+ target.writeInt( set.size() );
Marshaller marshaller = null;
ClassDefinition classDefinition = null;
@@ -87,7 +87,7 @@
for ( Object entry : set )
{
- if ( writePossibleNull( entry, dataOutput ) )
+ if ( writePossibleNull( entry, target ) )
{
if ( setType == null )
{
@@ -99,8 +99,8 @@
entry.getClass(), marshaller );
}
- dataOutput.writeLong( classDefinition.getId() );
- marshaller.marshall( entry, pd, dataOutput, serializationContext );
+ target.writeLong( classDefinition.getId() );
+ marshaller.marshall( entry, pd, target, serializationContext );
}
}
}
@@ -108,28 +108,28 @@
@Override
@SuppressWarnings( { "rawtypes", "unchecked" } )
- public <V> V unmarshall( PropertyDescriptor propertyDescriptor, DataInput dataInput,
+ public <V> V unmarshall( PropertyDescriptor propertyDescriptor, Source source,
SerializationContext serializationContext )
throws IOException
{
- if ( isNull( dataInput ) )
+ if ( isNull( source ) )
{
return null;
}
- int size = dataInput.readInt();
+ int size = source.readInt();
Set set = new HashSet( size );
if ( size > 0 )
{
for ( int i = 0; i < size; i++ )
{
- if ( isNull( dataInput ) )
+ if ( isNull( source ) )
{
set.add( null );
}
else
{
- long classId = dataInput.readLong();
+ long classId = source.readLong();
ClassDefinition classDefinition =
serializationContext.getClassDefinitionContainer().getClassDefinitionById( classId );
@@ -147,7 +147,7 @@
PropertyDescriptor pd =
new CheatPropertyDescriptor( propertyDescriptor.getPropertyName() + "Set",
classDefinition.getType(), marshaller );
- set.add( marshaller.unmarshall( pd, dataInput, serializationContext ) );
+ set.add( marshaller.unmarshall( pd, source, serializationContext ) );
}
}
}
diff --git a/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/marshaller/ShortArrayMarshaller.java b/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/marshaller/ShortArrayMarshaller.java
index 4eaacc4..61252d2 100644
--- a/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/marshaller/ShortArrayMarshaller.java
+++ b/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/marshaller/ShortArrayMarshaller.java
@@ -18,11 +18,11 @@
*/
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.Source;
+import org.apache.directmemory.lightning.Target;
import org.apache.directmemory.lightning.base.AbstractMarshaller;
import org.apache.directmemory.lightning.metadata.PropertyDescriptor;
@@ -37,12 +37,12 @@
}
@Override
- public void marshall( Object value, PropertyDescriptor propertyDescriptor, DataOutput dataOutput,
+ public void marshall( Object value, PropertyDescriptor propertyDescriptor, Target target,
SerializationContext serializationContext )
throws IOException
{
- if ( !writePossibleNull( value, dataOutput ) )
+ if ( !writePossibleNull( value, target ) )
{
return;
}
@@ -50,43 +50,43 @@
if ( short[].class == propertyDescriptor.getType() )
{
short[] array = (short[]) value;
- dataOutput.writeInt( array.length );
+ target.writeInt( array.length );
for ( short arrayValue : array )
{
- dataOutput.writeShort( arrayValue );
+ target.writeShort( arrayValue );
}
}
else
{
Short[] array = (Short[]) value;
- dataOutput.writeInt( array.length );
+ target.writeInt( array.length );
for ( short arrayValue : array )
{
- dataOutput.writeShort( arrayValue );
+ target.writeShort( arrayValue );
}
}
}
@Override
@SuppressWarnings( "unchecked" )
- public <V> V unmarshall( PropertyDescriptor propertyDescriptor, DataInput dataInput,
+ public <V> V unmarshall( PropertyDescriptor propertyDescriptor, Source source,
SerializationContext serializationContext )
throws IOException
{
- if ( isNull( dataInput ) )
+ if ( isNull( source ) )
{
return null;
}
- int size = dataInput.readInt();
+ int size = source.readInt();
if ( short[].class == propertyDescriptor.getType() )
{
short[] array = new short[size];
for ( int i = 0; i < size; i++ )
{
- array[i] = dataInput.readShort();
+ array[i] = source.readShort();
}
return (V) array;
@@ -96,7 +96,7 @@
Short[] array = new Short[size];
for ( int i = 0; i < size; i++ )
{
- array[i] = dataInput.readShort();
+ array[i] = source.readShort();
}
return (V) array;
diff --git a/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/marshaller/ShortMarshaller.java b/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/marshaller/ShortMarshaller.java
index 590f543..be0ed87 100644
--- a/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/marshaller/ShortMarshaller.java
+++ b/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/marshaller/ShortMarshaller.java
@@ -18,11 +18,11 @@
*/
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.Source;
+import org.apache.directmemory.lightning.Target;
import org.apache.directmemory.lightning.base.AbstractMarshaller;
import org.apache.directmemory.lightning.metadata.PropertyDescriptor;
@@ -37,36 +37,36 @@
}
@Override
- public void marshall( Object value, PropertyDescriptor propertyDescriptor, DataOutput dataOutput,
+ public void marshall( Object value, PropertyDescriptor propertyDescriptor, Target target,
SerializationContext serializationContext )
throws IOException
{
if ( Short.class == propertyDescriptor.getType() )
{
- if ( !writePossibleNull( value, dataOutput ) )
+ if ( !writePossibleNull( value, target ) )
{
return;
}
}
- dataOutput.writeShort( (Short) value );
+ target.writeShort( (Short) value );
}
@Override
@SuppressWarnings( "unchecked" )
- public <V> V unmarshall( PropertyDescriptor propertyDescriptor, DataInput dataInput,
+ public <V> V unmarshall( PropertyDescriptor propertyDescriptor, Source source,
SerializationContext serializationContext )
throws IOException
{
if ( Short.class == propertyDescriptor.getType() )
{
- if ( isNull( dataInput ) )
+ if ( isNull( source ) )
{
return null;
}
}
- return (V) Short.valueOf( dataInput.readShort() );
+ return (V) Short.valueOf( source.readShort() );
}
}
diff --git a/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/marshaller/StreamedMarshaller.java b/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/marshaller/StreamedMarshaller.java
index 67a28fa..1a91057 100644
--- a/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/marshaller/StreamedMarshaller.java
+++ b/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/marshaller/StreamedMarshaller.java
@@ -18,12 +18,12 @@
*/
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.Source;
import org.apache.directmemory.lightning.Streamed;
+import org.apache.directmemory.lightning.Target;
import org.apache.directmemory.lightning.base.AbstractObjectMarshaller;
import org.apache.directmemory.lightning.metadata.PropertyDescriptor;
@@ -38,20 +38,20 @@
}
@Override
- public void marshall( Object value, PropertyDescriptor propertyDescriptor, DataOutput dataOutput,
+ public void marshall( Object value, PropertyDescriptor propertyDescriptor, Target target,
SerializationContext serializationContext )
throws IOException
{
- ( (Streamed) value ).writeTo( dataOutput );
+ ( (Streamed) value ).writeTo( target );
}
@Override
- public <V> V unmarshall( V value, PropertyDescriptor propertyDescriptor, DataInput dataInput,
+ public <V> V unmarshall( V value, PropertyDescriptor propertyDescriptor, Source source,
SerializationContext serializationContext )
throws IOException
{
- ( (Streamed) value ).readFrom( dataInput );
+ ( (Streamed) value ).readFrom( source );
return value;
}
}
diff --git a/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/marshaller/StringMarshaller.java b/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/marshaller/StringMarshaller.java
index ba8ecb0..5f9446d 100644
--- a/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/marshaller/StringMarshaller.java
+++ b/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/marshaller/StringMarshaller.java
@@ -18,11 +18,11 @@
*/
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.Source;
+import org.apache.directmemory.lightning.Target;
import org.apache.directmemory.lightning.base.AbstractMarshaller;
import org.apache.directmemory.lightning.metadata.PropertyDescriptor;
@@ -37,30 +37,30 @@
}
@Override
- public void marshall( Object value, PropertyDescriptor propertyDescriptor, DataOutput dataOutput,
+ public void marshall( Object value, PropertyDescriptor propertyDescriptor, Target target,
SerializationContext serializationContext )
throws IOException
{
- if ( !writePossibleNull( value, dataOutput ) )
+ if ( !writePossibleNull( value, target ) )
{
return;
}
- dataOutput.writeUTF( (String) value );
+ target.writeString( (String) value );
}
@Override
@SuppressWarnings( "unchecked" )
- public <V> V unmarshall( PropertyDescriptor propertyDescriptor, DataInput dataInput,
+ public <V> V unmarshall( PropertyDescriptor propertyDescriptor, Source source,
SerializationContext serializationContext )
throws IOException
{
- if ( isNull( dataInput ) )
+ if ( isNull( source ) )
{
return null;
}
- return (V) dataInput.readUTF();
+ return (V) source.readString();
}
}
diff --git a/lightning-core/src/main/java/org/apache/directmemory/lightning/io/ByteBufferSource.java b/lightning-core/src/main/java/org/apache/directmemory/lightning/io/ByteBufferSource.java
index c536edc..37bd380 100644
--- a/lightning-core/src/main/java/org/apache/directmemory/lightning/io/ByteBufferSource.java
+++ b/lightning-core/src/main/java/org/apache/directmemory/lightning/io/ByteBufferSource.java
@@ -30,6 +30,13 @@
}
@Override
+ public boolean readBoolean()
+ throws IOException
+ {
+ return readByte() == 1 ? true : false;
+ }
+
+ @Override
public int readBytes( byte[] bytes )
throws IOException
{
diff --git a/lightning-core/src/main/java/org/apache/directmemory/lightning/io/ByteBufferTarget.java b/lightning-core/src/main/java/org/apache/directmemory/lightning/io/ByteBufferTarget.java
index fb9cb8d..cd92169 100644
--- a/lightning-core/src/main/java/org/apache/directmemory/lightning/io/ByteBufferTarget.java
+++ b/lightning-core/src/main/java/org/apache/directmemory/lightning/io/ByteBufferTarget.java
@@ -30,6 +30,13 @@
}
@Override
+ public void writeBoolean( boolean value )
+ throws IOException
+ {
+ writeByte( (byte) ( value ? 1 : 0 ) );
+ }
+
+ @Override
public void writeBytes( byte[] bytes )
throws IOException
{
diff --git a/lightning-core/src/main/java/org/apache/directmemory/lightning/io/InputStreamSource.java b/lightning-core/src/main/java/org/apache/directmemory/lightning/io/InputStreamSource.java
index 45fda48..1ca8161 100644
--- a/lightning-core/src/main/java/org/apache/directmemory/lightning/io/InputStreamSource.java
+++ b/lightning-core/src/main/java/org/apache/directmemory/lightning/io/InputStreamSource.java
@@ -64,6 +64,13 @@
}
@Override
+ public boolean readBoolean()
+ throws IOException
+ {
+ return readByte() == 1 ? true : false;
+ }
+
+ @Override
public int readBytes( byte[] bytes )
throws IOException
{
@@ -88,7 +95,7 @@
public short readUnsignedByte()
throws IOException
{
- return (short) ( readByte() & 0xFF );
+ return (short) ( readByte() & 0xFF );
}
@Override
diff --git a/lightning-core/src/main/java/org/apache/directmemory/lightning/io/OutputStreamTarget.java b/lightning-core/src/main/java/org/apache/directmemory/lightning/io/OutputStreamTarget.java
index a0955e2..e4700bc 100644
--- a/lightning-core/src/main/java/org/apache/directmemory/lightning/io/OutputStreamTarget.java
+++ b/lightning-core/src/main/java/org/apache/directmemory/lightning/io/OutputStreamTarget.java
@@ -41,6 +41,13 @@
}
@Override
+ public void writeBoolean( boolean value )
+ throws IOException
+ {
+ writeByte( (byte) ( value ? 1 : 0 ) );
+ }
+
+ @Override
public void writeBytes( byte[] bytes )
throws IOException
{
diff --git a/lightning-core/src/main/java/org/apache/directmemory/lightning/io/SerializerInputStream.java b/lightning-core/src/main/java/org/apache/directmemory/lightning/io/SerializerInputStream.java
deleted file mode 100644
index 35e0133..0000000
--- a/lightning-core/src/main/java/org/apache/directmemory/lightning/io/SerializerInputStream.java
+++ /dev/null
@@ -1,292 +0,0 @@
-/*
- * 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.io;
-
-import java.io.DataInput;
-import java.io.FilterInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.ObjectInput;
-import java.io.PushbackInputStream;
-import java.io.UTFDataFormatException;
-
-import org.apache.directmemory.lightning.Serializer;
-
-/**
- * Parts of this class taken from Hazelcast project
- */
-public class SerializerInputStream
- extends FilterInputStream
- implements ObjectInput
-{
-
- private final Serializer serializer;
-
- private final byte[] longReadBuffer = new byte[8];
-
- private char lineBuffer[];
-
- public SerializerInputStream( InputStream in, Serializer serializer )
- {
- super( in );
- this.serializer = serializer;
- }
-
- @Override
- public Object readObject()
- {
- return serializer.deserialize( (DataInput) this );
- }
-
- @Override
- public void readFully( byte[] b )
- throws IOException
- {
- in.read( b );
- }
-
- @Override
- public void readFully( byte[] b, int off, int len )
- throws IOException
- {
- in.read( b, off, len );
- }
-
- @Override
- public int skipBytes( int n )
- throws IOException
- {
- return (int) in.skip( n );
- }
-
- @Override
- public boolean readBoolean()
- throws IOException
- {
- return in.read() == 1;
- }
-
- @Override
- public byte readByte()
- throws IOException
- {
- return (byte) in.read();
- }
-
- @Override
- public int readUnsignedByte()
- throws IOException
- {
- return in.read();
- }
-
- @Override
- public short readShort()
- throws IOException
- {
- int byte1 = read();
- int byte2 = read();
- return (short) ( ( byte1 << 8 ) + ( byte2 << 0 ) );
- }
-
- @Override
- public int readUnsignedShort()
- throws IOException
- {
- int byte1 = read();
- int byte2 = read();
- return (short) ( ( byte1 << 8 ) + ( byte2 << 0 ) );
- }
-
- @Override
- public char readChar()
- throws IOException
- {
- return (char) readUnsignedShort();
- }
-
- @Override
- public int readInt()
- throws IOException
- {
- final int byte1 = read();
- final int byte2 = read();
- final int byte3 = read();
- final int byte4 = read();
- return ( ( byte1 << 24 ) + ( byte2 << 16 ) + ( byte3 << 8 ) + ( byte4 << 0 ) );
- }
-
- @Override
- public long readLong()
- throws IOException
- {
- in.read( longReadBuffer );
- return ( ( (long) longReadBuffer[0] << 56 ) + ( (long) ( longReadBuffer[1] & 255 ) << 48 )
- + ( (long) ( longReadBuffer[2] & 255 ) << 40 ) + ( (long) ( longReadBuffer[3] & 255 ) << 32 )
- + ( (long) ( longReadBuffer[4] & 255 ) << 24 ) + ( ( longReadBuffer[5] & 255 ) << 16 )
- + ( ( longReadBuffer[6] & 255 ) << 8 ) + ( ( longReadBuffer[7] & 255 ) << 0 ) );
- }
-
- @Override
- public float readFloat()
- throws IOException
- {
- return Float.intBitsToFloat( readInt() );
- }
-
- @Override
- public double readDouble()
- throws IOException
- {
- return Double.longBitsToDouble( readLong() );
- }
-
- @Override
- public String readLine()
- throws IOException
- {
- char buf[] = lineBuffer;
- if ( buf == null )
- {
- buf = lineBuffer = new char[128];
- }
- int room = buf.length;
- int offset = 0;
- int c;
- loop: while ( true )
- {
- switch ( c = read() )
- {
- case -1:
- case '\n':
- break loop;
- case '\r':
- final int c2 = read();
- if ( ( c2 != '\n' ) && ( c2 != -1 ) )
- {
- new PushbackInputStream( this ).unread( c2 );
- }
- break loop;
- default:
- if ( --room < 0 )
- {
- buf = new char[offset + 128];
- room = buf.length - offset - 1;
- System.arraycopy( lineBuffer, 0, buf, 0, offset );
- lineBuffer = buf;
- }
- buf[offset++] = (char) c;
- break;
- }
- }
- if ( ( c == -1 ) && ( offset == 0 ) )
- {
- return null;
- }
- return String.copyValueOf( buf, 0, offset );
-
- }
-
- @Override
- public String readUTF()
- throws IOException
- {
- boolean isNull = readBoolean();
- if ( isNull )
- return null;
- int length = readInt();
- StringBuilder result = new StringBuilder( length );
- int chunkSize = length / SerializerOutputStream.STRING_CHUNK_SIZE + 1;
- while ( chunkSize > 0 )
- {
- result.append( readShortUTF() );
- chunkSize--;
- }
- return result.toString();
- }
-
- private final String readShortUTF()
- throws IOException
- {
- final int utflen = readShort();
- byte[] bytearr = null;
- char[] chararr = null;
- bytearr = new byte[utflen];
- chararr = new char[utflen];
- int c, char2, char3;
- int count = 0;
- int chararr_count = 0;
- readFully( bytearr, 0, utflen );
- while ( count < utflen )
- {
- c = bytearr[count] & 0xff;
- if ( c > 127 )
- break;
- count++;
- chararr[chararr_count++] = (char) c;
- }
- while ( count < utflen )
- {
- c = bytearr[count] & 0xff;
- switch ( c >> 4 )
- {
- case 0:
- case 1:
- case 2:
- case 3:
- case 4:
- case 5:
- case 6:
- case 7:
- /* 0xxxxxxx */
- count++;
- chararr[chararr_count++] = (char) c;
- break;
- case 12:
- case 13:
- /* 110x xxxx 10xx xxxx */
- count += 2;
- if ( count > utflen )
- throw new UTFDataFormatException( "malformed input: partial character at end" );
- char2 = bytearr[count - 1];
- if ( ( char2 & 0xC0 ) != 0x80 )
- throw new UTFDataFormatException( "malformed input around byte " + count );
- chararr[chararr_count++] = (char) ( ( ( c & 0x1F ) << 6 ) | ( char2 & 0x3F ) );
- break;
- case 14:
- /* 1110 xxxx 10xx xxxx 10xx xxxx */
- count += 3;
- if ( count > utflen )
- throw new UTFDataFormatException( "malformed input: partial character at end" );
- char2 = bytearr[count - 2];
- char3 = bytearr[count - 1];
- if ( ( ( char2 & 0xC0 ) != 0x80 ) || ( ( char3 & 0xC0 ) != 0x80 ) )
- throw new UTFDataFormatException( "malformed input around byte " + ( count - 1 ) );
- chararr[chararr_count++] =
- (char) ( ( ( c & 0x0F ) << 12 ) | ( ( char2 & 0x3F ) << 6 ) | ( ( char3 & 0x3F ) << 0 ) );
- break;
- default:
- /* 10xx xxxx, 1111 xxxx */
- throw new UTFDataFormatException( "malformed input around byte " + count );
- }
- }
- // The number of chars produced may be less than utflen
- return new String( chararr, 0, chararr_count );
- }
-}
diff --git a/lightning-core/src/main/java/org/apache/directmemory/lightning/io/SerializerOutputStream.java b/lightning-core/src/main/java/org/apache/directmemory/lightning/io/SerializerOutputStream.java
deleted file mode 100644
index 14eabc1..0000000
--- a/lightning-core/src/main/java/org/apache/directmemory/lightning/io/SerializerOutputStream.java
+++ /dev/null
@@ -1,264 +0,0 @@
-/*
- * 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.io;
-
-import java.io.DataOutput;
-import java.io.FilterOutputStream;
-import java.io.IOException;
-import java.io.ObjectOutput;
-import java.io.OutputStream;
-
-import org.apache.directmemory.lightning.Serializer;
-
-/**
- * Parts of this class taken from Hazelcast project
- */
-public class SerializerOutputStream
- extends FilterOutputStream
- implements ObjectOutput
-{
-
- static final int STRING_CHUNK_SIZE = 16 * 1024;
-
- private final Serializer serializer;
-
- private int written = 0;
-
- public SerializerOutputStream( OutputStream out, Serializer serializer )
- {
- super( out );
- this.serializer = serializer;
- }
-
- @Override
- public void writeObject( Object object )
- {
- serializer.serialize( object, (DataOutput) this );
- }
-
- @Override
- public synchronized void write( int b )
- throws IOException
- {
- out.write( b );
- increaseWritten( 1 );
- }
-
- @Override
- public synchronized void write( byte[] b, int off, int len )
- throws IOException
- {
- out.write( b, off, len );
- increaseWritten( len );
- }
-
- @Override
- public void writeBoolean( boolean v )
- throws IOException
- {
- out.write( v ? 1 : 0 );
- }
-
- @Override
- public void writeByte( int v )
- throws IOException
- {
- out.write( v );
- increaseWritten( 1 );
- }
-
- @Override
- public void writeShort( int v )
- throws IOException
- {
- out.write( ( v >>> 8 ) & 0xFF );
- out.write( ( v >>> 0 ) & 0xFF );
- increaseWritten( 2 );
- }
-
- @Override
- public void writeChar( int v )
- throws IOException
- {
- out.write( ( v >>> 8 ) & 0xFF );
- out.write( ( v >>> 0 ) & 0xFF );
- increaseWritten( 2 );
- }
-
- @Override
- public void writeInt( int v )
- throws IOException
- {
- out.write( ( v >>> 24 ) & 0xFF );
- out.write( ( v >>> 16 ) & 0xFF );
- out.write( ( v >>> 8 ) & 0xFF );
- out.write( ( v >>> 0 ) & 0xFF );
- increaseWritten( 4 );
- }
-
- @Override
- public void writeLong( long v )
- throws IOException
- {
- byte[] buffer = new byte[8];
- buffer[0] = (byte) ( v >>> 56 );
- buffer[1] = (byte) ( v >>> 48 );
- buffer[2] = (byte) ( v >>> 40 );
- buffer[3] = (byte) ( v >>> 32 );
- buffer[4] = (byte) ( v >>> 24 );
- buffer[5] = (byte) ( v >>> 16 );
- buffer[6] = (byte) ( v >>> 8 );
- buffer[7] = (byte) ( v >>> 0 );
- out.write( buffer, 0, 8 );
- increaseWritten( 8 );
- }
-
- @Override
- public void writeFloat( float v )
- throws IOException
- {
- writeInt( Float.floatToIntBits( v ) );
- }
-
- @Override
- public void writeDouble( double v )
- throws IOException
- {
- writeLong( Double.doubleToLongBits( v ) );
- }
-
- @Override
- public void writeBytes( String s )
- throws IOException
- {
- int len = s.length();
- for ( int i = 0; i < len; i++ )
- {
- out.write( (byte) s.charAt( i ) );
- }
- increaseWritten( len );
- }
-
- @Override
- public void writeChars( String s )
- throws IOException
- {
- int len = s.length();
- for ( int i = 0; i < len; i++ )
- {
- int v = s.charAt( i );
- out.write( ( v >>> 8 ) & 0xFF );
- out.write( ( v >>> 0 ) & 0xFF );
- }
- increaseWritten( len * 2 );
- }
-
- @Override
- public void writeUTF( String s )
- throws IOException
- {
- boolean isNull = ( s == null );
- writeBoolean( isNull );
- if ( isNull )
- return;
- int length = s.length();
- writeInt( length );
- int chunkSize = length / STRING_CHUNK_SIZE + 1;
- for ( int i = 0; i < chunkSize; i++ )
- {
- int beginIndex = Math.max( 0, i * STRING_CHUNK_SIZE - 1 );
- int endIndex = Math.min( ( i + 1 ) * STRING_CHUNK_SIZE - 1, length );
- writeShortUTF( s.substring( beginIndex, endIndex ) );
- }
- }
-
- private final void writeShortUTF( final String str )
- throws IOException
- {
- final int strlen = str.length();
- int utflen = 0;
- int c, count = 0;
- /* use charAt instead of copying String to char array */
- for ( int i = 0; i < strlen; i++ )
- {
- c = str.charAt( i );
- if ( ( c >= 0x0001 ) && ( c <= 0x007F ) )
- {
- utflen++;
- }
- else if ( c > 0x07FF )
- {
- utflen += 3;
- }
- else
- {
- utflen += 2;
- }
- }
- // if (utflen > 65535)
- // throw new UTFDataFormatException("encoded string too long: " + utflen
- // + " bytes");
- final byte[] bytearr = new byte[utflen + 2];
- bytearr[count++] = (byte) ( ( utflen >>> 8 ) & 0xFF );
- bytearr[count++] = (byte) ( ( utflen ) & 0xFF );
- int i;
- for ( i = 0; i < strlen; i++ )
- {
- c = str.charAt( i );
- if ( !( ( c >= 0x0001 ) && ( c <= 0x007F ) ) )
- break;
- bytearr[count++] = (byte) c;
- }
- for ( ; i < strlen; i++ )
- {
- c = str.charAt( i );
- if ( ( c >= 0x0001 ) && ( c <= 0x007F ) )
- {
- bytearr[count++] = (byte) c;
- }
- else if ( c > 0x07FF )
- {
- bytearr[count++] = (byte) ( 0xE0 | ( ( c >> 12 ) & 0x0F ) );
- bytearr[count++] = (byte) ( 0x80 | ( ( c >> 6 ) & 0x3F ) );
- bytearr[count++] = (byte) ( 0x80 | ( ( c ) & 0x3F ) );
- }
- else
- {
- bytearr[count++] = (byte) ( 0xC0 | ( ( c >> 6 ) & 0x1F ) );
- bytearr[count++] = (byte) ( 0x80 | ( ( c ) & 0x3F ) );
- }
- }
- write( bytearr, 0, utflen + 2 );
- }
-
- public int size()
- {
- return written;
- }
-
- private void increaseWritten( int count )
- {
- int temp = written + count;
- if ( temp < 0 )
- {
- temp = Integer.MAX_VALUE;
- }
- written = temp;
- }
-}