net.kano.joscar.snaccmd
Class ShortCapabilityBlock

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

public class ShortCapabilityBlock
extends java.lang.Object
implements Writable

Short capability blocks are means of storing a capability block in two bytes instead of sixteen. Almost all of the official sixteen-byte AIM capability blocks contain fourteen of the same bytes. That is, most of AIM's capability blocks are of the form:

09 46 ?? ?? 4c 7f 11 d1
82 22 44 45 53 54 00 00
A short capability block only stores the values of the two bytes that vary between most of AIM's capabilities.

One may wish to note that capabilities that do not fit the given form are normally still stored as plain old CapabilityBlocks.


Constructor Summary
ShortCapabilityBlock(ByteBlock data)
          Creates a new short capability block object with the given two-byte block of data.
 
Method Summary
static boolean couldBeShortBlock(CapabilityBlock cap)
          Returns whether the given long capability block fits the form of the "family" of capability blocks that can be represented as short capability blocks.
 boolean equals(java.lang.Object obj)
          Returns whether this object is equal to the given object.
 ByteBlock getData()
          Returns the two bytes of data contained in this short capability block.
static ShortCapabilityBlock getShortBlock(CapabilityBlock cap)
          Returns a short capability block that represents the given long capability block.
 long getWritableLength()
          Returns the length of the data that was or will be written in a call to write.
 int hashCode()
           
static ShortCapabilityBlock[] readShortCaps(ByteBlock block)
          Reads a sequence of short capability blocks from the given block of binary data.
 CapabilityBlock toCapabilityBlock()
          Returns the CapabilityBlock that this short capability block represents.
 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, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ShortCapabilityBlock

public ShortCapabilityBlock(ByteBlock data)
                     throws java.lang.IllegalArgumentException
Creates a new short capability block object with the given two-byte block of data.

Parameters:
data - the two-byte block of data that this short capability block should contain
Throws:
java.lang.IllegalArgumentException - if the given block of data contains more or fewer than two bytes
Method Detail

readShortCaps

public static ShortCapabilityBlock[] readShortCaps(ByteBlock block)
Reads a sequence of short capability blocks from the given block of binary data. Note that this method will never return null; if no short capability blocks are present in the given block of data, an empty array will be returned.

Parameters:
block - a block of data containing a sequence of zero or more short capability blocks
Returns:
an array of short capability block objects, read from the given block of binary data

couldBeShortBlock

public static boolean couldBeShortBlock(CapabilityBlock cap)
Returns whether the given long capability block fits the form of the "family" of capability blocks that can be represented as short capability blocks.

Parameters:
cap - the capability block to check
Returns:
whether or not the given long capability block could be represented as a short capability block

getShortBlock

public static ShortCapabilityBlock getShortBlock(CapabilityBlock cap)
                                          throws java.lang.IllegalArgumentException
Returns a short capability block that represents the given long capability block.

Parameters:
cap - the capability block to convert to a short capability block
Returns:
a short capability block that represents the given long capability block
Throws:
java.lang.IllegalArgumentException - if the given capability block cannot be represented as a short capability block

getData

public final ByteBlock getData()
Returns the two bytes of data contained in this short capability block.

Returns:
this short capability block's (two-byte) data block

toCapabilityBlock

public final CapabilityBlock toCapabilityBlock()
Returns the CapabilityBlock that this short capability block represents.

Returns:
a CapabilityBlock equivalent to this short capability block

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

equals

public boolean equals(java.lang.Object obj)
Returns whether this object is equal to the given object. Note that this method returns false for all objects which are not ShortCapabilityBlocks - even CapabilityBlocks.

Parameters:
obj - the object to compare for equality
Returns:
whether or not this object is equal to the given object

hashCode

public int hashCode()

toString

public java.lang.String toString()