org.apache.http.entity
Class StringEntityHC4

java.lang.Object
  extended by org.apache.http.entity.AbstractHttpEntityHC4
      extended by org.apache.http.entity.StringEntityHC4
All Implemented Interfaces:
java.lang.Cloneable, org.apache.http.HttpEntity
Direct Known Subclasses:
UrlEncodedFormEntityHC4

@NotThreadSafe
public class StringEntityHC4
extends AbstractHttpEntityHC4
implements java.lang.Cloneable

A self contained, repeatable entity that obtains its content from a String.

Since:
4.0

Field Summary
protected  byte[] content
           
 
Fields inherited from class org.apache.http.entity.AbstractHttpEntityHC4
chunked, contentEncoding, contentType, OUTPUT_BUFFER_SIZE
 
Constructor Summary
StringEntityHC4(java.lang.String string)
          Creates a StringEntityHC4 with the specified content.
StringEntityHC4(java.lang.String string, java.nio.charset.Charset charset)
          Creates a StringEntityHC4 with the specified content and charset.
StringEntityHC4(java.lang.String string, ContentType contentType)
          Creates a StringEntityHC4 with the specified content and content type.
StringEntityHC4(java.lang.String string, java.lang.String charset)
          Creates a StringEntityHC4 with the specified content and charset.
StringEntityHC4(java.lang.String string, java.lang.String mimeType, java.lang.String charset)
          Deprecated. (4.1.3) use StringEntityHC4(String, ContentType)
 
Method Summary
 java.lang.Object clone()
           
 java.io.InputStream getContent()
           
 long getContentLength()
           
 boolean isRepeatable()
           
 boolean isStreaming()
          Tells that this entity is not streaming.
 void writeTo(java.io.OutputStream outstream)
           
 
Methods inherited from class org.apache.http.entity.AbstractHttpEntityHC4
consumeContent, getContentEncoding, getContentType, isChunked, setChunked, setContentEncoding, setContentEncoding, setContentType, setContentType
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

content

protected final byte[] content
Constructor Detail

StringEntityHC4

public StringEntityHC4(java.lang.String string,
                       ContentType contentType)
                throws java.nio.charset.UnsupportedCharsetException
Creates a StringEntityHC4 with the specified content and content type.

Parameters:
string - content to be used. Not null.
contentType - content type to be used. May be null, in which case the default MIME type ContentType.TEXT_PLAIN is assumed.
Throws:
java.lang.IllegalArgumentException - if the string parameter is null
java.nio.charset.UnsupportedCharsetException - Thrown when the named charset is not available in this instance of the Java virtual machine
Since:
4.2

StringEntityHC4

@Deprecated
public StringEntityHC4(java.lang.String string,
                                  java.lang.String mimeType,
                                  java.lang.String charset)
                throws java.io.UnsupportedEncodingException
Deprecated. (4.1.3) use StringEntityHC4(String, ContentType)

Creates a StringEntityHC4 with the specified content, MIME type and charset

Parameters:
string - content to be used. Not null.
mimeType - MIME type to be used. May be null, in which case the default is HTTP.PLAIN_TEXT_TYPE i.e. "text/plain"
charset - character set to be used. May be null, in which case the default is HTTP.DEFAULT_CONTENT_CHARSET i.e. "ISO-8859-1"
Throws:
java.io.UnsupportedEncodingException - If the named charset is not supported.
java.lang.IllegalArgumentException - if the string parameter is null
Since:
4.1

StringEntityHC4

public StringEntityHC4(java.lang.String string,
                       java.lang.String charset)
                throws java.nio.charset.UnsupportedCharsetException
Creates a StringEntityHC4 with the specified content and charset. The MIME type defaults to "text/plain".

Parameters:
string - content to be used. Not null.
charset - character set to be used. May be null, in which case the default is HTTP.DEFAULT_CONTENT_CHARSET is assumed
Throws:
java.lang.IllegalArgumentException - if the string parameter is null
java.nio.charset.UnsupportedCharsetException - Thrown when the named charset is not available in this instance of the Java virtual machine

StringEntityHC4

public StringEntityHC4(java.lang.String string,
                       java.nio.charset.Charset charset)
Creates a StringEntityHC4 with the specified content and charset. The MIME type defaults to "text/plain".

Parameters:
string - content to be used. Not null.
charset - character set to be used. May be null, in which case the default is HTTP.DEFAULT_CONTENT_CHARSET is assumed
Throws:
java.lang.IllegalArgumentException - if the string parameter is null
Since:
4.2

StringEntityHC4

public StringEntityHC4(java.lang.String string)
                throws java.io.UnsupportedEncodingException
Creates a StringEntityHC4 with the specified content. The content type defaults to ContentType.TEXT_PLAIN.

Parameters:
string - content to be used. Not null.
Throws:
java.lang.IllegalArgumentException - if the string parameter is null
java.io.UnsupportedEncodingException - if the default HTTP charset is not supported.
Method Detail

isRepeatable

public boolean isRepeatable()
Specified by:
isRepeatable in interface org.apache.http.HttpEntity

getContentLength

public long getContentLength()
Specified by:
getContentLength in interface org.apache.http.HttpEntity

getContent

public java.io.InputStream getContent()
                               throws java.io.IOException
Specified by:
getContent in interface org.apache.http.HttpEntity
Throws:
java.io.IOException

writeTo

public void writeTo(java.io.OutputStream outstream)
             throws java.io.IOException
Specified by:
writeTo in interface org.apache.http.HttpEntity
Throws:
java.io.IOException

isStreaming

public boolean isStreaming()
Tells that this entity is not streaming.

Specified by:
isStreaming in interface org.apache.http.HttpEntity
Returns:
false

clone

public java.lang.Object clone()
                       throws java.lang.CloneNotSupportedException
Overrides:
clone in class java.lang.Object
Throws:
java.lang.CloneNotSupportedException