com.sun.multicast.util
Class Util

java.lang.Object
  |
  +--com.sun.multicast.util.Util

public class Util
extends java.lang.Object

Utility class for reading and writing bigendian integers to and from a byte array. This class is used for encoding and decoding network packets.


Method Summary
static java.lang.Object deepClone(java.lang.Object object)
          Perform a deep clone of an object.
static int InetAddressToInt(java.net.InetAddress ia)
          Converts an InetAddress into an int.
static java.net.InetAddress intToInetAddress(int address)
          Converts an int into an InetAddress.
static int readInt(byte[] arr, int pos)
          Reads a signed int (4 byte bigendian integer) from a byte array starting at index pos.
static long readLong(byte[] arr, int pos)
          Reads a signed long (8 byte bigendian integer) from a byte array starting at index pos.
static java.lang.Object readObject(byte[] bytes)
          Read an object from a byte array using serialization.
static long readUnsignedInt(byte[] arr, int pos)
          Reads an unsigned int (4 byte bigendian integer) from a byte array starting at index pos.
static int readUnsignedShort(byte[] arr, int pos)
          Reads an unsigned short (2 byte bigendian integer) from a byte array starting at index pos.
static void writeByteArrayToFile(byte[] buf, java.lang.String fileName, int len)
          Method to write a byte array to a file.
static void writeInt(int i, byte[] arr, int pos)
          Writes a signed int (4 byte bigendian integer) to a byte array starting at index pos.
static void writeLong(long l, byte[] arr, int pos)
          Writes a signed long (8 byte bigendian integer) to a byte array starting at index pos.
static byte[] writeObject(java.lang.Object object)
          Write an object to a byte array using serialization.
static void writeShort(short s, byte[] arr, int pos)
          Writes a signed short (2 byte bigendian integer) to a byte array starting at index pos.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

readUnsignedShort

public static int readUnsignedShort(byte[] arr,
                                    int pos)
Reads an unsigned short (2 byte bigendian integer) from a byte array starting at index pos.
Parameters:
arr - the byte array
pos - the index into the byte array
Returns:
the unsigned short (expanded to an int to avoid sign problems)

writeShort

public static void writeShort(short s,
                              byte[] arr,
                              int pos)
Writes a signed short (2 byte bigendian integer) to a byte array starting at index pos.
Parameters:
s - the signed short
arr - the byte array
pos - the index into the byte array

readUnsignedInt

public static long readUnsignedInt(byte[] arr,
                                   int pos)
Reads an unsigned int (4 byte bigendian integer) from a byte array starting at index pos.
Parameters:
arr - the byte array
pos - the index into the byte array
Returns:
the unsigned int (expanded to a long to avoid sign problems)

readInt

public static int readInt(byte[] arr,
                          int pos)
Reads a signed int (4 byte bigendian integer) from a byte array starting at index pos.
Parameters:
arr - the byte array
pos - the index into the byte array
Returns:
the signed int

writeInt

public static void writeInt(int i,
                            byte[] arr,
                            int pos)
Writes a signed int (4 byte bigendian integer) to a byte array starting at index pos.
Parameters:
i - the signed int
arr - the byte array
pos - the index into the byte array

readLong

public static long readLong(byte[] arr,
                            int pos)
Reads a signed long (8 byte bigendian integer) from a byte array starting at index pos.
Parameters:
arr - the byte array
pos - the index into the byte array
Returns:
the signed long

writeLong

public static void writeLong(long l,
                             byte[] arr,
                             int pos)
Writes a signed long (8 byte bigendian integer) to a byte array starting at index pos.
Parameters:
l - the signed long
arr - the byte array
pos - the index into the byte array

intToInetAddress

public static java.net.InetAddress intToInetAddress(int address)
Converts an int into an InetAddress.
Parameters:
address - the int
Returns:
a new InetAddress for the int

InetAddressToInt

public static int InetAddressToInt(java.net.InetAddress ia)
Converts an InetAddress into an int.
Parameters:
ia - the InetAddress
Returns:
the int

readObject

public static java.lang.Object readObject(byte[] bytes)
Read an object from a byte array using serialization.
Parameters:
object - the byte stream to read
Returns:
the object read

writeObject

public static byte[] writeObject(java.lang.Object object)
Write an object to a byte array using serialization.
Parameters:
object - the object to be written
Returns:
the byte stream

deepClone

public static java.lang.Object deepClone(java.lang.Object object)
Perform a deep clone of an object. This ensures that the new object shares no state with the old one. This is achieved by serializing and deserializing the object.
Parameters:
object - the object to be cloned
Returns:
the new object

writeByteArrayToFile

public static void writeByteArrayToFile(byte[] buf,
                                        java.lang.String fileName,
                                        int len)
                                 throws java.io.IOException
Method to write a byte array to a file.


JavaTM Reliable MulticastTM Service version 1.1
Copyright (c) 2001, Sun Microsystems Laboratories, All rights reserved.