Package com.google.api.client.http
Class LowLevelHttpRequest
- java.lang.Object
-
- com.google.api.client.http.LowLevelHttpRequest
-
- Direct Known Subclasses:
MockLowLevelHttpRequest
public abstract class LowLevelHttpRequest extends Object
Low-level HTTP request.This allows providing a different implementation of the HTTP request that is more compatible with the Java environment used.
Implementation has no fields and therefore thread-safe, but sub-classes are not necessarily thread-safe.
- Since:
- 1.0
- Author:
- Yaniv Inbar
-
-
Constructor Summary
Constructors Constructor Description LowLevelHttpRequest()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract voidaddHeader(String name, String value)Adds a header to the HTTP request.abstract LowLevelHttpResponseexecute()Executes the request and returns a low-level HTTP response object.StringgetContentEncoding()Returns the content encoding (for example"gzip") ornullfor none.longgetContentLength()Returns the content length or less than zero if not known.StringgetContentType()Returns the content type ornullfor none.StreamingContentgetStreamingContent()Returns the streaming content ornullfor no content.voidsetContentEncoding(String contentEncoding)Sets the content encoding (for example"gzip") ornullfor none.voidsetContentLength(long contentLength)Sets the content length or less than zero if not known.voidsetContentType(String contentType)Sets the content type ornullfor none.voidsetStreamingContent(StreamingContent streamingContent)Sets the streaming content ornullfor no content.voidsetTimeout(int connectTimeout, int readTimeout)Sets the connection and read timeouts.
-
-
-
Method Detail
-
addHeader
public abstract void addHeader(String name, String value) throws IOException
Adds a header to the HTTP request.Note that multiple headers of the same name need to be supported, in which case
addHeader(java.lang.String, java.lang.String)will be called for each instance of the header.- Parameters:
name- header namevalue- header value- Throws:
IOException
-
setContentLength
public final void setContentLength(long contentLength) throws IOExceptionSets the content length or less than zero if not known.Default value is
-1.- Throws:
IOException- I/O exception- Since:
- 1.14
-
getContentLength
public final long getContentLength()
Returns the content length or less than zero if not known.- Since:
- 1.14
-
setContentEncoding
public final void setContentEncoding(String contentEncoding) throws IOException
Sets the content encoding (for example"gzip") ornullfor none.- Throws:
IOException- I/O exception- Since:
- 1.14
-
getContentEncoding
public final String getContentEncoding()
Returns the content encoding (for example"gzip") ornullfor none.- Since:
- 1.14
-
setContentType
public final void setContentType(String contentType) throws IOException
Sets the content type ornullfor none.- Throws:
IOException- I/O exception- Since:
- 1.14
-
getContentType
public final String getContentType()
Returns the content type ornullfor none.- Since:
- 1.14
-
setStreamingContent
public final void setStreamingContent(StreamingContent streamingContent) throws IOException
Sets the streaming content ornullfor no content.- Throws:
IOException- I/O exception- Since:
- 1.14
-
getStreamingContent
public final StreamingContent getStreamingContent()
Returns the streaming content ornullfor no content.- Since:
- 1.14
-
setTimeout
public void setTimeout(int connectTimeout, int readTimeout) throws IOExceptionSets the connection and read timeouts.Default implementation does nothing, but subclasses should normally override.
- Parameters:
connectTimeout- timeout in milliseconds to establish a connection or0for an infinite timeoutreadTimeout- Timeout in milliseconds to read data from an established connection or0for an infinite timeout- Throws:
IOException- I/O exception- Since:
- 1.4
-
execute
public abstract LowLevelHttpResponse execute() throws IOException
Executes the request and returns a low-level HTTP response object.- Throws:
IOException
-
-