net.kano.joscar.snaccmd.icbm
Class OldIconHashInfo

java.lang.Object
  extended byOldIconHashInfo

public final class OldIconHashInfo
extends java.lang.Object

A data structure containing a set of information about a buddy icon. This is called "old" icon hash data because of the new buddy icon system (the 0x10 service).

Note that this data structure is stored in two separate formats in the OSCAR protocol. The first is when "advertising" one's buddy icon in an IM and the second is when sending one's icon to another user in a rendezvous packet. Accordingly, are two pairs of read* and write* methods for reading from and writing to these two formats.


Constructor Summary
  OldIconHashInfo(java.io.File file)
          Creates an old icon hash block from the contents, size, and last-modified time of the given file.
  OldIconHashInfo(long size, int sum, long timestamp)
          Creates a new icon hash data object with the given properties.
protected OldIconHashInfo(long size, int sum, long timestamp, int blockSize)
          Creates a new icon hash data object with the given properties.
 
Method Summary
static int computeIconSum(ByteBlock data)
          Returns an "old icon sum" from the given buddy icon data.
static int computeIconSum(java.io.InputStream in)
          Returns an icon sum of all of the data in the given stream.
 int getHashBlockSize()
          Returns the total size of the data structure from which this icon hash information object was read, or -1 if this block was not read from an incoming block of binary data.
 long getIconSize()
          Returns the file size of the icon, as sent in this object.
 int getImTlvFormatLength()
          Returns the number of bytes that would be or have been written with a call to writeToImTlv.
 int getRvDataFormatLength()
          Returns the number of bytes that would be or have been written with a call to writeToRvData.
 int getSum()
          Returns an "icon sum" of the icon data, as sent in this object.
 long getTimestamp()
          Returns the time at which the icon was modified, in seconds since the unix epoch, as sent in this object.
static OldIconHashInfo readIconHashFromImTlvData(ByteBlock block)
          Returns an icon hash data block read from the beginning of the given block of binary data.
static OldIconHashInfo readIconHashFromRvData(ByteBlock block)
          Returns an icon hash data block read from the beginning of the given block of binary data.
 java.lang.String toString()
           
 void writeToImTlv(java.io.OutputStream out)
          Writes this icon hash block to the given stream in the format normally used in advertising one's buddy icon in an IM.
 void writeToRvData(java.io.OutputStream out)
          Writes this icon hash block to the given stream in the format normally used in sending one's buddy icon to a buddy in a SendBuddyIconRvCmd.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

OldIconHashInfo

public OldIconHashInfo(java.io.File file)
                throws java.io.FileNotFoundException,
                       java.io.IOException
Creates an old icon hash block from the contents, size, and last-modified time of the given file.

Parameters:
file - a buddy icon file
Throws:
java.io.FileNotFoundException - if the given file does not exist
java.io.IOException - if an I/O error occurs (i.e., if the file cannot be read)

OldIconHashInfo

protected OldIconHashInfo(long size,
                          int sum,
                          long timestamp,
                          int blockSize)
Creates a new icon hash data object with the given properties.

Parameters:
size - the file size of the icon
sum - a hash of the icon data
timestamp - the time at which the icon was modified last, in seconds since the unix epoch
blockSize - the total size of this object, in bytes, as read from an incoming block of binary data

OldIconHashInfo

public OldIconHashInfo(long size,
                       int sum,
                       long timestamp)
Creates a new icon hash data object with the given properties.

Parameters:
size - the file size of the icon
sum - a hash of the icon data
timestamp - the time at which the icon was modified last, in seconds since the unix epoch
Method Detail

computeIconSum

public static int computeIconSum(java.io.InputStream in)
                          throws java.io.IOException
Returns an icon sum of all of the data in the given stream. Data are read from until the end of the given stream has bene reached.

Parameters:
in - a stream containing a buddy icon
Returns:
an "old icon sum" of the data in the given stream
Throws:
java.io.IOException - if an I/O exception occurs

computeIconSum

public static int computeIconSum(ByteBlock data)
Returns an "old icon sum" from the given buddy icon data.

Parameters:
data - the raw buddy icon data
Returns:
an icon sum suitable for use in an OldIconHashData

readIconHashFromImTlvData

public static OldIconHashInfo readIconHashFromImTlvData(ByteBlock block)
Returns an icon hash data block read from the beginning of the given block of binary data. Returns null if the given block does not contain a valid icon hash data block. Note that this method reads the data using the format normally used in sending one's icon hash in an IM.

Parameters:
block - the block of data from which to read
Returns:
an icon hash data block read from the given block, or null if none could be read

readIconHashFromRvData

public static OldIconHashInfo readIconHashFromRvData(ByteBlock block)
Returns an icon hash data block read from the beginning of the given block of binary data. Returns null if the given block does not contain a valid icon hash data block. Note that this method reads the data using the format normally used in sending one's icon hash along with one's icon in a SendBuddyIconRvCmd.

Parameters:
block - the block of data from which to read
Returns:
an icon hash data block read from the given block, or null if none could be read

getIconSize

public final long getIconSize()
Returns the file size of the icon, as sent in this object.

Returns:
the icon's size, in bytes

getSum

public final int getSum()
Returns an "icon sum" of the icon data, as sent in this object.

Returns:
the icon's "icon sum"

getTimestamp

public final long getTimestamp()
Returns the time at which the icon was modified, in seconds since the unix epoch, as sent in this object.

Returns:
the time at which this icon was modified

getHashBlockSize

public int getHashBlockSize()
Returns the total size of the data structure from which this icon hash information object was read, or -1 if this block was not read from an incoming block of binary data.

Returns:
the total size, in bytes, of the data strcture from which this icon hash information object was read, or -1 if this object was not read from an incoming block of binary data

writeToImTlv

public void writeToImTlv(java.io.OutputStream out)
                  throws java.io.IOException
Writes this icon hash block to the given stream in the format normally used in advertising one's buddy icon in an IM.

Parameters:
out - the stream to which to write this block
Throws:
java.io.IOException - if an I/O error occurs

getImTlvFormatLength

public int getImTlvFormatLength()
Returns the number of bytes that would be or have been written with a call to writeToImTlv.

Returns:
the length, in bytes, of the icon hash data block format used in advertising one's buddy icon in an IM

writeToRvData

public void writeToRvData(java.io.OutputStream out)
                   throws java.io.IOException
Writes this icon hash block to the given stream in the format normally used in sending one's buddy icon to a buddy in a SendBuddyIconRvCmd.

Parameters:
out - the stream to which to write this block
Throws:
java.io.IOException - if an I/O error occurs

getRvDataFormatLength

public int getRvDataFormatLength()
Returns the number of bytes that would be or have been written with a call to writeToRvData.

Returns:
the length, in bytes, of the icon hash data block format used in sending one's buddy icon in a rendezvous packet

toString

public java.lang.String toString()