|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.google.api.client.http.InputStreamContent
public final class InputStreamContent
Serializes HTTP request content from an input stream into an output stream.
The type and inputStream fields are required. The input
stream is guaranteed to be closed at the end of
writeTo(OutputStream).
For a file input, use setFileInput(File), and for a byte array or
string input use setByteArrayInput(byte[]).
Sample use with a URL:
private static void setRequestJpegContent(HttpRequest request, URL jpegUrl) {
InputStreamContent content = new InputStreamContent();
content.inputStream = jpegUrl.openStream();
content.type = "image/jpeg";
request.content = content;
}
| Field Summary | |
|---|---|
String |
encoding
Content encoding (for example "gzip") or null for none. |
InputStream |
inputStream
Required input stream to read from. |
long |
length
Content length or less than zero if not known. |
String |
type
Required content type. |
| Constructor Summary | |
|---|---|
InputStreamContent()
|
|
| Method Summary | |
|---|---|
static void |
copy(InputStream inputStream,
OutputStream outputStream)
Writes the content provided by the given source input stream into the given destination output stream. |
String |
getEncoding()
Returns the content encoding (for example "gzip") or null
for none. |
long |
getLength()
Returns the content length or less than zero if not known. |
String |
getType()
Returns the content type. |
void |
setByteArrayInput(byte[] content)
Sets the inputStream and length from the given byte
array. |
void |
setFileInput(File file)
Sets the inputStream from a file input stream based on the given
file, and the length based on the file's length. |
void |
writeTo(OutputStream out)
Writes the content to the given output stream. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public String type
public long length
-1.
public InputStream inputStream
public String encoding
"gzip") or null for none.
| Constructor Detail |
|---|
public InputStreamContent()
| Method Detail |
|---|
public void setFileInput(File file)
throws FileNotFoundException
inputStream from a file input stream based on the given
file, and the length based on the file's length.
Sample use:
private static void setRequestJpegContent(HttpRequest request, File jpegFile) {
InputStreamContent content = new InputStreamContent();
content.setFileInput(jpegFile);
content.type = "image/jpeg";
request.content = content;
}
FileNotFoundExceptionpublic void setByteArrayInput(byte[] content)
inputStream and length from the given byte
array.
For string input, call the appropriate String.getBytes(int, int, byte[], int) method.
Sample use:
private static void setRequestJsonContent(HttpRequest request, String json) {
InputStreamContent content = new InputStreamContent();
content.setByteArrayInput(json.getBytes());
content.type = "application/json";
request.content = content;
}
public void writeTo(OutputStream out)
throws IOException
HttpContent
writeTo in interface HttpContentIOExceptionpublic String getEncoding()
HttpContent"gzip") or null
for none.
getEncoding in interface HttpContentpublic long getLength()
HttpContent
getLength in interface HttpContentpublic String getType()
HttpContent
getType in interface HttpContent
public static void copy(InputStream inputStream,
OutputStream outputStream)
throws IOException
The input stream is guaranteed to be closed at the end of the method.
inputStream - source input streamoutputStream - destination output stream
IOException - I/O exception
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||