@Singleton
public class IOUtils
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
REGEX_ILLEGAL_IN_FILENAME
Regular expression of illegal characters or strings in file or directory names '/', '\n', '\r', * '//', '\t',
'\0', '\f', '`', '?', '*', '\\', '<', '>', '|', '\"', ':', '~', '!', '§', '$', '%', '&'
|
static java.io.File |
TMP_DIR |
Constructor and Description |
---|
IOUtils() |
Modifier and Type | Method and Description |
---|---|
boolean |
checkFileInStudyAssetsDirExists(java.lang.String dirName,
java.lang.String filePath) |
static boolean |
checkFilename(java.lang.String filename) |
boolean |
checkStudyAssetsDirExists(java.lang.String dirName) |
java.lang.String |
cloneComponentHtmlFile(java.lang.String studyAssetsDirName,
java.lang.String htmlFilePath)
Copies a component's HTML file.
|
java.lang.String |
cloneStudyAssetsDirectory(java.lang.String srcDirName)
Copies study assets' directory.
|
static void |
createDir(java.io.File file)
Creates the given File as a directory, including necessary and non-existent parent directories.
|
void |
createStudyAssetsDir(java.lang.String dirName)
Creates a study assets dir.
|
java.io.File[] |
findDirectories(java.io.File dir)
Returns all directories within this directory.
|
java.io.File[] |
findFiles(java.io.File dir,
java.lang.String prefix,
java.lang.String suffix)
Returns all files within this directory that have the prefix and the suffix.
|
java.lang.String |
findNonExistingStudyAssetsDirName(java.lang.String dirName) |
java.lang.String |
generateFileName(java.lang.String rawName)
Generates a filename from a name in a specified length.
|
java.lang.String |
generateFileName(java.lang.String rawName,
java.lang.String suffix)
Generates a filename from a name in a specified length and adds the suffix.
|
java.lang.String |
generateStudyAssetsPath(java.lang.String dirName)
Generates a study assets directory path.
|
java.nio.file.Path |
getAssetsFilePath(java.lang.String filepath,
java.lang.String filename,
Study study)
Get a Path to a file in a study assets directory.
|
java.io.File |
getExistingFileInStudyAssetsDir(java.lang.String dirName,
java.lang.String filePath)
Gets the File object which resides under filePath within the study assets' directory.
|
java.io.File |
getExistingFileSecurely(java.lang.String path,
java.lang.String filePath)
Gets the File object while preventing a path traversal attack and checks whether the file exists and is no
directory.
|
java.io.File |
getFileInStudyAssetsDir(java.lang.String dirName,
java.lang.String filePath)
Gets the File object which resides under filePath within the study assets' directory.
|
static java.lang.String |
getResultsPath(java.lang.Long studyResultId,
java.lang.Long componentResultId)
Path to result files in file system (after unpacking - so using the OS' file separator)
|
static java.lang.String |
getResultsPathForZip(java.lang.Long studyResultId,
java.lang.Long componentResultId)
Path to result files in zip package with '/' as file separator
|
long |
getResultUploadDirSize(java.lang.Long studyResultId)
Returns the disk size in Bytes of all uploaded files belonging to the given study result ID.
|
java.io.File |
getResultUploadFileSecurely(java.lang.Long studyResultId,
java.lang.Long componentResultId,
java.lang.String filename) |
static java.lang.String |
getResultUploadsDir(java.lang.Long studyResultId)
Path to result uploads folder where JATOS stores the uploaded result files
|
static java.lang.String |
getResultUploadsDir(java.lang.Long studyResultId,
java.lang.Long componentResultId)
Path to result uploads folder where JATOS stores the uploaded result files
|
java.io.File |
getStudyAssetsDir(java.lang.String dirName)
Gets the study assets with the given directory name.
|
long |
getStudyAssetsDirSize(java.lang.String dirName)
Returns the disk size in Bytes of all files inside the given study assets directory.
|
void |
moveStudyAssetsDir(java.io.File srcDir,
java.lang.String targetDirName)
Moves study assets dir into the assets root dir.
|
java.lang.String |
readFile(java.io.File file)
Reads the given file and returns the content as String.
|
void |
removeResultUploadsDir(java.lang.Long studyResultId) |
void |
removeResultUploadsDir(java.lang.Long studyResultId,
java.lang.Long componentResultId) |
void |
removeStudyAssetsDir(java.lang.String dirName)
Remove study assets' directory if exists.
|
void |
renameHtmlFile(java.lang.String oldHtmlFilePath,
java.lang.String newHtmlFilePath,
java.lang.String studyAssetName)
Renames a component's HTML file.
|
void |
renameStudyAssetsDir(java.lang.String oldDirName,
java.lang.String newDirName)
Renames a study assets dir.
|
public static final java.lang.String REGEX_ILLEGAL_IN_FILENAME
public static final java.io.File TMP_DIR
public java.lang.String readFile(java.io.File file) throws java.io.IOException
java.io.IOException
public boolean checkStudyAssetsDirExists(java.lang.String dirName)
public boolean checkFileInStudyAssetsDirExists(java.lang.String dirName, java.lang.String filePath)
public java.io.File getExistingFileSecurely(java.lang.String path, java.lang.String filePath) throws java.io.IOException
java.io.IOException
public java.io.File getFileInStudyAssetsDir(java.lang.String dirName, java.lang.String filePath) throws java.io.IOException
java.io.IOException
public java.io.File getExistingFileInStudyAssetsDir(java.lang.String dirName, java.lang.String filePath)
public java.io.File getStudyAssetsDir(java.lang.String dirName) throws java.io.IOException
java.io.IOException
public java.lang.String generateFileName(java.lang.String rawName, java.lang.String suffix)
public static boolean checkFilename(java.lang.String filename)
public java.lang.String generateFileName(java.lang.String rawName)
public java.lang.String generateStudyAssetsPath(java.lang.String dirName)
public void removeStudyAssetsDir(java.lang.String dirName) throws java.io.IOException
java.io.IOException
public java.nio.file.Path getAssetsFilePath(java.lang.String filepath, java.lang.String filename, Study study) throws java.io.IOException
filepath
- Filepath to the file. If it points to a directory (indicated by a trailing '/') the returned Path
consists of filepath + filename. If it does not point to a directory it is treated as Path to a
file and returned as Path (without the filename parameter). This parameter is optional and can be
null to signal the Path to the file is supposed to be in the root of the study assets directory.
If it has a leading '/' it gets removed. It can be URL encoded but doesn't have to be.filename
- Filename of the file (without path).study
- Study where the study assets belong tojava.io.IOException
public java.lang.String cloneComponentHtmlFile(java.lang.String studyAssetsDirName, java.lang.String htmlFilePath) throws java.io.IOException
studyAssetsDirName
- Name of the study assetshtmlFilePath
- Local file path to the HTML file. The file can be in a subdirectory of the study
assets directory.java.io.IOException
public java.lang.String cloneStudyAssetsDirectory(java.lang.String srcDirName) throws java.io.IOException
java.io.IOException
public java.lang.String findNonExistingStudyAssetsDirName(java.lang.String dirName)
public void moveStudyAssetsDir(java.io.File srcDir, java.lang.String targetDirName) throws java.io.IOException
srcDir
- The source dir File can be anywhere in the file system.targetDirName
- Name of the target dir within the assets root dirjava.io.IOException
public void createStudyAssetsDir(java.lang.String dirName) throws java.io.IOException
dirName
- Name of the new study assets dir.java.io.IOException
public java.io.File[] findFiles(java.io.File dir, java.lang.String prefix, java.lang.String suffix)
public java.io.File[] findDirectories(java.io.File dir)
public void renameStudyAssetsDir(java.lang.String oldDirName, java.lang.String newDirName) throws java.io.IOException
java.io.IOException
public long getStudyAssetsDirSize(java.lang.String dirName)
public void renameHtmlFile(java.lang.String oldHtmlFilePath, java.lang.String newHtmlFilePath, java.lang.String studyAssetName) throws java.io.IOException
oldHtmlFilePath
- The current local file path within the study assetsnewHtmlFilePath
- The new local file path within the study assetsstudyAssetName
- The name (not the path) of the study assetsjava.io.IOException
public static void createDir(java.io.File file) throws java.io.IOException
java.io.IOException
public static java.lang.String getResultUploadsDir(java.lang.Long studyResultId)
public static java.lang.String getResultUploadsDir(java.lang.Long studyResultId, java.lang.Long componentResultId)
public static java.lang.String getResultsPathForZip(java.lang.Long studyResultId, java.lang.Long componentResultId)
public static java.lang.String getResultsPath(java.lang.Long studyResultId, java.lang.Long componentResultId)
public long getResultUploadDirSize(java.lang.Long studyResultId)
public java.io.File getResultUploadFileSecurely(java.lang.Long studyResultId, java.lang.Long componentResultId, java.lang.String filename) throws java.io.IOException
java.io.IOException
public void removeResultUploadsDir(java.lang.Long studyResultId) throws java.io.IOException
java.io.IOException
public void removeResultUploadsDir(java.lang.Long studyResultId, java.lang.Long componentResultId) throws java.io.IOException
java.io.IOException