net.rim.pushsdk.commons.content
Class BinaryContent

java.lang.Object
  extended by net.rim.pushsdk.commons.content.Content
      extended by net.rim.pushsdk.commons.content.SinglePartContent
          extended by net.rim.pushsdk.commons.content.BinaryContent
Direct Known Subclasses:
GifImageContent, JpegImageContent, Mp4AudioContent, Mp4VideoContent, MpegAudioContent, MpegVideoContent, PngImageContent, ThreeGPAudioContent, ThreeGPVideoContent

public class BinaryContent
extends SinglePartContent

Represents binary content, automatically sets the appropriate content type and content transfer encoding header for a binary payload to 'binary'.

If requested, base64 encoding will be done on the binary content and the content transfer encoding header will be set to base64.

Author:
mdicesare

Field Summary
static String CONTENT_TRANSFER_ENCODING_BASE64
          The base64 content transfer encoding.
static String CONTENT_TRANSFER_ENCODING_BINARY
          The binary content transfer encoding.
 
Fields inherited from class net.rim.pushsdk.commons.content.Content
BOUNDARY_DELIMITER_BYTES, contentType, headers, NEW_LINE, NEW_LINE_BYTES
 
Constructor Summary
BinaryContent(byte[] content, boolean shouldBase64Encode)
          Constructs content of a binary type.
BinaryContent(byte[] content, ContentType contentType, boolean shouldBase64Encode)
          Constructs content of a binary type.
BinaryContent(File file, boolean shouldBase64Encode)
          Constructs content of a binary type from the contents of the file.
BinaryContent(URL url, boolean shouldBase64Encode)
          Constructs content of a binary type from the contents of the URL.
 
Method Summary
 boolean isEmpty()
          Determines whether the content is empty.
 String toString()
          Constructs a String with all attributes in name = value format.
protected  void writeContentTo(ByteArrayOutputStream out)
          Writes content out to the specified output stream.
 
Methods inherited from class net.rim.pushsdk.commons.content.SinglePartContent
checkExtension, getBytesFromFile, getBytesFromURL, writeTo
 
Methods inherited from class net.rim.pushsdk.commons.content.Content
addHeader, getContentType, getHeader, getHeaders, setContentType, setHeader, writeHeadersTo
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

CONTENT_TRANSFER_ENCODING_BINARY

public static final String CONTENT_TRANSFER_ENCODING_BINARY
The binary content transfer encoding.

See Also:
Constant Field Values

CONTENT_TRANSFER_ENCODING_BASE64

public static final String CONTENT_TRANSFER_ENCODING_BASE64
The base64 content transfer encoding.

See Also:
Constant Field Values
Constructor Detail

BinaryContent

public BinaryContent(byte[] content,
                     boolean shouldBase64Encode)
Constructs content of a binary type. Automatically sets the content type header to application/octet-stream.

Parameters:
content - the binary content
shouldBase64Encode - whether content should be base64-encoded

BinaryContent

public BinaryContent(byte[] content,
                     ContentType contentType,
                     boolean shouldBase64Encode)
Constructs content of a binary type. Sets the content type header to the specified type.

Parameters:
content - the binary content
contentType - type used to set header
shouldBase64Encode - whether content should be base64-encoded

BinaryContent

public BinaryContent(File file,
                     boolean shouldBase64Encode)
              throws IOException
Constructs content of a binary type from the contents of the file. Automatically sets the content type header to application/octet-stream.

Parameters:
file - the binary content stored in a file
shouldBase64Encode - whether content should be base64-encoded
Throws:
IOException

BinaryContent

public BinaryContent(URL url,
                     boolean shouldBase64Encode)
              throws IOException
Constructs content of a binary type from the contents of the URL. Automatically sets the content type header to application/octet-stream.

Parameters:
url - the content URL
shouldBase64Encode - whether content should be base64-encoded
Throws:
IOException
Method Detail

toString

public String toString()
Constructs a String with all attributes in name = value format.

Overrides:
toString in class Content
Returns:
a String representation of this object.

isEmpty

public boolean isEmpty()
Description copied from class: Content
Determines whether the content is empty.

Specified by:
isEmpty in class Content
Returns:
true if the content is deemed to be empty; false otherwise

writeContentTo

protected void writeContentTo(ByteArrayOutputStream out)
                       throws IOException
Description copied from class: SinglePartContent
Writes content out to the specified output stream.

Specified by:
writeContentTo in class SinglePartContent
Parameters:
out - the output stream
Throws:
IOException - if any IO errors occur writing to the output stream


Copyright © 2011 Research In Motion. All Rights Reserved.