org.apache.commons.httpclient.methods

Class InputStreamRequestEntity

Implemented Interfaces:
RequestEntity

public class InputStreamRequestEntity
extends java.lang.Object
implements RequestEntity

A RequestEntity that contains an InputStream.
Since:
3.0

Field Summary

static int
CONTENT_LENGTH_AUTO
The content length will be calculated automatically.

Constructor Summary

InputStreamRequestEntity(InputStream content)
Creates a new InputStreamRequestEntity with the given content and a content type of CONTENT_LENGTH_AUTO.
InputStreamRequestEntity(InputStream content, String contentType)
Creates a new InputStreamRequestEntity with the given content, content type, and a content length of CONTENT_LENGTH_AUTO.
InputStreamRequestEntity(InputStream content, long contentLength)
Creates a new InputStreamRequestEntity with the given content and content length.
InputStreamRequestEntity(InputStream content, long contentLength, String contentType)
Creates a new InputStreamRequestEntity with the given content, content length, and content type.

Method Summary

InputStream
getContent()
long
getContentLength()
Gets the content length.
String
getContentType()
Gets the entity's content type.
boolean
isRepeatable()
Tests if this method is repeatable.
void
writeRequest(OutputStream out)
Writes the request entity to the given stream.

Field Details

CONTENT_LENGTH_AUTO

public static final int CONTENT_LENGTH_AUTO
The content length will be calculated automatically. This implies buffering of the content.
Field Value:
-2

Constructor Details

InputStreamRequestEntity

public InputStreamRequestEntity(InputStream content)
Parameters:
content - The content to set.

InputStreamRequestEntity

public InputStreamRequestEntity(InputStream content,
                                String contentType)
Parameters:
content - The content to set.
contentType - The type of the content, or null.

InputStreamRequestEntity

public InputStreamRequestEntity(InputStream content,
                                long contentLength)
Creates a new InputStreamRequestEntity with the given content and content length.
Parameters:
content - The content to set.
contentLength - The content size in bytes or any of CONTENT_LENGTH_AUTO, CONTENT_LENGTH_CHUNKED. If the number of bytes or CONTENT_LENGTH_CHUNKED is specified the content will not be buffered when getContentLength() is called.

InputStreamRequestEntity

public InputStreamRequestEntity(InputStream content,
                                long contentLength,
                                String contentType)
Creates a new InputStreamRequestEntity with the given content, content length, and content type.
Parameters:
content - The content to set.
contentLength - The content size in bytes or any of CONTENT_LENGTH_AUTO, CONTENT_LENGTH_CHUNKED. If the number of bytes or CONTENT_LENGTH_CHUNKED is specified the content will not be buffered when getContentLength() is called.
contentType - The type of the content, or null.

Method Details

getContent

public InputStream getContent()
Returns:
Returns the content.

getContentLength

public long getContentLength()
Gets the content length. If the content length has not been set, the content will be buffered to determine the actual content length.
Specified by:
getContentLength in interface RequestEntity

getContentType

public String getContentType()
Gets the entity's content type. This content type will be used as the value for the "Content-Type" header.
Specified by:
getContentType in interface RequestEntity
Returns:
the entity's content type

isRepeatable

public boolean isRepeatable()
Tests if this method is repeatable. Only true if the content has been buffered.
Specified by:
isRepeatable in interface RequestEntity

writeRequest

public void writeRequest(OutputStream out)
            throws IOException
Writes the request entity to the given stream.
Specified by:
writeRequest in interface RequestEntity
Parameters:
out -

Copyright (c) 1999-2005 - Apache Software Foundation