Top Description Fields Constructors Methods
org.apache.http.entity

public Class FileEntity

extends AbstractHttpEntity
implements Cloneable
Class Inheritance
All Implemented Interfaces
java.lang.Cloneable
Imports
java.io.File, .FileInputStream, .IOException, .InputStream, .OutputStream, org.apache.http.util.Args

A self contained, repeatable entity that obtains its content from a file.
Since
4.0

Field Summary

Modifier and TypeField and Description
protected final File
Inherited from org.apache.http.entity.AbstractHttpEntity:
chunkedcontentEncodingcontentTypeOUTPUT_BUFFER_SIZE

Constructor Summary

AccessConstructor and Description
public
FileEntity(final File
The file to serve.
file
,
final String
The content type for the given file.
contentType
)

Deprecated (4.1.3) FileEntity(File, ContentType)
Creates a new instance.
public
FileEntity(final File
The file to serve.
file
,
final ContentType
The content type for the given file.
contentType
)

Creates a new instance.

public
FileEntity(final File
The file to serve.
file
)

Creates a new instance.

Method Summary

Modifier and TypeMethod and Description
public Object
clone()

Overrides java.lang.Object.clone.

Creates and returns a copy of this object.
public InputStream
getContent()

Implements org.apache.http.HttpEntity.getContent.

Returns a content stream of the entity.
public long
getContentLength()

Implements org.apache.http.HttpEntity.getContentLength.

Tells the length of the content, if known.
public boolean
isRepeatable()

Implements org.apache.http.HttpEntity.isRepeatable.

Tells if the entity is capable of producing its data more than once.
public boolean

Returns:

false
isStreaming
()

Implements org.apache.http.HttpEntity.isStreaming.

Tells that this entity is not streaming.
public void
writeTo(final OutputStream
the output stream to write entity content to
outStream
)

Implements org.apache.http.HttpEntity.writeTo.

Writes the entity content out to the output stream.
Inherited from org.apache.http.entity.AbstractHttpEntity:
consumeContentgetContentEncodinggetContentTypeisChunkedsetChunkedsetContentEncodingsetContentEncodingsetContentTypesetContentTypetoString

Field Detail

fileback to summary
protected final File file

Constructor Detail

FileEntityback to summary
public FileEntity(final File file, final String contentType)

Deprecated

(4.1.3) FileEntity(File, ContentType)

Creates a new instance.

Parameters
file:File

The file to serve.

contentType:String

The content type for the given file.

Annotations
@Deprecated
FileEntityback to summary
public FileEntity(final File file, final ContentType contentType)

Creates a new instance.

Parameters
file:File

The file to serve.

contentType:ContentType

The content type for the given file.

Since
4.2
FileEntityback to summary
public FileEntity(final File file)

Creates a new instance.

Parameters
file:File

The file to serve.

Since
4.2

Method Detail

cloneback to summary
public Object clone() throws CloneNotSupportedException

Overrides java.lang.Object.clone.

Doc from java.lang.Object.clone.

Creates and returns a copy of this object. The precise meaning of "copy" may depend on the class of the object. The general intent is that, for any object x, the expression:

x.clone() != x
will be true, and that the expression:
x.clone().getClass() == x.getClass()
will be true, but these are not absolute requirements. While it is typically the case that:
x.clone().equals(x)
will be true, this is not an absolute requirement.

By convention, the returned object should be obtained by calling super.clone. If a class and all of its superclasses (except Object) obey this convention, it will be the case that x.clone().getClass() == x.getClass().

By convention, the object returned by this method should be independent of this object (which is being cloned). To achieve this independence, it may be necessary to modify one or more fields of the object returned by super.clone before returning it. Typically, this means copying any mutable objects that comprise the internal "deep structure" of the object being cloned and replacing the references to these objects with references to the copies. If a class contains only primitive fields or references to immutable objects, then it is usually the case that no fields in the object returned by super.clone need to be modified.

Returns:Object

a clone of this instance.

Annotations
@Override
Exceptions
CloneNotSupportedException:
if the object's class does not support the Cloneable interface. Subclasses that override the clone method can also throw this exception to indicate that an instance cannot be cloned.
getContentback to summary
public InputStream getContent() throws IOException

Implements org.apache.http.HttpEntity.getContent.

Doc from org.apache.http.HttpEntity.getContent.

Returns a content stream of the entity. Repeatable 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 Note

Please note all entity implementations must ensure that all allocated resources are properly deallocated after the InputStream#close() method is invoked.

Returns:InputStream

content stream of the entity.

Annotations
@Override
Exceptions
IOException:
if the stream could not be created
getContentLengthback to summary
public long getContentLength()

Implements org.apache.http.HttpEntity.getContentLength.

Doc from org.apache.http.HttpEntity.getContentLength.

Tells the length of the content, if known.

Returns:long

the number of bytes of the content, or a negative number if unknown. If the content length is known but exceeds Long.MAX_VALUE, a negative number is returned.

Annotations
@Override
isRepeatableback to summary
public boolean isRepeatable()

Implements org.apache.http.HttpEntity.isRepeatable.

Doc from org.apache.http.HttpEntity.isRepeatable.

Tells if the entity is capable of producing its data more than once. A repeatable entity's getContent() and writeTo(OutputStream) methods can be called more than once whereas a non-repeatable entity's can not.

Returns:boolean

true if the entity is repeatable, false otherwise.

Annotations
@Override
isStreamingback to summary
public boolean isStreaming()

Implements org.apache.http.HttpEntity.isStreaming.

Tells that this entity is not streaming.

Returns:boolean

false

Annotations
@Override
writeToback to summary
public void writeTo(final OutputStream outStream) throws IOException

Implements org.apache.http.HttpEntity.writeTo.

Doc from org.apache.http.HttpEntity.writeTo.

Writes the entity content out to the output stream.

Important Note

Please note all entity implementations must ensure that all allocated resources are properly deallocated when this method returns.

Parameters
outStream:OutputStream

the output stream to write entity content to

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs