C7 Client File Transmission
brownie provides a file transmission feature which allows the user to create files on the client side so that they are automatically transmitted to the servers database after each session.
The following code pieces show how the feature can be used to create files so that they are automatically transmitted to the servers database afterwards.
Depending on whether you need a FileWriter object, which is able to write text into a file, or a FileOutputStream, which is able to write binary data into a file, you may want to look at one of the following examples:
// For a text file use this example to get a FileWriter object FileManager fileManager = FileManager.getInstance(); String clientID = ClientGuiController.getInstance().getClientId(); FileWriter writer = fileManager.getFileWriter("FilePrefix",clientID); writer.write("This will be written into the file and then transmitted to the servers database afterwards."); writer.flush();
// For a binary file use this example to get a FileOutputStream object FileManager fileManager = FileManager.getInstance(); String clientID = ClientGuiController.getInstance().getClientId(); FileOutputStream stream = fileManager.getFileOutputStream("FilePrefix",clientID); String content = "This will be written into the file and then transmitted to the servers database afterwards."; stream.write(content.getBytes()); // Remark: Of course, this is just and example and it should not be used // for text but rather for e.g. audio and video files stream.flush();
Remark: the method implementing this code would need to throw or catch an IOException
To make use of this feature it is necessary to create files on the client side exclusively with the FileManager which can be found in the "ExpCommon"-Project in the "edu.kit.exp.files" package. The function getFileWriter creates a unique file name by combining the purpose specific File-Prefix (first parameter) and the client id (second parameter) with a time stamp and a unique id. After that it returns a FileWriter-Object using the file name. The ending of this files is ".expdata".
A reference to the FileWriter-Object is also stored in the FileManager. Any file created this way during runtime will automatically be closed and transmitted to the server after the session.
On the server side the files can be found as plain files and as binary code in the database using binary large object (blob) fields.
Path for storage
There is also the option to modify the path these files are stored in. This can be done in the system.properties file by providing and entry called "filedir=". If there is a path given behind the equals-sign, all ".expdata"-files will be stored in this path.
Note that if there is no path provided brownie will store the files in the execution directory, which may be different depending on the operation system (usually Windows stores them in the project folder, while unix stores them in the folder above).
Also note that if you provide a path here, please make sure, that this folder exists and is accessible by the jar-file.
This is particularly interesting for the execution of brownie in the laboratory as the jar may be executed on a shared space, but the storage of the potentially big ".expdata"-files should be done locally to avoid network congestion.