Package com.google.api.client.http
Class LowLevelHttpRequest
- java.lang.Object
-
- com.google.api.client.http.LowLevelHttpRequest
-
- Direct Known Subclasses:
Apache5HttpRequest,ApacheHttpRequest,ApacheHttpRequest,HttpHeaders.HeaderParsingFakeLevelHttpRequest,MockLowLevelHttpRequest,NetHttpRequest
public abstract class LowLevelHttpRequest extends java.lang.ObjectLow-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
-
-
Field Summary
Fields Modifier and Type Field Description private java.lang.StringcontentEncodingContent encoding (for example"gzip") ornullfor none.private longcontentLengthContent length or less than zero if not known.private java.lang.StringcontentTypeContent type ornullfor none.private StreamingContentstreamingContentStreaming content ornullfor no content.
-
Constructor Summary
Constructors Constructor Description LowLevelHttpRequest()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract voidaddHeader(java.lang.String name, java.lang.String value)Adds a header to the HTTP request.abstract LowLevelHttpResponseexecute()Executes the request and returns a low-level HTTP response object.java.lang.StringgetContentEncoding()Returns the content encoding (for example"gzip") ornullfor none.longgetContentLength()Returns the content length or less than zero if not known.java.lang.StringgetContentType()Returns the content type ornullfor none.StreamingContentgetStreamingContent()Returns the streaming content ornullfor no content.voidsetContentEncoding(java.lang.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(java.lang.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.voidsetWriteTimeout(int writeTimeout)Sets the write timeout for POST/PUT requests.
-
-
-
Field Detail
-
contentLength
private long contentLength
Content length or less than zero if not known.
-
contentEncoding
private java.lang.String contentEncoding
Content encoding (for example"gzip") ornullfor none.
-
contentType
private java.lang.String contentType
Content type ornullfor none.
-
streamingContent
private StreamingContent streamingContent
Streaming content ornullfor no content.
-
-
Method Detail
-
addHeader
public abstract void addHeader(java.lang.String name, java.lang.String value) throws java.io.IOExceptionAdds 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:
java.io.IOException
-
setContentLength
public final void setContentLength(long contentLength) throws java.io.IOExceptionSets the content length or less than zero if not known.Default value is
-1.- Throws:
java.io.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(java.lang.String contentEncoding) throws java.io.IOExceptionSets the content encoding (for example"gzip") ornullfor none.- Throws:
java.io.IOException- I/O exception- Since:
- 1.14
-
getContentEncoding
public final java.lang.String getContentEncoding()
Returns the content encoding (for example"gzip") ornullfor none.- Since:
- 1.14
-
setContentType
public final void setContentType(java.lang.String contentType) throws java.io.IOExceptionSets the content type ornullfor none.- Throws:
java.io.IOException- I/O exception- Since:
- 1.14
-
getContentType
public final java.lang.String getContentType()
Returns the content type ornullfor none.- Since:
- 1.14
-
setStreamingContent
public final void setStreamingContent(StreamingContent streamingContent) throws java.io.IOException
Sets the streaming content ornullfor no content.- Throws:
java.io.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 java.io.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:
java.io.IOException- I/O exception- Since:
- 1.4
-
setWriteTimeout
public void setWriteTimeout(int writeTimeout) throws java.io.IOExceptionSets the write timeout for POST/PUT requests.Default implementation does nothing, but subclasses should normally override.
- Parameters:
writeTimeout- timeout in milliseconds to establish a connection or0for an infinite timeout- Throws:
java.io.IOException- I/O exception- Since:
- 1.27
-
execute
public abstract LowLevelHttpResponse execute() throws java.io.IOException
Executes the request and returns a low-level HTTP response object.- Throws:
java.io.IOException
-
-