org.openadaptor.security
Class Footer

java.lang.Object
  extended by org.openadaptor.security.Footer

public class Footer
extends java.lang.Object

Footer class represent any fooer information appended to the data packet by a Security Agent Information is stored in "properties"; name/value pairs. The name is a string, like "signature" and the value must be a byte array. Footers can have any number of properties, including none. Footers know how to write themselves out and read themselves back in.


Field Summary
protected static int NO_ID
          indicates that _idValue has not been assigned a value yet.
 
Constructor Summary
Footer()
          Default constructor
Footer(int idValue)
          Constructor providing a predefined identifier value.
 
Method Summary
protected  boolean byteArrayEquals(byte[] b1, byte[] b2)
          Returns true iff both byte arrays contain identical byte sequences.
 boolean equals(java.lang.Object obj)
          Implements equals() operation for Footer objects
 void fromInputStream(java.io.InputStream is)
          Reads and populates the Footer from the InputStream.
protected  int getIdentifierValue()
          Returns the identifier value for the footer.
 byte[] getProperty(java.lang.String name)
           
 void setProperty(java.lang.String name, byte[] data)
           
 void toOutputStream(java.io.OutputStream os)
          Writes out the footer to an OutputStream.
 java.lang.String toString()
          Create string representation of Footer, for debugging or diagnostics.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

NO_ID

protected static final int NO_ID
indicates that _idValue has not been assigned a value yet.

See Also:
Constant Field Values
Constructor Detail

Footer

public Footer()
Default constructor


Footer

public Footer(int idValue)
Constructor providing a predefined identifier value. Used for a footer which will be populated by being read in, where the identifier value has been read in a header

Parameters:
idValue -
Method Detail

setProperty

public void setProperty(java.lang.String name,
                        byte[] data)

getProperty

public byte[] getProperty(java.lang.String name)

getIdentifierValue

protected int getIdentifierValue()
Returns the identifier value for the footer. Used as basic protection when reading/writing Footer.


toOutputStream

public void toOutputStream(java.io.OutputStream os)
                    throws java.io.IOException
Writes out the footer to an OutputStream. The format used is intended to be as simple and efficient as possible. First the true length of the footer is written out. Then the properties are written out, names in UTF-8 format, null terminated, then the byte array value, preceded by a 32 bit length. Each string (name and value) is zero-terminated. The last value is followed by another zero byte (i.e. the next name is apparently of zero length. For example:
 Footer contains:  signature=[00, 01, 02, 03];
 Encoded as: \23\0\0\0signature\0\4\0\0\0\0\1\2\3\0
 
Note - current implementation could be optimised; it creates a ByteArrayOutputStream for each call.

Parameters:
os - output stream
Throws:
java.io.IOException

fromInputStream

public void fromInputStream(java.io.InputStream is)
                     throws java.io.IOException
Reads and populates the Footer from the InputStream. Note that it clears out any existing properties. See toOutputStream for format details.

Parameters:
is - InputStream from which to read Footer details.
Throws:
java.io.IOException - If there are problems reading from InputStream.

equals

public boolean equals(java.lang.Object obj)
Implements equals() operation for Footer objects

Overrides:
equals in class java.lang.Object
Parameters:
obj - Comparison object.
Returns:
true if equal, false if not

toString

public java.lang.String toString()
Create string representation of Footer, for debugging or diagnostics. Outputs the properties as a pseudo-XML fragment. I say pseudo as it does not encode XML-special characters (e.g. <) so would break any parsers.

Overrides:
toString in class java.lang.Object
Returns:
String representation of Footer

byteArrayEquals

protected boolean byteArrayEquals(byte[] b1,
                                  byte[] b2)
Returns true iff both byte arrays contain identical byte sequences. Either or both can be null; if both then true will be returned.

Parameters:
b1 - first byte array.
b2 - first byte array.
Returns:
True if equal.