You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directmemory.apache.org by no...@apache.org on 2012/11/02 20:41:53 UTC
svn commit: r1405123 - in
/directmemory/lightning/trunk/lightning-core/src/main/java/org/apache/directmemory/lightning:
./ internal/io/ io/
Author: noctarius
Date: Fri Nov 2 19:41:52 2012
New Revision: 1405123
URL: http://svn.apache.org/viewvc?rev=1405123&view=rev
Log:
Started implementation of special source / target interfaces to unify the internal handling of system specific buffers (for example MemoryBuffer in DirectMemory or ChannelBuffer in Netty)
Added:
directmemory/lightning/trunk/lightning-core/src/main/java/org/apache/directmemory/lightning/Source.java
directmemory/lightning/trunk/lightning-core/src/main/java/org/apache/directmemory/lightning/Target.java
directmemory/lightning/trunk/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/io/ByteOrderUtils.java
directmemory/lightning/trunk/lightning-core/src/main/java/org/apache/directmemory/lightning/io/ByteBufferSource.java
directmemory/lightning/trunk/lightning-core/src/main/java/org/apache/directmemory/lightning/io/ByteBufferTarget.java
directmemory/lightning/trunk/lightning-core/src/main/java/org/apache/directmemory/lightning/io/InputStreamSource.java
directmemory/lightning/trunk/lightning-core/src/main/java/org/apache/directmemory/lightning/io/OutputStreamTarget.java
Added: directmemory/lightning/trunk/lightning-core/src/main/java/org/apache/directmemory/lightning/Source.java
URL: http://svn.apache.org/viewvc/directmemory/lightning/trunk/lightning-core/src/main/java/org/apache/directmemory/lightning/Source.java?rev=1405123&view=auto
==============================================================================
--- directmemory/lightning/trunk/lightning-core/src/main/java/org/apache/directmemory/lightning/Source.java (added)
+++ directmemory/lightning/trunk/lightning-core/src/main/java/org/apache/directmemory/lightning/Source.java Fri Nov 2 19:41:52 2012
@@ -0,0 +1,66 @@
+/*
+ * 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;
+
+import java.io.IOException;
+import java.nio.ByteOrder;
+
+public interface Source
+{
+
+ ByteOrder byteOrder();
+
+ long readableBytes();
+
+ int readBytes( byte[] bytes )
+ throws IOException;
+
+ int readBytes( byte[] bytes, int offset, int length )
+ throws IOException;
+
+ byte readByte()
+ throws IOException;
+
+ short readUnsignedByte()
+ throws IOException;
+
+ short readShort()
+ throws IOException;
+
+ char readChar()
+ throws IOException;
+
+ int readInt()
+ throws IOException;
+
+ long readLong()
+ throws IOException;
+
+ float readFloat()
+ throws IOException;
+
+ double readDouble()
+ throws IOException;
+
+ void clear()
+ throws IOException;
+
+ void free()
+ throws IOException;
+}
Added: directmemory/lightning/trunk/lightning-core/src/main/java/org/apache/directmemory/lightning/Target.java
URL: http://svn.apache.org/viewvc/directmemory/lightning/trunk/lightning-core/src/main/java/org/apache/directmemory/lightning/Target.java?rev=1405123&view=auto
==============================================================================
--- directmemory/lightning/trunk/lightning-core/src/main/java/org/apache/directmemory/lightning/Target.java (added)
+++ directmemory/lightning/trunk/lightning-core/src/main/java/org/apache/directmemory/lightning/Target.java Fri Nov 2 19:41:52 2012
@@ -0,0 +1,67 @@
+/*
+ * 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;
+
+import java.io.IOException;
+import java.nio.ByteOrder;
+
+public interface Target
+{
+
+ ByteOrder byteOrder();
+
+ long writtenBytes();
+
+ void writeBytes( byte[] bytes )
+ throws IOException;
+
+ void writeBytes( byte[] bytes, int offset, int length )
+ throws IOException;
+
+ void writeByte( byte value )
+ throws IOException;
+
+ void writeUnsignedByte( short value )
+ throws IOException;
+
+ void writeShort( short value )
+ throws IOException;
+
+ void writeChar( char value )
+ throws IOException;
+
+ void writeInt( int value )
+ throws IOException;
+
+ void writeLong( long value )
+ throws IOException;
+
+ void writeFloat( float value )
+ throws IOException;
+
+ void writeDouble( double value )
+ throws IOException;
+
+ void clear()
+ throws IOException;
+
+ void free()
+ throws IOException;
+
+}
Added: directmemory/lightning/trunk/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/io/ByteOrderUtils.java
URL: http://svn.apache.org/viewvc/directmemory/lightning/trunk/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/io/ByteOrderUtils.java?rev=1405123&view=auto
==============================================================================
--- directmemory/lightning/trunk/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/io/ByteOrderUtils.java (added)
+++ directmemory/lightning/trunk/lightning-core/src/main/java/org/apache/directmemory/lightning/internal/io/ByteOrderUtils.java Fri Nov 2 19:41:52 2012
@@ -0,0 +1,173 @@
+/*
+ * 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 org.apache.directmemory.lightning.Source;
+import org.apache.directmemory.lightning.Target;
+
+public class ByteOrderUtils
+{
+
+ public static void putShort( short value, Target target, boolean bigEndian )
+ throws IOException
+ {
+ if ( bigEndian )
+ {
+ target.writeByte( (byte) ( value >> 8 ) );
+ target.writeByte( (byte) ( value >> 0 ) );
+ }
+ else
+ {
+ target.writeByte( (byte) ( value >> 0 ) );
+ target.writeByte( (byte) ( value >> 8 ) );
+ }
+ }
+
+ public static short getShort( Source source, boolean bigEndian )
+ throws IOException
+ {
+ if ( bigEndian )
+ {
+ byte b1 = source.readByte();
+ byte b0 = source.readByte();
+ return buildShort( b1, b0 );
+ }
+ else
+ {
+ byte b0 = source.readByte();
+ byte b1 = source.readByte();
+ return buildShort( b1, b0 );
+ }
+ }
+
+ public static void putInt( int value, Target target, boolean bigEndian )
+ throws IOException
+ {
+ if ( bigEndian )
+ {
+ target.writeByte( (byte) ( value >>> 24 ) );
+ target.writeByte( (byte) ( value >>> 16 ) );
+ target.writeByte( (byte) ( value >>> 8 ) );
+ target.writeByte( (byte) ( value >>> 0 ) );
+ }
+ else
+ {
+ target.writeByte( (byte) ( value >>> 0 ) );
+ target.writeByte( (byte) ( value >>> 8 ) );
+ target.writeByte( (byte) ( value >>> 16 ) );
+ target.writeByte( (byte) ( value >>> 24 ) );
+ }
+ }
+
+ public static int getInt( Source source, boolean bigEndian )
+ throws IOException
+ {
+ if ( bigEndian )
+ {
+ byte b3 = source.readByte();
+ byte b2 = source.readByte();
+ byte b1 = source.readByte();
+ byte b0 = source.readByte();
+ return buildInt( b3, b2, b1, b0 );
+ }
+ else
+ {
+ byte b0 = source.readByte();
+ byte b1 = source.readByte();
+ byte b2 = source.readByte();
+ byte b3 = source.readByte();
+ return buildInt( b3, b2, b1, b0 );
+ }
+ }
+
+ public static void putLong( long value, Target target, boolean bigEndian )
+ throws IOException
+ {
+ if ( bigEndian )
+ {
+ target.writeByte( (byte) ( value >> 56 ) );
+ target.writeByte( (byte) ( value >> 48 ) );
+ target.writeByte( (byte) ( value >> 40 ) );
+ target.writeByte( (byte) ( value >> 32 ) );
+ target.writeByte( (byte) ( value >> 24 ) );
+ target.writeByte( (byte) ( value >> 16 ) );
+ target.writeByte( (byte) ( value >> 8 ) );
+ target.writeByte( (byte) ( value >> 0 ) );
+ }
+ else
+ {
+ target.writeByte( (byte) ( value >> 0 ) );
+ target.writeByte( (byte) ( value >> 8 ) );
+ target.writeByte( (byte) ( value >> 16 ) );
+ target.writeByte( (byte) ( value >> 24 ) );
+ target.writeByte( (byte) ( value >> 32 ) );
+ target.writeByte( (byte) ( value >> 40 ) );
+ target.writeByte( (byte) ( value >> 48 ) );
+ target.writeByte( (byte) ( value >> 56 ) );
+ }
+ }
+
+ public static long getLong( Source source, boolean bigEndian )
+ throws IOException
+ {
+ if ( bigEndian )
+ {
+ byte b7 = source.readByte();
+ byte b6 = source.readByte();
+ byte b5 = source.readByte();
+ byte b4 = source.readByte();
+ byte b3 = source.readByte();
+ byte b2 = source.readByte();
+ byte b1 = source.readByte();
+ byte b0 = source.readByte();
+ return buildLong( b7, b6, b5, b4, b3, b2, b1, b0 );
+ }
+ else
+ {
+ byte b0 = source.readByte();
+ byte b1 = source.readByte();
+ byte b2 = source.readByte();
+ byte b3 = source.readByte();
+ byte b4 = source.readByte();
+ byte b5 = source.readByte();
+ byte b6 = source.readByte();
+ byte b7 = source.readByte();
+ return buildLong( b7, b6, b5, b4, b3, b2, b1, b0 );
+ }
+ }
+
+ private static short buildShort( byte b1, byte b0 )
+ {
+ return (short) ( ( ( ( b1 & 0xFF ) << 8 ) | ( ( b0 & 0xFF ) << 0 ) ) );
+ }
+
+ private static int buildInt( byte b3, byte b2, byte b1, byte b0 )
+ {
+ return ( ( ( ( b3 & 0xFF ) << 24 ) | ( ( b2 & 0xFF ) << 16 ) | ( ( b1 & 0xFF ) << 8 ) | ( ( b0 & 0xFF ) << 0 ) ) );
+ }
+
+ private static long buildLong( byte b7, byte b6, byte b5, byte b4, byte b3, byte b2, byte b1, byte b0 )
+ {
+ return ( ( ( ( b7 & 0xFF ) << 56 ) | ( ( b6 & 0xFF ) << 48 ) | ( ( b5 & 0xFF ) << 40 ) | ( ( b4 & 0xFF ) << 32 )
+ | ( ( b3 & 0xFF ) << 24 ) | ( ( b2 & 0xFF ) << 16 ) | ( ( b1 & 0xFF ) << 8 ) | ( ( b0 & 0xFF ) << 0 ) ) );
+ }
+
+}
Added: directmemory/lightning/trunk/lightning-core/src/main/java/org/apache/directmemory/lightning/io/ByteBufferSource.java
URL: http://svn.apache.org/viewvc/directmemory/lightning/trunk/lightning-core/src/main/java/org/apache/directmemory/lightning/io/ByteBufferSource.java?rev=1405123&view=auto
==============================================================================
--- directmemory/lightning/trunk/lightning-core/src/main/java/org/apache/directmemory/lightning/io/ByteBufferSource.java (added)
+++ directmemory/lightning/trunk/lightning-core/src/main/java/org/apache/directmemory/lightning/io/ByteBufferSource.java Fri Nov 2 19:41:52 2012
@@ -0,0 +1,116 @@
+package org.apache.directmemory.lightning.io;
+
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
+
+import org.apache.directmemory.lightning.Source;
+
+public class ByteBufferSource
+ implements Source
+{
+
+ private final ByteBuffer byteBuffer;
+
+ public ByteBufferSource( ByteBuffer byteBuffer )
+ {
+ this.byteBuffer = byteBuffer;
+ }
+
+ @Override
+ public ByteOrder byteOrder()
+ {
+ return byteBuffer.order();
+ }
+
+ @Override
+ public long readableBytes()
+ {
+ return byteBuffer.limit();
+ }
+
+ @Override
+ public int readBytes( byte[] bytes )
+ throws IOException
+ {
+ return readBytes( bytes, 0, bytes.length );
+ }
+
+ @Override
+ public int readBytes( byte[] bytes, int offset, int length )
+ throws IOException
+ {
+ byteBuffer.get( bytes, offset, length );
+ return length - offset;
+ }
+
+ @Override
+ public byte readByte()
+ throws IOException
+ {
+ return byteBuffer.get();
+ }
+
+ @Override
+ public short readUnsignedByte()
+ throws IOException
+ {
+ return (short) ( readByte() & 0xFF );
+ }
+
+ @Override
+ public short readShort()
+ throws IOException
+ {
+ return byteBuffer.getShort();
+ }
+
+ @Override
+ public char readChar()
+ throws IOException
+ {
+ return (char) readShort();
+ }
+
+ @Override
+ public int readInt()
+ throws IOException
+ {
+ return byteBuffer.getInt();
+ }
+
+ @Override
+ public long readLong()
+ throws IOException
+ {
+ return byteBuffer.getLong();
+ }
+
+ @Override
+ public float readFloat()
+ throws IOException
+ {
+ return byteBuffer.getFloat();
+ }
+
+ @Override
+ public double readDouble()
+ throws IOException
+ {
+ return byteBuffer.getDouble();
+ }
+
+ @Override
+ public void clear()
+ throws IOException
+ {
+ byteBuffer.clear();
+ }
+
+ @Override
+ public void free()
+ throws IOException
+ {
+ }
+
+}
Added: directmemory/lightning/trunk/lightning-core/src/main/java/org/apache/directmemory/lightning/io/ByteBufferTarget.java
URL: http://svn.apache.org/viewvc/directmemory/lightning/trunk/lightning-core/src/main/java/org/apache/directmemory/lightning/io/ByteBufferTarget.java?rev=1405123&view=auto
==============================================================================
--- directmemory/lightning/trunk/lightning-core/src/main/java/org/apache/directmemory/lightning/io/ByteBufferTarget.java (added)
+++ directmemory/lightning/trunk/lightning-core/src/main/java/org/apache/directmemory/lightning/io/ByteBufferTarget.java Fri Nov 2 19:41:52 2012
@@ -0,0 +1,115 @@
+package org.apache.directmemory.lightning.io;
+
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
+
+import org.apache.directmemory.lightning.Target;
+
+public class ByteBufferTarget
+ implements Target
+{
+
+ private final ByteBuffer byteBuffer;
+
+ public ByteBufferTarget( ByteBuffer byteBuffer )
+ {
+ this.byteBuffer = byteBuffer;
+ }
+
+ @Override
+ public ByteOrder byteOrder()
+ {
+ return byteBuffer.order();
+ }
+
+ @Override
+ public long writtenBytes()
+ {
+ return byteBuffer.position();
+ }
+
+ @Override
+ public void writeBytes( byte[] bytes )
+ throws IOException
+ {
+ writeBytes( bytes, 0, bytes.length );
+ }
+
+ @Override
+ public void writeBytes( byte[] bytes, int offset, int length )
+ throws IOException
+ {
+ byteBuffer.put( bytes, offset, length );
+ }
+
+ @Override
+ public void writeByte( byte value )
+ throws IOException
+ {
+ byteBuffer.put( value );
+ }
+
+ @Override
+ public void writeUnsignedByte( short value )
+ throws IOException
+ {
+ byteBuffer.put( (byte) value );
+ }
+
+ @Override
+ public void writeShort( short value )
+ throws IOException
+ {
+ byteBuffer.putShort( value );
+ }
+
+ @Override
+ public void writeChar( char value )
+ throws IOException
+ {
+ writeShort( (short) value );
+ }
+
+ @Override
+ public void writeInt( int value )
+ throws IOException
+ {
+ byteBuffer.putInt( value );
+ }
+
+ @Override
+ public void writeLong( long value )
+ throws IOException
+ {
+ byteBuffer.putLong( value );
+ }
+
+ @Override
+ public void writeFloat( float value )
+ throws IOException
+ {
+ byteBuffer.putFloat( value );
+ }
+
+ @Override
+ public void writeDouble( double value )
+ throws IOException
+ {
+ byteBuffer.putDouble( value );
+ }
+
+ @Override
+ public void clear()
+ throws IOException
+ {
+ byteBuffer.clear();
+ }
+
+ @Override
+ public void free()
+ throws IOException
+ {
+ }
+
+}
Added: directmemory/lightning/trunk/lightning-core/src/main/java/org/apache/directmemory/lightning/io/InputStreamSource.java
URL: http://svn.apache.org/viewvc/directmemory/lightning/trunk/lightning-core/src/main/java/org/apache/directmemory/lightning/io/InputStreamSource.java?rev=1405123&view=auto
==============================================================================
--- directmemory/lightning/trunk/lightning-core/src/main/java/org/apache/directmemory/lightning/io/InputStreamSource.java (added)
+++ directmemory/lightning/trunk/lightning-core/src/main/java/org/apache/directmemory/lightning/io/InputStreamSource.java Fri Nov 2 19:41:52 2012
@@ -0,0 +1,149 @@
+/*
+ * 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.IOException;
+import java.io.InputStream;
+import java.nio.ByteOrder;
+
+import org.apache.directmemory.lightning.Source;
+import org.apache.directmemory.lightning.internal.io.ByteOrderUtils;
+
+public class InputStreamSource
+ implements Source
+{
+
+ private final InputStream stream;
+
+ private final ByteOrder byteOrder;
+
+ public InputStreamSource( InputStream stream )
+ {
+ this( stream, ByteOrder.BIG_ENDIAN );
+ }
+
+ public InputStreamSource( InputStream stream, ByteOrder byteOrder )
+ {
+ this.stream = stream;
+ this.byteOrder = byteOrder;
+ }
+
+ @Override
+ public ByteOrder byteOrder()
+ {
+ return byteOrder;
+ }
+
+ @Override
+ public long readableBytes()
+ {
+ try
+ {
+ return stream.available();
+ }
+ catch ( IOException e )
+ {
+ return -1;
+ }
+ }
+
+ @Override
+ public int readBytes( byte[] bytes )
+ throws IOException
+ {
+ return readBytes( bytes, 0, bytes.length );
+ }
+
+ @Override
+ public int readBytes( byte[] bytes, int offset, int length )
+ throws IOException
+ {
+ return stream.read( bytes, offset, length );
+ }
+
+ @Override
+ public byte readByte()
+ throws IOException
+ {
+ return (byte) stream.read();
+ }
+
+ @Override
+ public short readUnsignedByte()
+ throws IOException
+ {
+ return (short) ( readByte() & 0xFF );
+ }
+
+ @Override
+ public short readShort()
+ throws IOException
+ {
+ return ByteOrderUtils.getShort( this, byteOrder == ByteOrder.BIG_ENDIAN );
+ }
+
+ @Override
+ public char readChar()
+ throws IOException
+ {
+ return (char) readShort();
+ }
+
+ @Override
+ public int readInt()
+ throws IOException
+ {
+ return ByteOrderUtils.getInt( this, byteOrder == ByteOrder.BIG_ENDIAN );
+ }
+
+ @Override
+ public long readLong()
+ throws IOException
+ {
+ return ByteOrderUtils.getLong( this, byteOrder == ByteOrder.BIG_ENDIAN );
+ }
+
+ @Override
+ public float readFloat()
+ throws IOException
+ {
+ return Float.intBitsToFloat( readInt() );
+ }
+
+ @Override
+ public double readDouble()
+ throws IOException
+ {
+ return Double.longBitsToDouble( readLong() );
+ }
+
+ @Override
+ public void clear()
+ throws IOException
+ {
+ throw new UnsupportedOperationException( "InputStreamSource cannot be reused" );
+ }
+
+ @Override
+ public void free()
+ throws IOException
+ {
+ }
+
+}
Added: directmemory/lightning/trunk/lightning-core/src/main/java/org/apache/directmemory/lightning/io/OutputStreamTarget.java
URL: http://svn.apache.org/viewvc/directmemory/lightning/trunk/lightning-core/src/main/java/org/apache/directmemory/lightning/io/OutputStreamTarget.java?rev=1405123&view=auto
==============================================================================
--- directmemory/lightning/trunk/lightning-core/src/main/java/org/apache/directmemory/lightning/io/OutputStreamTarget.java (added)
+++ directmemory/lightning/trunk/lightning-core/src/main/java/org/apache/directmemory/lightning/io/OutputStreamTarget.java Fri Nov 2 19:41:52 2012
@@ -0,0 +1,132 @@
+package org.apache.directmemory.lightning.io;
+
+import java.io.IOException;
+import java.io.OutputStream;
+import java.nio.ByteOrder;
+
+import org.apache.directmemory.lightning.Target;
+import org.apache.directmemory.lightning.internal.io.ByteOrderUtils;
+
+public class OutputStreamTarget
+ implements Target
+{
+
+ private final OutputStream stream;
+
+ private final ByteOrder byteOrder;
+
+ private long writtenBytes = 0;
+
+ public OutputStreamTarget( OutputStream stream )
+ {
+ this( stream, ByteOrder.BIG_ENDIAN );
+ }
+
+ public OutputStreamTarget( OutputStream stream, ByteOrder byteOrder )
+ {
+ this.stream = stream;
+ this.byteOrder = byteOrder;
+ }
+
+ @Override
+ public ByteOrder byteOrder()
+ {
+ return byteOrder;
+ }
+
+ @Override
+ public long writtenBytes()
+ {
+ return writtenBytes;
+ }
+
+ @Override
+ public void writeBytes( byte[] bytes )
+ throws IOException
+ {
+ writeBytes( bytes, 0, bytes.length );
+ }
+
+ @Override
+ public void writeBytes( byte[] bytes, int offset, int length )
+ throws IOException
+ {
+ stream.write( bytes, offset, length );
+ writtenBytes += ( length - offset );
+ }
+
+ @Override
+ public void writeByte( byte value )
+ throws IOException
+ {
+ stream.write( value );
+ writtenBytes++;
+ }
+
+ @Override
+ public void writeUnsignedByte( short value )
+ throws IOException
+ {
+ stream.write( (byte) value );
+ writtenBytes++;
+ }
+
+ @Override
+ public void writeShort( short value )
+ throws IOException
+ {
+ ByteOrderUtils.putShort( value, this, byteOrder == ByteOrder.BIG_ENDIAN );
+ writtenBytes += 2;
+ }
+
+ @Override
+ public void writeChar( char value )
+ throws IOException
+ {
+ writeShort( (short) value );
+ }
+
+ @Override
+ public void writeInt( int value )
+ throws IOException
+ {
+ ByteOrderUtils.putInt( value, this, byteOrder == ByteOrder.BIG_ENDIAN );
+ writtenBytes += 4;
+ }
+
+ @Override
+ public void writeLong( long value )
+ throws IOException
+ {
+ ByteOrderUtils.putLong( value, this, byteOrder == ByteOrder.BIG_ENDIAN );
+ writtenBytes += 8;
+ }
+
+ @Override
+ public void writeFloat( float value )
+ throws IOException
+ {
+ writeInt( Float.floatToIntBits( value ) );
+ }
+
+ @Override
+ public void writeDouble( double value )
+ throws IOException
+ {
+ writeLong( Double.doubleToLongBits( value ) );
+ }
+
+ @Override
+ public void clear()
+ throws IOException
+ {
+ throw new UnsupportedOperationException( "OutputStreamTarget cannot be reused" );
+ }
+
+ @Override
+ public void free()
+ throws IOException
+ {
+ }
+
+}