com.sun.sgs.impl.util
Class DataStreamUtil

java.lang.Object
  extended by com.sun.sgs.impl.util.DataStreamUtil

public final class DataStreamUtil
extends Object

Utility methods for reading from data input streams and writing to data output streams.


Method Summary
static byte[][] readByteArrays(DataInput in)
          Reads an array of byte arrays from a data input stream.
static byte[] readBytes(DataInput in)
          Reads the number of bytes and the byte data from a data input stream and returns the resulting array.
static long[] readLongs(DataInput in)
          Reads an array of longs from a data input stream.
static String readString(DataInput in)
          Reads a string or null from a data input stream.
static String[] readStrings(DataInput in)
          Reads an array of strings from a data input stream.
static void writeByteArrays(byte[][] array, DataOutput out)
          Writes an array of byte arrays to a data output stream.
static void writeBytes(byte[] bytes, DataOutput out)
          Writes the number of bytes and the byte data to a data output stream.
static void writeLongs(long[] array, DataOutput out)
          Writes an array of longs to a data output stream.
static void writeString(String string, DataOutput out)
          Writes a string or null to a data output stream.
static void writeStrings(String[] array, DataOutput out)
          Writes an array of strings to a data output stream.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

readBytes

public static byte[] readBytes(DataInput in)
                        throws IOException
Reads the number of bytes and the byte data from a data input stream and returns the resulting array. Returns null if the length is -1.

Parameters:
in - the data input stream
Returns:
the byte array or null
Throws:
IOException - if an I/O error occurs

writeBytes

public static void writeBytes(byte[] bytes,
                              DataOutput out)
                       throws IOException
Writes the number of bytes and the byte data to a data output stream. Writes a length of -1 if the bytes are null

Parameters:
bytes - the bytes or null
out - the data output stream
Throws:
IOException - if an I/O error occurs

readString

public static String readString(DataInput in)
                         throws IOException
Reads a string or null from a data input stream. If the initial boolean value is true, the next item is the UTF for the string; otherwise, the string was null.

Parameters:
in - the data input stream
Returns:
the string or null
Throws:
IOException - if an I/O error occurs

writeString

public static void writeString(String string,
                               DataOutput out)
                        throws IOException
Writes a string or null to a data output stream. Writes the boolean value true followed by the UTF for the string if it is not null, otherwise writes false.

Parameters:
string - the string or null
out - the data output stream
Throws:
IOException - if an I/O error occurs

readStrings

public static String[] readStrings(DataInput in)
                            throws IOException
Reads an array of strings from a data input stream. The array elements can be null.

Parameters:
in - the data input stream
Returns:
the array
Throws:
IOException - if an I/O error occurs

writeStrings

public static void writeStrings(String[] array,
                                DataOutput out)
                         throws IOException
Writes an array of strings to a data output stream. The array elements can be null.

Parameters:
array - the array
out - the data output stream
Throws:
IOException - if an I/O error occurs

readLongs

public static long[] readLongs(DataInput in)
                        throws IOException
Reads an array of longs from a data input stream.

Parameters:
in - the data input stream
Returns:
the array
Throws:
IOException - if an I/O error occurs

writeLongs

public static void writeLongs(long[] array,
                              DataOutput out)
                       throws IOException
Writes an array of longs to a data output stream.

Parameters:
array - the array
out - the data output stream
Throws:
IOException - if an I/O error occurs

readByteArrays

public static byte[][] readByteArrays(DataInput in)
                               throws IOException
Reads an array of byte arrays from a data input stream.

Parameters:
in - the data input stream
Returns:
the array of byte arrays
Throws:
IOException - if an I/O error occurs

writeByteArrays

public static void writeByteArrays(byte[][] array,
                                   DataOutput out)
                            throws IOException
Writes an array of byte arrays to a data output stream.

Parameters:
array - the array of byte arrays
out - the data output stream
Throws:
IOException - if an I/O error occurs

RedDwarf, Version 0.10.1
2010-03-14 10:56:12

Copyright © 2010 The RedDwarf Authors. All rights reserved
Copyright © 2007-2010 Sun Microsystems, Inc. All rights reserved