net.rim.pushsdk.commons.content
Class TextContent

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.TextContent
Direct Known Subclasses:
HtmlContent, XmlContent

public class TextContent
extends SinglePartContent

Represents text content. It will automatically set the appropriate content type for a text payload and a charset param if specified.

Author:
mdicesare

Field Summary
 
Fields inherited from class net.rim.pushsdk.commons.content.Content
BOUNDARY_DELIMITER_BYTES, contentType, headers, NEW_LINE, NEW_LINE_BYTES
 
Constructor Summary
TextContent(File file)
          Constructs content of a text type from the contents of the file.
TextContent(File file, String characterSet)
          Constructs content of a text type from the contents of the file.
TextContent(String content)
          Constructs content of a text type.
TextContent(String content, ContentType contentType)
          Constructs content of a text type.
TextContent(String content, String characterSet)
          Constructs content of a text type.
TextContent(URL url)
          Constructs content of a text type from the contents of the URL.
 
Method Summary
protected  void checkExtension(String string)
          Verifies that the file ends in the .txt file extension.
protected  String getCharacterSet(URL url)
          Gets the character set for the specified URL.
 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)
          Note: The text content will be encoded to the specified character set if the content type for this content has a charset parameter.
 
Methods inherited from class net.rim.pushsdk.commons.content.SinglePartContent
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
 

Constructor Detail

TextContent

public TextContent(String content)
Constructs content of a text type. Automatically sets the content type header to text/plain. The default platform character encoding (file.encoding) will be used to encode the textual content before being sent over the wire.

Parameters:
content - the textual content

TextContent

public TextContent(String content,
                   String characterSet)
Constructs content of a text type. Automatically sets the content type header to text/plain. A character set parameter can be specified; the text content will be encoded into that character set before being sent over the wire.

Parameters:
content - the textual content
characterSet - the character set to encode the textual content

TextContent

public TextContent(File file)
            throws IOException
Constructs content of a text type from the contents of the file. Automatically sets the content type header to text/plain. The default platform character encoding (file.encoding) will be used to encode the textual content before being sent over the wire.

Parameters:
file - the text content stored in a file
Throws:
IOException

TextContent

public TextContent(File file,
                   String characterSet)
            throws IOException
Constructs content of a text type from the contents of the file. Automatically sets the content type header to text/plain. The text content will be encoded into that character set before being sent over the wire.

Parameters:
file - the text content stored in a file
characterSet - the character set to encode the textual content
Throws:
IOException - if any error occurs regarding the file passed in

TextContent

public TextContent(URL url)
            throws IOException
Constructs content of a text type from the contents of the URL. Automatically sets the content type header to text/plain. If the URL has a character set it will be used, otherwise the default platform character encoding (file.encoding) will be used to encode the textual content before being sent over the wire.

Parameters:
url - the content URL
Throws:
IOException

TextContent

public TextContent(String content,
                   ContentType contentType)
Constructs content of a text type. Sets the content type header to the specified content type. If the content type specified does not contain a character set parameter, the default platform character encoding (file.encoding) will be used to encode the textual content before being sent over the wire.

Parameters:
content - the textual content
contentType - type used to set header
Method Detail

writeContentTo

protected void writeContentTo(ByteArrayOutputStream out)
                       throws IOException
Note: The text content will be encoded to the specified character set if the content type for this content has a charset parameter. Otherwise, the default character set will be used.

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

checkExtension

protected void checkExtension(String string)
Verifies that the file ends in the .txt file extension.

Overrides:
checkExtension in class SinglePartContent
Parameters:
string - the file name

getCharacterSet

protected String getCharacterSet(URL url)
                          throws IOException
Gets the character set for the specified URL.

Parameters:
url - the URL
Returns:
the URL's character set
Throws:
IOException - if any IO errors occur reading from the URL

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

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.


Copyright © 2011 Research In Motion. All Rights Reserved.