Package de.xima.fc.gui.common.utils
Class FileUtils
java.lang.Object
de.xima.fc.gui.common.utils.FileUtils
- Author:
- XIMA MEDIA GmbH
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic org.primefaces.model.StreamedContentGeneratesStreamedContentwith an emptyInputStream, which is used in various Beans related to File Download or Upload, when somehow the sources are empty or equal nullstatic <E extends IFileDataEntity<?>,T extends IFileProviding<?, E>>
FilecreateZipFile(List<T> entities, File outDir) Packs the files of the given entities into one zip file which will be placed in the specified output directorystatic <E extends IFileDataEntity<?>,T extends IFileProviding<?, E>>
FilecreateZipFile(List<T> entities, File outDir, String zipFileName) Packs the files of the given entities into one zip file which will be placed in the specified output directorystatic <E extends IFileDataEntity<?>,T extends IFileProviding<?, E>>
FilecreateZipFileFromDataSources(List<Datenquelle> sources, File outDir, String zipFileName) Packs the contents of the given data sources into one zip file which will be placed in the specified output directorystatic FilecreateZipFileFromFiles(List<File> files, File outDir, String zipFileName) Packs the given files one zip file which will be placed in the specified output directorystatic StringgenerateFileName(Datenquelle source) Generates a file name for the given data sourcestatic StringgetContentType(File file) Returns the content type of the given filestatic StringgetContentType(String fileName) Returns the content type of the file by its filenamestatic byte[]getData(org.primefaces.model.file.UploadedFile upload) Returns the data of theUploadedFileas a byte arraystatic StringgetExtension(Datenquelle source) Returns the file extension for the given data sourcestatic FilegetFile(Datenquelle source, File outDir) Generates aFilefor a given data sourcestatic <E extends IFileDataEntity<?>,T extends IFileProviding<?, E>>
FileGets theFilefrom anIFileProvidingentity placed within the specified output directorygetMostRecentFile(Iterable<Path> files) Given a set of files, finds the file or directory that was modified most recently.static <F extends IFileEntity<?,?>>
org.primefaces.model.StreamedContentgetStreamedContent(F fileEntity) Gets aStreamedContentfor the givenIFileEntityfile entitystatic org.primefaces.model.StreamedContentgetStreamedContent(List<Datenquelle> sources, String zipFileName) GeneratesStreamedContentfrom the given List of data sources.static <E extends IFileDataEntity<?>,T extends IFileProviding<?, E>>
org.primefaces.model.StreamedContentgetStreamedContent(T entity) Gets aStreamedContentfor the givenIFileProvidingentitystatic org.primefaces.model.StreamedContentgetStreamedContentEmpty(String fileName, String contentType, Charset encoding) static org.primefaces.model.StreamedContentgetStreamedContentFile(Path file, String fileName, String contentType, Charset encoding) Creates a streamed content instance that returns the given file.static org.primefaces.model.StreamedContentgetStreamedContentFileOrZip(Iterable<Path> files, String fileName, String contentType, Charset encoding) Creates a streamed content instance that either contains a single file directly, or a ZIP file when the given files contain more than one file or no file at all.static org.primefaces.model.StreamedContentgetStreamedContentZip(Iterable<Path> files, String fileName) Creates a streamed content instance that returns a ZIP file with all given files.static StringgetStyleClass(String fileName) static booleanisImageFile(String fileName) static InputStreamCreates an input stream for reading the given file that deletes the file once the stream is closed.static org.primefaces.model.DefaultStreamedContent.BuildernewStreamedContentBuilder(String fileName, String contentType, Charset encoding) Creates a new streamed content builder with the given meta data set, but no binary data yet.
-
Field Details
-
ENCODING
Deprecated.- See Also:
-
FILENAME_GENERAL_ZIP
- See Also:
-
-
Constructor Details
-
FileUtils
public FileUtils()
-
-
Method Details
-
createEmptyStreamedContent
public static org.primefaces.model.StreamedContent createEmptyStreamedContent()GeneratesStreamedContentwith an emptyInputStream, which is used in various Beans related to File Download or Upload, when somehow the sources are empty or equal null- Returns:
- the empty
StreamedContent
-
createZipFile
public static <E extends IFileDataEntity<?>,T extends IFileProviding<?, File createZipFileE>> (List<T> entities, File outDir) throws IOException Packs the files of the given entities into one zip file which will be placed in the specified output directory- Parameters:
entities-IFileProvidingentities that should be packed into one zip archiveoutDir-Fileoutput directory where the resulting zip file will be placed- Returns:
Filein zip format containing all the files of the entities- Throws:
IOException- on errors during creating the zip file
-
createZipFile
public static <E extends IFileDataEntity<?>,T extends IFileProviding<?, File createZipFileE>> (List<T> entities, File outDir, String zipFileName) throws IOException Packs the files of the given entities into one zip file which will be placed in the specified output directory- Parameters:
entities-IFileProvidingentities that should be packed into one zip archiveoutDir-Fileoutput directory where the resulting zip file will be placedzipFileName-Stringname of the resulting zip file- Returns:
Filein zip format containing all the files of the entities- Throws:
IOException- on errors during creating the zip file
-
createZipFileFromDataSources
public static <E extends IFileDataEntity<?>,T extends IFileProviding<?, File createZipFileFromDataSourcesE>> (List<Datenquelle> sources, File outDir, String zipFileName) throws IOException Packs the contents of the given data sources into one zip file which will be placed in the specified output directory- Parameters:
sources-IFileProvidingdata sources that should be packed into one zip archiveoutDir-Fileoutput directory where the resulting zip file will be placedzipFileName-Stringname of the resulting zip file- Returns:
Filein zip format containing all the content files of the data sources- Throws:
IOException- on errors during creating the zip file
-
createZipFileFromFiles
public static File createZipFileFromFiles(List<File> files, File outDir, String zipFileName) throws IOException Packs the given files one zip file which will be placed in the specified output directory- Parameters:
files-Listfiles that should be packed into one zip archiveoutDir-Fileoutput directory where the resulting zip file will be placedzipFileName-Stringname of the resulting zip file- Returns:
Filein zip format containing all the files- Throws:
IOException- on errors during creating the zip file
-
generateFileName
Generates a file name for the given data source- Parameters:
source-Datenquelle- Returns:
Stringfile name of the given data source
-
getContentType
Returns the content type of the given file -
getContentType
Returns the content type of the file by its filename -
getData
public static byte[] getData(org.primefaces.model.file.UploadedFile upload) throws Exception, OutOfMemoryError Returns the data of theUploadedFileas a byte array- Parameters:
upload-UploadedFileholding the data- Returns:
- byte[] of the data
- Throws:
Exception- on errors during reading theUploadedFileOutOfMemoryError- if Java Virtual Machine is out of memory
-
getExtension
Returns the file extension for the given data source- Parameters:
source-Datenquelle- Returns:
Stringfile extension
-
getFile
Generates aFilefor a given data source- Parameters:
source-Datenquellefor which a file should be generatedoutDir-Fileoutput directory where resulting file should be placed- Returns:
Fileof the given data source- Throws:
IOException- on errors during writing the file
-
getFile
public static <E extends IFileDataEntity<?>,T extends IFileProviding<?, File getFileE>> (T entity, File outDir) throws IOException Gets theFilefrom anIFileProvidingentity placed within the specified output directory- Parameters:
entity-IFileProvidingholding the desired fileoutDir-Fileoutput directory where resulting file should be placed- Returns:
Fileof the given entity- Throws:
IOException- on errors during writing the file
-
getMostRecentFile
Given a set of files, finds the file or directory that was modified most recently. Files or directories that do not exist are omitted. Returns an empty optional if no paths were given or none of the files or directories exist.- Parameters:
files- Files to process.- Returns:
- The file or directory that was modified most recently
-
getStreamedContent
public static <F extends IFileEntity<?,?>> org.primefaces.model.StreamedContent getStreamedContent(F fileEntity) Gets aStreamedContentfor the givenIFileEntityfile entity- Type Parameters:
F- Type of the file data entity.- Parameters:
fileEntity- for which to return aStreamedContent- Returns:
StreamedContentof the givenIFileProvidingentity ornullif the entity isnull
-
getStreamedContent
public static org.primefaces.model.StreamedContent getStreamedContent(List<Datenquelle> sources, String zipFileName) throws Exception GeneratesStreamedContentfrom the given List of data sources. If this list contains only a single entry theStreamedContentfor this data source will be returned. If the list contains more than one entry the data sources will be packed into a zip file with the specified filename and the generatedStreamedContentof the zip file will be returned.- Parameters:
sources-Listof the data sources to generateStreamedContentforzipFileName-Stringname of the resulting zip file if more than one data source is contained within the given data source list- Returns:
- the
StreamedContentof all the marked model data sources - Throws:
Exception- on errors during creating theStreamedContent
-
getStreamedContent
public static <E extends IFileDataEntity<?>,T extends IFileProviding<?, org.primefaces.model.StreamedContent getStreamedContentE>> (T entity) Gets aStreamedContentfor the givenIFileProvidingentity- Type Parameters:
E- Type of the file data entity.T- Type of the class that provides the file.- Parameters:
entity- for which to return aStreamedContent- Returns:
StreamedContentof the givenIFileProvidingentity ornullif the entity isnull
-
getStreamedContentEmpty
public static org.primefaces.model.StreamedContent getStreamedContentEmpty(String fileName, String contentType, Charset encoding) - Parameters:
fileName- File name for the download file.contentType- Content type for the downloaded file.encoding- Encoding of the file, should only be set for text files (mainly mime typetext/*, otherwise passnull.- Returns:
- A streamed content instance with no data.
-
getStreamedContentFile
public static org.primefaces.model.StreamedContent getStreamedContentFile(Path file, String fileName, String contentType, Charset encoding) Creates a streamed content instance that returns the given file.- Parameters:
file- File to stream.fileName- Name of the file.contentType- Content type of the file.encoding- Encoding of the file, should only be set for text files (mainly mime typetext/*, otherwise passnull.- Returns:
- A streamed content for the given file.
-
getStreamedContentFileOrZip
public static org.primefaces.model.StreamedContent getStreamedContentFileOrZip(Iterable<Path> files, String fileName, String contentType, Charset encoding) Creates a streamed content instance that either contains a single file directly, or a ZIP file when the given files contain more than one file or no file at all.- Parameters:
files- Files to stream.fileName- Name of the file.contentType- Content type of the file.encoding- Encoding of the file, should only be set for text files (mainly mime typetext/*, otherwise passnull.- Returns:
- A streamed content with either a single file or a ZIP file.
-
getStreamedContentZip
public static org.primefaces.model.StreamedContent getStreamedContentZip(Iterable<Path> files, String fileName) Creates a streamed content instance that returns a ZIP file with all given files.- Parameters:
files- File to stream.fileName- Name of the file.- Returns:
- A streamed content with a ZIP file contain all given files.
-
getStyleClass
-
isImageFile
-
newDeleteFileOnCloseInputStream
Creates an input stream for reading the given file that deletes the file once the stream is closed. If any methods of the input stream throw anIOException, the file is deleted immediately.- Parameters:
file- Path to the file.- Returns:
- An input stream for reading the file.
- Throws:
IOException- When the input stream could not be opened. The file is still deleted.
-
newStreamedContentBuilder
public static org.primefaces.model.DefaultStreamedContent.Builder newStreamedContentBuilder(String fileName, String contentType, Charset encoding) Creates a new streamed content builder with the given meta data set, but no binary data yet.- Parameters:
fileName- Name of the file.contentType- Content type of the file.encoding- Encoding of the file, should only be set for text files (mainly mime typetext/*, otherwise passnull.- Returns:
- A new builder with the given data.
-
CmnConst.DFLT_ENCODING