public class FileClient
extends java.lang.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));
Modifier and Type | Method and Description |
---|---|
static FileClient |
create(java.io.File file)
Create a FileClient builder using the specified file as a data source.
|
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.
|
<T> ListDataReader<T> |
createListDataReader(InputStreamIterableInputConverter<T> converter)
Creates an instance of
ListDataReader that can be passed directly in the
DataProvider.retrieveList(ListDataReader) method. |
<T> ObjectDataReader<T> |
createObjectDataReader(InputStreamInputConverter<T> converter)
Creates an instance of
ObjectDataReader that can be passed directly in the
DataProvider.retrieveObject(ObjectDataReader) method. |
<T> ObjectDataRemover<T> |
createObjectDataRemover()
Creates an instance of
ObjectDataRemover that can be passed directly in the
DataProvider.removeObject(GluonObservableObject, ObjectDataRemover) method. |
<T> ObjectDataWriter<T> |
createObjectDataWriter(OutputStreamOutputConverter<T> converter)
Creates an instance of
ObjectDataWriter that can be passed directly in the
DataProvider.storeObject(Object, ObjectDataWriter) method. |
public static FileClient create(java.io.File file)
file
- the file to be used as the data sourceDataProvider
public FileDataSource createFileDataSource()
public <T> ObjectDataReader<T> createObjectDataReader(InputStreamInputConverter<T> converter)
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
.T
- the type of the object to readconverter
- the converter to use to convert the data read from the file into an objectpublic <T> ObjectDataWriter<T> createObjectDataWriter(OutputStreamOutputConverter<T> converter)
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.T
- the type of the object to writeconverter
- the converter to use to convert the object into data to write to the filepublic <T> ObjectDataRemover<T> createObjectDataRemover()
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.T
- the type of the object to removepublic <T> ListDataReader<T> createListDataReader(InputStreamIterableInputConverter<T> converter)
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
.T
- the type of the objects contained in the list to readconverter
- the converter to use to convert the data read from the file into a list of objects