org.deegree.commons.utils.nio
Class BufferSerializer

java.lang.Object
  extended by org.deegree.commons.utils.nio.BufferSerializer

public class BufferSerializer
extends Object

The BufferSerializer class TODO add class documentation here.

Version:
$Revision: 30119 $, $Date: 2011-03-22 10:02:35 +0100 (Tue, 22 Mar 2011) $
Author:
Rutger Bezema, last edited by: $Author: aschmitz $

Constructor Summary
BufferSerializer()
           
 
Method Summary
static ByteBuffer readByteBufferFromStream(DataInputStream in, boolean direct)
          Reads a number of bytes from the stream and fills a direct, native ByteBuffer with them.
static FloatBuffer readFloatBufferFromStream(DataInputStream in, boolean direct)
          Reads a number of floats from the stream and fills a direct, native FloatBuffer with them.
static void writeBufferToStream(Buffer buffer, DataOutputStream out)
          Writes a buffer to the given output stream by checking the instance of the buffer and writing the native values appropriately.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BufferSerializer

public BufferSerializer()
Method Detail

writeBufferToStream

public static void writeBufferToStream(Buffer buffer,
                                       DataOutputStream out)
                                throws IOException
Writes a buffer to the given output stream by checking the instance of the buffer and writing the native values appropriately. Because of the ObjectOutputStream is not seekable, the serialized buffer will be corrupted if an IOException occurs. The 'size' integer will in this case not be set to -1 and will not contain the correct number of 'native-types' to read.

Parameters:
buffer -
out -
Throws:
IOException

readFloatBufferFromStream

public static FloatBuffer readFloatBufferFromStream(DataInputStream in,
                                                    boolean direct)
                                             throws IOException
Reads a number of floats from the stream and fills a direct, native FloatBuffer with them.

The callee has to ensure that this method is called in it's right time, so that the next read to the stream gives an int and the read(s) thereafter will result in the number of values denoted by the first int value. Using this class will result in a correct order. The following code will result in correct reading and writing of the buffers: FloatBuffer myFloatBuffer; private void writeObject( ObjectOutputStream out ){ BufferSerializer.writeBufferToStream( out, myFloatBuffer ); } private void readObject( ObjectInputStream in ){ myFloatBuffer = BufferSerializer.readFloatBufferFromStream( in ); }

Parameters:
in -
direct -
Returns:
the floatBuffer of null if no indication of the number of floats to read has been made.
Throws:
IOException

readByteBufferFromStream

public static ByteBuffer readByteBufferFromStream(DataInputStream in,
                                                  boolean direct)
                                           throws IOException
Reads a number of bytes from the stream and fills a direct, native ByteBuffer with them.

The callee has to ensure that this method is called in it's right time, so that the next read to the stream gives an int and the read(s) thereafter will result in the number of values denoted by the first int value. Using this class will result in a correct order. The following code will result in correct reading and writing of the buffers: ByteBuffer myByteBuffer; private void writeObject( ObjectOutputStream out ){ BufferSerializer.writeBufferToStream( out, myByteBuffer ); } private void readObject( ObjectInputStream in ){ myByteBuffer = BufferSerializer.readByteBufferFromStream( in ); }

Parameters:
in -
direct -
Returns:
the floatBuffer of null if no indication of the number of floats to read has been made.
Throws:
IOException


Copyright © 2011. All Rights Reserved.