|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.google.api.client.http.AbstractInputStreamContent
com.google.api.client.http.InputStreamContent
public final class InputStreamContent
Concrete implementation of AbstractInputStreamContent that simply handles the transfer of
data from an input stream to an output stream. This should only be used for streams that can not
be re-opened and retried. If you have a stream that it is possible to recreate please create a
new subclass of AbstractInputStreamContent.
The AbstractInputStreamContent.type field is required. The input stream is guaranteed to be closed at the end of
AbstractInputStreamContent.writeTo(OutputStream).
Sample use with a URL:
private static void setRequestJpegContent(HttpRequest request, URL jpegUrl) throws IOException {
InputStreamContent content = new InputStreamContent();
content.inputStream = jpegUrl.openStream();
content.type = "image/jpeg";
request.content = content;
}
| Field Summary | |
|---|---|
InputStream |
inputStream
Required input stream to read from. |
long |
length
Content length or less than zero if not known. |
| Fields inherited from class com.google.api.client.http.AbstractInputStreamContent |
|---|
encoding, type |
| Constructor Summary | |
|---|---|
InputStreamContent()
|
|
| Method Summary | |
|---|---|
static void |
copy(InputStream inputStream,
OutputStream outputStream)
Deprecated. Scheduled for removal in version 1.5. Please use AbstractInputStreamContent.copy(java.io.InputStream, java.io.OutputStream) as an alternative. |
protected InputStream |
getInputStream()
Return an input stream for the specific implementation type of AbstractInputStreamContent. |
long |
getLength()
Returns the content length or less than zero if not known. |
boolean |
retrySupported()
Returns whether or not retry is supported on this content type. |
void |
setByteArrayInput(byte[] content)
Deprecated. Scheduled for removal in 1.5. Please use ByteArrayContent instead. |
void |
setFileInput(File file)
Deprecated. Scheduled for removal in 1.5. Please use FileContent instead. |
| Methods inherited from class com.google.api.client.http.AbstractInputStreamContent |
|---|
getEncoding, getType, writeTo |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public long length
-1.
public InputStream inputStream
| Constructor Detail |
|---|
public InputStreamContent()
| Method Detail |
|---|
@Deprecated
public void setFileInput(File file)
throws FileNotFoundException
FileContent instead.
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)
throws FileNotFoundException {
InputStreamContent content = new InputStreamContent();
content.setFileInput(jpegFile);
content.type = "image/jpeg";
request.content = content;
}
FileNotFoundException@Deprecated public void setByteArrayInput(byte[] content)
ByteArrayContent instead.
inputStream and length from the given byte array.
For string input, call the appropriate String.getBytes(int, int, byte[], int) method.
Sample use:
static void setRequestJsonContent(HttpRequest request, String json) {
InputStreamContent content = new InputStreamContent();
content.setByteArrayInput(Strings.toBytesUtf8(json));
content.type = "application/json";
request.content = content;
}
public long getLength()
HttpContent
public boolean retrySupported()
HttpContent
protected InputStream getInputStream()
AbstractInputStreamContentAbstractInputStreamContent. If the specific implementation will return true for
HttpContent.retrySupported() this should be a factory function which will create a new
InputStream from the source data whenever invoked.
getInputStream in class AbstractInputStreamContent
@Deprecated
public static void copy(InputStream inputStream,
OutputStream outputStream)
throws IOException
AbstractInputStreamContent.copy(java.io.InputStream, java.io.OutputStream) as an alternative.
The input stream is guaranteed to be closed at the end of the method.
Sample use:
static void downloadMedia(HttpResponse response, File file)
throws IOException {
FileOutputStream out = new FileOutputStream(file);
try {
InputStreamContent.copy(response.getContent(), out);
} finally {
out.close();
}
}
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 | |||||||||