JXTA

net.jxta.impl.endpoint.msgframing
Class MessagePackageHeader

java.lang.Object
  extended by net.jxta.impl.endpoint.msgframing.MessagePackageHeader

public class MessagePackageHeader
extends Object

Header Package for Messages. Analogous to HTTP Headers.


Nested Class Summary
static class MessagePackageHeader.Header
          Used for storing individual header elements.
 
Constructor Summary
MessagePackageHeader()
          Creates a new instance of MessagePackageHeader.
MessagePackageHeader(InputStream in)
          Creates a new instance of MessagePackageHeader.
 
Method Summary
 void addHeader(String name, byte[] value)
          Add a header.
 void addHeader(String name, String value)
          Add a header.
 ByteBuffer getByteBuffer()
          Return a ByteBuffer representing this group of header elements.
 long getContentLengthHeader()
          Convenience method for getting the "content-length" header.
 MimeMediaType getContentTypeHeader()
          Convenience method for getting the "content-type" header.
 Iterator<MessagePackageHeader.Header> getHeader(String name)
          Gets all of the headers matching the specified name
 ListIterator<MessagePackageHeader.Header> getHeaders()
          Gets all of the headers.
 boolean readHeader(ByteBuffer buffer)
          Reads a Header from a ByteBuffer
 void replaceHeader(String name, byte[] value)
          Replace a header.
 void replaceHeader(String name, String value)
          Replace a header.
 void sendToStream(OutputStream out)
          Write this group of header elements to a stream.
 void setContentLengthHeader(long length)
          Convenience method setting the "content-length" header.
 void setContentTypeHeader(MimeMediaType type)
          Convenience method for setting the "content-type" header.
 String toString()
          
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

MessagePackageHeader

public MessagePackageHeader()
Creates a new instance of MessagePackageHeader. Used for outgoing messages.


MessagePackageHeader

public MessagePackageHeader(InputStream in)
                     throws IOException
Creates a new instance of MessagePackageHeader. Used for incoming messages.

Parameters:
in - The stream from which the headers will be read.
Throws:
IOException - if an io error occurs.
Method Detail

toString

public String toString()

Overrides:
toString in class Object

readHeader

public boolean readHeader(ByteBuffer buffer)
                   throws IOException
Reads a Header from a ByteBuffer

Parameters:
buffer - the input buffer
Returns:
true If the header block was completely read.
Throws:
IOException - if an io error is encountered

addHeader

public void addHeader(String name,
                      byte[] value)
Add a header.

Parameters:
name - The header name. The UTF-8 encoded representation of this name may not be longer than 255 bytes.
value - The value for the header. May not exceed 65535 bytes in length.

addHeader

public void addHeader(String name,
                      String value)
Add a header.

Parameters:
name - The header name. The UTF-8 encoded representation of this name may not be longer than 255 bytes.
value - The value for the header. May not exceed 65535 bytes in length.

replaceHeader

public void replaceHeader(String name,
                          byte[] value)
Replace a header. Replaces all existing headers with the same name.

Parameters:
name - The header name. The UTF-8 encoded representation of this name may not be longer than 255 bytes.
value - The value for the header. May not exceed 65535 bytes in length.

replaceHeader

public void replaceHeader(String name,
                          String value)
Replace a header. Replaces all existing headers with the same name

Parameters:
name - The header name. The UTF-8 encoded representation of this name may not be longer than 255 bytes.
value - The value for the header. May not exceed 65535 bytes in length.

getHeaders

public ListIterator<MessagePackageHeader.Header> getHeaders()
Gets all of the headers. This iterator provides access to the live data of this instance. Modifying the headers using add(), set(), remove() is permitted.

Returns:
all of the headers

getHeader

public Iterator<MessagePackageHeader.Header> getHeader(String name)
Gets all of the headers matching the specified name

Parameters:
name - the name of the header we are seeking.

sendToStream

public void sendToStream(OutputStream out)
                  throws IOException
Write this group of header elements to a stream.

Parameters:
out - the stream to send the headers to.
Throws:
IOException - if an io error occurs

getByteBuffer

public ByteBuffer getByteBuffer()
Return a ByteBuffer representing this group of header elements.

Returns:
ByteBuffer representing this Header

setContentLengthHeader

public void setContentLengthHeader(long length)
Convenience method setting the "content-length" header.

Parameters:
length - length of the message.

getContentLengthHeader

public long getContentLengthHeader()
Convenience method for getting the "content-length" header.

Returns:
length from the header or -1 if there was no content-length header element.

setContentTypeHeader

public void setContentTypeHeader(MimeMediaType type)
Convenience method for setting the "content-type" header.

Parameters:
type - type of the message.

getContentTypeHeader

public MimeMediaType getContentTypeHeader()
Convenience method for getting the "content-type" header.

Returns:
type from the header or "application/octet-stream" if there was no content-type header.

JXSE