Class DataFile


  • public class DataFile
    extends DataObject
    A reference to a file in the data api
    • 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 API
      byte[] getBytes()
      Gets the data for this file as as string
      java.io.File getFile()
      Gets the data for this file and saves it to a local temporary file
      java.io.InputStream getInputStream()
      Gets the data for this file as an InputStream
      java.lang.String getString()
      Gets the data for this file as as string using UTF-8 charset
      java.lang.String getString​(java.nio.charset.Charset encoding)
      Gets the data for this file as as string using a custom charset
      void put​(byte[] data)
      Upload raw data to this file as binary
      void 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 stream
      void put​(java.lang.String data)
      Upload string data to this file as UTF-8 text
      void 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 java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • 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 class DataObject
        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 DataAPI
        java.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 API
        java.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 API
        java.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 API
        java.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 API
        java.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 API
        java.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