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 void
delete()
Deletes this file.boolean
exists()
Returns whether the file exists in the Data APIbyte[]
getBytes()
Gets the data for this file as as stringjava.io.File
getFile()
Gets the data for this file and saves it to a local temporary filejava.io.InputStream
getInputStream()
Gets the data for this file as an InputStreamjava.lang.String
getString()
Gets the data for this file as as string using UTF-8 charsetjava.lang.String
getString(java.nio.charset.Charset encoding)
Gets the data for this file as as string using a custom charsetvoid
put(byte[] data)
Upload raw data to this file as binaryvoid
put(java.io.File file)
Upload new data to this file from an existing file.void
put(java.io.InputStream is)
Upload raw data to this file as an input streamvoid
put(java.lang.String data)
Upload string data to this file as UTF-8 textvoid
put(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 APIException
Returns whether the file exists in the Data API- Specified by:
exists
in 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.IOException
Gets 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.IOException
Gets 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.IOException
Gets 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.IOException
Gets 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.IOException
Gets 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 APIException
Upload 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 APIException
Upload 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 APIException
Upload 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 APIException
Upload 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.FileNotFoundException
Upload 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 APIException
Deletes this file.- Throws:
APIException
- if there were any problems communicating with the Algorithmia API
-
-