|
JXTA | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectnet.jxta.endpoint.MessageElement
net.jxta.endpoint.ByteArrayMessageElement
public class ByteArrayMessageElement
A Message Element using byte arrays for the element data.
This implementation does not copy the byte array provided and assumes that the contents of the byte array will not change through out the lifetime of the MessageElement. some synchronization is due to optimization ingetBytes(boolean)
which replaces value of internal member b
.
Field Summary | |
---|---|
protected byte[] |
b
The bytes of this element. |
protected int |
len
length of the element data. sometimes the same as b.length, but may be lesser. |
protected int |
offset
This is the offset of our data within the array |
Fields inherited from class net.jxta.endpoint.MessageElement |
---|
cachedGetByteLength, cachedGetBytes, cachedToString, name, sig, type |
Constructor Summary | |
---|---|
ByteArrayMessageElement(String name,
MimeMediaType type,
byte[] b,
int offset,
int len,
MessageElement sig)
Create a new Element, but dont add it to the message. |
|
ByteArrayMessageElement(String name,
MimeMediaType type,
byte[] b,
int offset,
MessageElement sig)
Create a new MessageElement, The contents of the provided byte array are not copied during construction. |
|
ByteArrayMessageElement(String name,
MimeMediaType type,
byte[] b,
MessageElement sig)
Create a new Message Element. |
Method Summary | |
---|---|
boolean |
equals(Object target)
Elements are considered equal if they have the same name, type and signatures. |
long |
getByteLength()
Returns the size of the element data in bytes. |
byte[] |
getBytes()
Returns the contents of this element as a byte array. |
byte[] |
getBytes(boolean copy)
Returns a byte array which contains the element data. |
InputStream |
getStream()
Returns the stream of bytes which represents the content of this Document . |
int |
hashCode()
|
void |
sendToStream(OutputStream sendTo)
Send the contents of this Document to the specified stream. |
String |
toString()
Returns a String representation of the element data. |
Methods inherited from class net.jxta.endpoint.MessageElement |
---|
clone, copyInputStreamToOutputStream, getElementName, getElementProperty, getFileExtension, getMimeType, getSequentialName, getSignature, getUniqueName, setElementProperty |
Methods inherited from class java.lang.Object |
---|
finalize, getClass, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
protected byte[] b
protected int offset
protected int len
Constructor Detail |
---|
public ByteArrayMessageElement(String name, MimeMediaType type, byte[] b, MessageElement sig)
name
- Name of the MessageElement. May be the empty string ("") if
the MessageElement is not named.type
- Type of the MessageElement. null is the same as specifying
the type "Application/Octet-stream".b
- A byte array containing the contents of this element.sig
- optional message digest/digital signature element or null if
no signature is desired.public ByteArrayMessageElement(String name, MimeMediaType type, byte[] b, int offset, MessageElement sig)
name
- Name of the MessageElement. May be the empty string ("") if
the MessageElement is not named.type
- Type of the MessageElement. null is the same as specifying
the type "Application/Octet-stream".b
- A byte array containing the contents of this element.offset
- all bytes before this location in b
will be ignored.sig
- optional message digest/digital signature elemnent or null if
no signature is desired.public ByteArrayMessageElement(String name, MimeMediaType type, byte[] b, int offset, int len, MessageElement sig)
name
- Name of the MessageElement. May be the empty string ("") if
the MessageElement is not named.type
- Type of the MessageElement. null is the same as specifying
the type "Application/Octet-stream".b
- A byte array containing the contents of this Element.offset
- all bytes before this location will be ignored.len
- number of bytes to includesig
- optional message digest/digital signature element or null if
no signature is desired.Method Detail |
---|
public boolean equals(Object target)
equals
in class MessageElement
public int hashCode()
hashCode
in class MessageElement
public String toString()
'charset'
parameter of the message element's mimetype, if
any, is used to determine encoding. If the charset specified is
unsupported then the default encoding will be used.
synchronized for caching purposes.
Returns the string representation of this element. The 'charset'
parameter of the mimetype, if any, is used to determine encoding. If
the charset specified is unsupported then the default encoding will be
used.
toString
in class MessageElement
public long getByteLength()
getByteLength
in class MessageElement
public byte[] getBytes(boolean copy)
copy
parameter allows you to request a
private, modifiable copy of the element data.
This implementation builds the byte array from the stream.
synchronized so that we can replace our internal buffer with
the buffer we are returning if we were using a shared buffer.
getBytes
in class MessageElement
copy
- If true then the result can be modified without damaging the state of this
MessageElement. If false, then the result may be a shared copy of the data and
should be considered read-only.
public InputStream getStream()
Document
.
InputStream
containing the bytes
of this Document
.public void sendToStream(OutputStream sendTo) throws IOException
Document
to the specified stream.
This version probably has sub-optimal performance. Sub-classes
should override this implementation.
sendToStream
in interface DocumentStreamIO
sendToStream
in class MessageElement
sendTo
- The OutputStream to which the Document
will
be written.
IOException
- For errors while writing the Document
.public byte[] getBytes()
|
JXSE | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |