Package com.algorithmia.data
Class DataFile
- java.lang.Object
-
- com.algorithmia.data.DataObject
-
- com.algorithmia.data.DataFile
-
public class DataFile extends DataObject
A reference to a file in the data api
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class com.algorithmia.data.DataObject
DataObject.DataObjectType
-
-
Field Summary
-
Fields inherited from class com.algorithmia.data.DataObject
client, dataType, path
-
-
Constructor Summary
Constructors Constructor Description DataFile(HttpClient client, java.lang.String dataUrl)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voiddelete()Deletes this file.booleanexists()Returns whether the file exists in the Data APIbyte[]getBytes()Gets the data for this file as as stringjava.io.FilegetFile()Gets the data for this file and saves it to a local temporary filejava.io.InputStreamgetInputStream()Gets the data for this file as an InputStreamjava.lang.StringgetString()Gets the data for this file as as string using UTF-8 charsetjava.lang.StringgetString(java.nio.charset.Charset encoding)Gets the data for this file as as string using a custom charsetvoidput(byte[] data)Upload raw data to this file as binaryvoidput(java.io.File file)Upload new data to this file from an existing file.voidput(java.io.InputStream is)Upload raw data to this file as an input streamvoidput(java.lang.String data)Upload string data to this file as UTF-8 textvoidput(java.lang.String data, java.nio.charset.Charset charset)Upload string data to this file as text using a custom Charset-
Methods inherited from class com.algorithmia.data.DataObject
getName, getParent, getType, getUrl, isDirectory, isFile, toString
-
-
-
-
Constructor Detail
-
DataFile
public DataFile(HttpClient client, java.lang.String dataUrl)
-
-
Method Detail
-
exists
public boolean exists() throws APIExceptionReturns whether the file exists in the Data API- Specified by:
existsin classDataObject- Returns:
- true iff the file exists
- Throws:
APIException- if there were any problems communicating with the DataAPI
-
getFile
public java.io.File getFile() throws APIException, java.io.IOExceptionGets the data for this file and saves it to a local temporary file- Returns:
- the data as a local temporary file
- Throws:
APIException- if there were any problems communicating with the DataAPIjava.io.IOException- if there were any problems consuming the response content
-
getInputStream
public java.io.InputStream getInputStream() throws APIException, java.io.IOExceptionGets the data for this file as an InputStream- Returns:
- the data as an InputStream
- Throws:
APIException- if there were any problems communicating with the Algorithmia APIjava.io.IOException- if there were any problems consuming the response content
-
getString
public java.lang.String getString() throws java.io.IOExceptionGets the data for this file as as string using UTF-8 charset- Returns:
- the data as a String
- Throws:
APIException- if there were any problems communicating with the Algorithmia APIjava.io.IOException- if there were any problems consuming the response content
-
getString
public java.lang.String getString(java.nio.charset.Charset encoding) throws java.io.IOExceptionGets the data for this file as as string using a custom charset- Parameters:
encoding- the character encoding of the string- Returns:
- the data as a String
- Throws:
APIException- if there were any problems communicating with the Algorithmia APIjava.io.IOException- if there were any problems consuming the response content
-
getBytes
public byte[] getBytes() throws java.io.IOExceptionGets the data for this file as as string- Returns:
- the data as a String
- Throws:
APIException- if there were any problems communicating with the Algorithmia APIjava.io.IOException- if there were any problems consuming the response content
-
put
public void put(java.lang.String data) throws APIExceptionUpload string data to this file as UTF-8 text- Parameters:
data- the data to upload- Throws:
APIException- if there were any problems communicating with the Algorithmia API
-
put
public void put(java.lang.String data, java.nio.charset.Charset charset) throws APIExceptionUpload string data to this file as text using a custom Charset- Parameters:
data- the data to upload- Throws:
APIException- if there were any problems communicating with the Algorithmia API
-
put
public void put(byte[] data) throws APIExceptionUpload raw data to this file as binary- Parameters:
data- the data to upload- Throws:
APIException- if there were any problems communicating with the Algorithmia API
-
put
public void put(java.io.InputStream is) throws APIExceptionUpload raw data to this file as an input stream- Parameters:
is- the input stream of data to upload- Throws:
APIException- if there were any problems communicating with the Algorithmia API
-
put
public void put(java.io.File file) throws APIException, java.io.FileNotFoundExceptionUpload new data to this file from an existing file. These is a convenience wrapper for using InputStream.- Parameters:
file- the file to upload data from- Throws:
APIException- if there were any problems communicating with the Algorithmia APIjava.io.FileNotFoundException- if the specified file does not exist
-
delete
public void delete() throws APIExceptionDeletes this file.- Throws:
APIException- if there were any problems communicating with the Algorithmia API
-
-