net.kano.joscar.snaccmd
Class ExtraInfoBlockHolder

java.lang.Object
  extended byExtraInfoBlockHolder
All Implemented Interfaces:
LiveWritable, Writable

public class ExtraInfoBlockHolder
extends java.lang.Object
implements Writable

A data structure used to hold ExtraInfoBlocks and some sort of code. As of this writing, this structure is only used in ExtraInfoAck commands, and any advantages to sending ExtraInfoBlocks directly is unknown.

See Also:
ExtraInfoAck

Field Summary
static int CODE_DEFAULT
          The code value sent by default by the AIM server.
 
Constructor Summary
  ExtraInfoBlockHolder(ExtraInfoBlock both)
          Creates an extra info block holder whose blocks are both set to the given block and with a code value of CODE_DEFAULT.
  ExtraInfoBlockHolder(ExtraInfoBlock first, int code, ExtraInfoBlock second)
          Creates a new ExtraInfoBlockHolder with the given properties.
protected ExtraInfoBlockHolder(ExtraInfoBlock first, int code, ExtraInfoBlock second, int totalSize)
          Creates a new ExtraInfoBlockHolder with the given properties.
 
Method Summary
 int getCode()
          The numeric code contained in this extra info block holder.
 ExtraInfoBlock getFirstBlock()
          Returns the first extra info block contained in this extra info block holder.
 ExtraInfoBlock getSecondBlock()
          Returns the second extra info block contained in this extra info block holder.
 int getTotalSize()
          Returns the number of bytes read to create this object, if read from an incoming block of binary data with readBlockHolder.
 long getWritableLength()
          Returns the length of the data that was or will be written in a call to write.
static ExtraInfoBlockHolder readBlockHolder(ByteBlock block)
          Reads an ExtraInfoBlockHolder from the given block of binary data.
static ExtraInfoBlockHolder[] readBlockHolders(ByteBlock block)
          Reads a series of ExtraInfoBlockHolders from the given block of binary data.
 java.lang.String toString()
           
 void write(java.io.OutputStream out)
          Writes a representation of this object to the given stream.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

CODE_DEFAULT

public static final int CODE_DEFAULT
The code value sent by default by the AIM server.

See Also:
Constant Field Values
Constructor Detail

ExtraInfoBlockHolder

protected ExtraInfoBlockHolder(ExtraInfoBlock first,
                               int code,
                               ExtraInfoBlock second,
                               int totalSize)
Creates a new ExtraInfoBlockHolder with the given properties.

Parameters:
first - the first ExtraInfoBlock to hold in this block holder
code - the numeric code to hold in this block holder
second - the second ExtraInfoBlock to hold in this block holder
totalSize - the total number of bytes read to create this object, if read from an incoming block of binary data

ExtraInfoBlockHolder

public ExtraInfoBlockHolder(ExtraInfoBlock both)
Creates an extra info block holder whose blocks are both set to the given block and with a code value of CODE_DEFAULT. As of this writing, this is the only format used.

Parameters:
both - the extra info block to use as both the first and second blocks

ExtraInfoBlockHolder

public ExtraInfoBlockHolder(ExtraInfoBlock first,
                            int code,
                            ExtraInfoBlock second)
Creates a new ExtraInfoBlockHolder with the given properties.

Parameters:
first - the first ExtraInfoBlock to hold in this block holder
code - the numeric code to hold in this block holder, like CODE_DEFAULT
second - the second ExtraInfoBlock to hold in this block holder
Method Detail

readBlockHolder

public static final ExtraInfoBlockHolder readBlockHolder(ByteBlock block)
Reads an ExtraInfoBlockHolder from the given block of binary data. The total number of bytes read can be obtained by calling the getTotalSize() method of the returned object. Note that if no valid extra info block holder object can be read, this method will return null.

Parameters:
block - a block of data containing an extra info block holder object
Returns:
an extra info block holder object read from the given block of binary data, or null if none could be read

readBlockHolders

public static final ExtraInfoBlockHolder[] readBlockHolders(ByteBlock block)
Reads a series of ExtraInfoBlockHolders from the given block of binary data. Note that this method will never return null; if no extra info block holder objects can be read from the given block of data, an empty array is returned. The total number of bytes read can be obtained by adding the results of calling getTotalSize() on each of the elements of the returned array.

Parameters:
block - a block of data containing a sequence of zero or more ExtraInfoBlocks
Returns:
a list of the ExtraInfoBlock objects read from the given block of binary data

getFirstBlock

public final ExtraInfoBlock getFirstBlock()
Returns the first extra info block contained in this extra info block holder.

Returns:
the first extra info block

getCode

public final int getCode()
The numeric code contained in this extra info block holder. Note that this is normally CODE_DEFAULT.

Returns:
the numeric code contained in this extra info block holder

getSecondBlock

public final ExtraInfoBlock getSecondBlock()
Returns the second extra info block contained in this extra info block holder.

Returns:
the second extra info block

getTotalSize

public final int getTotalSize()
Returns the number of bytes read to create this object, if read from an incoming block of binary data with readBlockHolder.

Returns:
the total number of bytes read to create this object

getWritableLength

public long getWritableLength()
Description copied from interface: Writable
Returns the length of the data that was or will be written in a call to write. The value returned by this method must not change after its first invocation.

Specified by:
getWritableLength in interface Writable
Returns:
the length of the data to be written by write

write

public void write(java.io.OutputStream out)
           throws java.io.IOException
Description copied from interface: Writable
Writes a representation of this object to the given stream. The length of the data written by this function must match any value previously returned by getWritableLength.

Specified by:
write in interface Writable
Parameters:
out - the stream to which to write
Throws:
java.io.IOException - if an I/O error occurs

toString

public java.lang.String toString()