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 void
addHeader(String name, String value)
Adds a header to the HTTP request.abstract LowLevelHttpResponse
execute()
Executes the request and returns a low-level HTTP response object.String
getContentEncoding()
Returns the content encoding (for example"gzip"
) ornull
for none.long
getContentLength()
Returns the content length or less than zero if not known.String
getContentType()
Returns the content type ornull
for none.StreamingContent
getStreamingContent()
Returns the streaming content ornull
for no content.void
setContentEncoding(String contentEncoding)
Sets the content encoding (for example"gzip"
) ornull
for none.void
setContentLength(long contentLength)
Sets the content length or less than zero if not known.void
setContentType(String contentType)
Sets the content type ornull
for none.void
setStreamingContent(StreamingContent streamingContent)
Sets the streaming content ornull
for no content.void
setTimeout(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 IOException
Sets 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"
) ornull
for none.- Throws:
IOException
- I/O exception- Since:
- 1.14
-
getContentEncoding
public final String getContentEncoding()
Returns the content encoding (for example"gzip"
) ornull
for none.- Since:
- 1.14
-
setContentType
public final void setContentType(String contentType) throws IOException
Sets the content type ornull
for none.- Throws:
IOException
- I/O exception- Since:
- 1.14
-
getContentType
public final String getContentType()
Returns the content type ornull
for none.- Since:
- 1.14
-
setStreamingContent
public final void setStreamingContent(StreamingContent streamingContent) throws IOException
Sets the streaming content ornull
for no content.- Throws:
IOException
- I/O exception- Since:
- 1.14
-
getStreamingContent
public final StreamingContent getStreamingContent()
Returns the streaming content ornull
for no content.- Since:
- 1.14
-
setTimeout
public void setTimeout(int connectTimeout, int readTimeout) throws IOException
Sets the connection and read timeouts.Default implementation does nothing, but subclasses should normally override.
- Parameters:
connectTimeout
- timeout in milliseconds to establish a connection or0
for an infinite timeoutreadTimeout
- Timeout in milliseconds to read data from an established connection or0
for 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
-
-