Class FileClient


  • public class FileClient
    extends Object

    The FileClient assists in using the DataProvider with files, that are located on the local file system, as the data source. For instance, to read a file that contains json data, you can use the following code:

         FileClient fileClient = FileClient.create(new File("sample.json"));
         JsonInputConverter<Sample> converter = new JsonInputConverter<>(Sample.class);
         GluonObservableObject<Sample> sample = DataProvider.retrieveObject(fileClient.createObjectDataReader(converter));
     
    • Method Detail

      • create

        public static FileClient create​(File file)
        Create a FileClient builder using the specified file as a data source.
        Parameters:
        file - the file to be used as the data source
        Returns:
        a FileClient that can be used together with the DataProvider
      • createFileDataSource

        public FileDataSource createFileDataSource()
        Build a FileDataSource that can be used as an InputDataSource to read from the file or an OutputDataSource to write to the file.
        Returns:
        a FileDataSource that works with the file that was specified on this FileClient
      • createObjectDataReader

        public <T> ObjectDataReader<T> createObjectDataReader​(InputStreamInputConverter<T> converter)
        Creates an instance of ObjectDataReader that can be passed directly in the DataProvider.retrieveObject(ObjectDataReader) method. The object data reader will read the data from the file that was specified on this FileClient and convert it into an object by using the specified converter.
        Type Parameters:
        T - the type of the object to read
        Parameters:
        converter - the converter to use to convert the data read from the file into an object
        Returns:
        an ObjectDataReader instance that constructs an object from the file with the specified converter
      • createObjectDataWriter

        public <T> ObjectDataWriter<T> createObjectDataWriter​(OutputStreamOutputConverter<T> converter)
        Creates an instance of ObjectDataWriter that can be passed directly in the DataProvider.storeObject(Object, ObjectDataWriter) method. The object data writer will convert an object by using the specified converter and writes the converted data into the file that was specified on this FileClient.
        Type Parameters:
        T - the type of the object to write
        Parameters:
        converter - the converter to use to convert the object into data to write to the file
        Returns:
        an ObjectDataWriter instance that writes an object into the file with the specified converter
      • createObjectDataRemover

        public <T> ObjectDataRemover<T> createObjectDataRemover()
        Creates an instance of ObjectDataRemover that can be passed directly in the DataProvider.removeObject(GluonObservableObject, ObjectDataRemover) method. The actual observable object that is passed in with the removeObject method is ignored. The ObjectDataRemover will just remove the file that was specified on this FileClient.
        Type Parameters:
        T - the type of the object to remove
        Returns:
        an ObjectDataRemover instance that removes the file
      • createListDataReader

        public <T> ListDataReader<T> createListDataReader​(InputStreamIterableInputConverter<T> converter)
        Creates an instance of ListDataReader that can be passed directly in the DataProvider.retrieveList(ListDataReader) method. The list data reader will read the data from the file that was specified on this FileClient and convert it into a list of objects by using the specified converter.
        Type Parameters:
        T - the type of the objects contained in the list to read
        Parameters:
        converter - the converter to use to convert the data read from the file into a list of objects
        Returns:
        a ListDataReader instance that constructs a list of objects from the file with the specified converter