- java.lang.Object
-
- com.gluonhq.connect.provider.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 Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static FileClient
create(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 ofListDataReader
that can be passed directly in theDataProvider.retrieveList(ListDataReader)
method.<T> ObjectDataReader<T>
createObjectDataReader(InputStreamInputConverter<T> converter)
Creates an instance ofObjectDataReader
that can be passed directly in theDataProvider.retrieveObject(ObjectDataReader)
method.<T> ObjectDataRemover<T>
createObjectDataRemover()
Creates an instance ofObjectDataRemover
that can be passed directly in theDataProvider.removeObject(GluonObservableObject, ObjectDataRemover)
method.<T> ObjectDataWriter<T>
createObjectDataWriter(OutputStreamOutputConverter<T> converter)
Creates an instance ofObjectDataWriter
that can be passed directly in theDataProvider.storeObject(Object, ObjectDataWriter)
method.
-
-
-
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 ofObjectDataReader
that can be passed directly in theDataProvider.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 specifiedconverter
.- 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 ofObjectDataWriter
that can be passed directly in theDataProvider.storeObject(Object, ObjectDataWriter)
method. The object data writer will convert an object by using the specifiedconverter
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 ofObjectDataRemover
that can be passed directly in theDataProvider.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 ofListDataReader
that can be passed directly in theDataProvider.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 specifiedconverter
.- 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
-
-