@Contract(threading=IMMUTABLE) public class StringEntity extends AbstractHttpEntity
String.| Constructor and Description |
|---|
StringEntity(String string)
Creates a StringEntity with the specified content.
|
StringEntity(String string,
java.nio.charset.Charset charset)
Creates a StringEntity with the specified content and charset.
|
StringEntity(String string,
java.nio.charset.Charset charset,
boolean chunked) |
StringEntity(String string,
ContentType contentType) |
StringEntity(String string,
ContentType contentType,
boolean chunked) |
StringEntity(String string,
ContentType contentType,
String contentEncoding,
boolean chunked)
Creates a StringEntity with the specified content and content type.
|
| Modifier and Type | Method and Description |
|---|---|
void |
close()
Closes this resource, relinquishing any underlying resources.
|
InputStream |
getContent()
Returns a content stream of the entity.
|
long |
getContentLength()
Returns length of the entity, if known.
|
boolean |
isRepeatable()
Tells if the entity is capable of producing its data more than once.
|
boolean |
isStreaming()
Tells whether this entity depends on an underlying stream.
|
void |
writeTo(OutputStream outStream)
Writes the entity content out to the output stream.
|
getContentEncoding, getContentType, getTrailerNames, getTrailers, isChunked, toString, writeTopublic StringEntity(String string)
ContentType.TEXT_PLAIN.string - content to be used. Not null.IllegalArgumentException - if the string parameter is nullpublic StringEntity(String string, java.nio.charset.Charset charset)
string - content to be used. Not null.charset - character set to be used. May be null, in which case the default
is StandardCharsets.ISO_8859_1 is assumedpublic StringEntity(String string, java.nio.charset.Charset charset, boolean chunked)
public StringEntity(String string, ContentType contentType)
public StringEntity(String string, ContentType contentType, boolean chunked)
public StringEntity(String string, ContentType contentType, String contentEncoding, boolean chunked)
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.public final void close()
throws IOException
AutoCloseabletry-with-resources statement.
While this interface method is declared to throw Exception, implementers are
strongly encouraged to declare concrete implementations of the close method to
throw more specific exceptions, or to throw no exception at all if the close operation cannot
fail.
Implementers of this interface are also strongly advised to not have the close method
throw InterruptedException.
This exception interacts with a thread's interrupted status.
Note that unlike the close method of Closeable,
this close method is not required to be idempotent. In other words, calling this
close method more than once may have some visible side effect, unlike
Closeable.close which is required to have no effect if called more than once.
However, implementers of this interface are strongly encouraged to make their close
methods idempotent.
IOException - if an I/O error occurspublic final InputStream getContent() throws IOException
HttpEntityRepeatable entities are expected
to create a new instance of InputStream for each invocation
of this method and therefore can be consumed multiple times.
Entities that are not repeatable are expected
to return the same InputStream instance and therefore
may not be consumed more than once.
IMPORTANT: Please note all entity implementations must ensure that
all allocated resources are properly deallocated after
the InputStream.close() method is invoked.
IOException - if the stream could not be createdHttpEntity.isRepeatable()public final long getContentLength()
EntityDetailspublic final boolean isRepeatable()
HttpEntityisRepeatable in interface HttpEntityisRepeatable in class AbstractHttpEntitypublic final boolean isStreaming()
HttpEntitytrue. Self-contained entities should return
false. Wrapping entities should delegate this call
to the wrapped entity.true if the entity content is streamed,
false otherwisepublic final void writeTo(OutputStream outStream) throws IOException
HttpEntityIMPORTANT: Please note all entity implementations must ensure that all allocated resources are properly deallocated when this method returns.
writeTo in interface HttpEntitywriteTo in class AbstractHttpEntityoutStream - the output stream to write entity content toIOException - if an I/O error occurs