webfunds.sox
Class Encodable
java.lang.Object
|
+--webfunds.sox.Encodable
- Direct Known Subclasses:
- AbstractParams, AbstractPayment, Account, ArmouredPayment, BasicReply, BasicReplyPacket, BasicRequest, BasicRequestPacket, Id, MailItem, Receipt, Reply, Request, RequestPacket, SOXServer, StateReceipt, SubAccount, Token, Token
- public abstract class Encodable
- extends java.lang.Object
- implements java.io.Serializable
This is an abstract base class for all Encodable
objects. An Encodable object is capable of saving
and restoring itself to and from byte arrays and
Input/Output Streams.
Derived classes need only define the encode(InputStream)
and decode(OutputStream) methods, but may also wish
to define a constructor that accepts an InputStream
or byte array as a parameter, and then proceeds to
call the decode() method with this parameter.
- See Also:
- Serialized Form
|
Method Summary |
void |
decode(byte[] data)
|
void |
decode(java.io.InputStream is)
|
byte[] |
encode()
|
void |
encode(java.io.OutputStream os)
|
static void |
main(java.lang.String[] argv)
|
static byte[] |
readByteArray(java.io.DataInput dis)
A utility function to read a byte arrays
from a DataInputStream, using a length prefix. |
static java.security.cert.Certificate |
readCertificate(java.io.DataInputStream dis)
A utility function to read a Certificate
from a DataInputStream (using a length prefix). |
static java.util.Properties |
readProperties(java.io.DataInput dis)
|
static java.lang.String |
readString(java.io.DataInput dis)
|
static void |
writeByteArray(java.io.DataOutput dos,
byte[] data)
A utility function to write a byte array
to a DataOutputStream, with a length prefix. |
static void |
writeCertificate(java.io.DataOutputStream dos,
java.security.cert.Certificate cert)
A utility function to write a Certificate
to a DataOutputStream (with a length prefix). |
static void |
writeProperties(java.io.DataOutput dos,
java.util.Properties pt)
|
static void |
writeString(java.io.DataOutput dos,
java.lang.String text)
|
| Methods inherited from class java.lang.Object |
clone,
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
toString,
wait,
wait,
wait |
Encodable
public Encodable()
encode
public void encode(java.io.OutputStream os)
throws java.io.IOException
encode
public byte[] encode()
decode
public void decode(java.io.InputStream is)
throws java.io.IOException,
SOXPacketException
decode
public void decode(byte[] data)
throws SOXPacketException
- Throws:
- java.io.IOException - can be thrown if the data is longer than
necessary. In situations where the data should be read from
a larger chunk, it may be more convenient to create a
ByteArrayInputStream from the data and use decode(InputStream).
readByteArray
public static byte[] readByteArray(java.io.DataInput dis)
throws java.io.IOException
- A utility function to read a byte arrays
from a DataInputStream, using a length prefix.
NOTE: there is no way to read in a null, a byte[0] is returned in
that case.
- Parameters:
dis - the stream from which to read the data- Returns:
- a byte array read from the stream
writeByteArray
public static void writeByteArray(java.io.DataOutput dos,
byte[] data)
throws java.io.IOException
- A utility function to write a byte array
to a DataOutputStream, with a length prefix.
NOTE: there is no difference between null and byte[0]
in the enoding, and readByteArray will *always* return a byte[0];
- Parameters:
dos - the stream to which the data is writtendata - the data to write
writeString
public static void writeString(java.io.DataOutput dos,
java.lang.String text)
throws java.io.IOException
readString
public static java.lang.String readString(java.io.DataInput dis)
throws java.io.IOException
writeProperties
public static void writeProperties(java.io.DataOutput dos,
java.util.Properties pt)
throws java.io.IOException
readProperties
public static java.util.Properties readProperties(java.io.DataInput dis)
throws java.io.IOException
writeCertificate
public static void writeCertificate(java.io.DataOutputStream dos,
java.security.cert.Certificate cert)
throws java.io.IOException
- A utility function to write a Certificate
to a DataOutputStream (with a length prefix).
Primarily provided since the encode() method of the
Certificate class insists on a stream parameter, and
does provide a simple method to return the object
encoded as a byte array.
- Parameters:
dos - the stream to which the certificate is writtencert - the certificate to encode and write
readCertificate
public static java.security.cert.Certificate readCertificate(java.io.DataInputStream dis)
throws java.io.IOException
- A utility function to read a Certificate
from a DataInputStream (using a length prefix).
Primarily provided for completeness (to match
the writeCertificate).
- Parameters:
dis - the stream from which the certificate is read- Returns:
- A Certificate object constructed from the input stream
main
public static void main(java.lang.String[] argv)
throws java.io.IOException