Class EmptyContent (1.42.2)

Stay organized with collections Save and categorize content based on your preferences.
public class EmptyContent implements HttpContent

Empty HTTP content of length zero just to force HttpRequest#execute() to add the header Content-Length: 0.

Note that there is no Content-Length header if the HTTP request content is null . However, when making a request like PUT or POST without a Content-Length header, some servers may respond with a 411 Length Required error. Specifying the Content-Length: 0 header may work around that problem.

Inheritance

java.lang.Object > EmptyContent

Implements

HttpContent

Constructors

EmptyContent()

public EmptyContent()

Methods

getLength()

public long getLength()

Returns the content length or less than zero if not known.

Returns
TypeDescription
long
Exceptions
TypeDescription
IOException

getType()

public String getType()

Returns the content type or null for none.

Returns
TypeDescription
String

retrySupported()

public boolean retrySupported()

Returns whether or not retry is supported on this content type.

Returns
TypeDescription
boolean

writeTo(OutputStream out)

public void writeTo(OutputStream out)

Writes the byte content to the given output stream.

Implementations must not close the output stream, and instead should flush the output stream. Some callers may assume that the output stream has not been closed, and will fail to work if it has been closed.

Parameter
NameDescription
outOutputStream
Exceptions
TypeDescription
IOException