Package de.xima.fc.gui.common.utils
Class FileUtils
- java.lang.Object
-
- de.xima.fc.gui.common.utils.FileUtils
-
public class FileUtils extends Object
- Author:
- XIMA MEDIA GmbH
-
-
Field Summary
Fields Modifier and Type Field Description static String
ENCODING
static String
FILENAME_GENERAL_ZIP
-
Constructor Summary
Constructors Constructor Description FileUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static org.primefaces.model.StreamedContent
createEmptyStreamedContent()
GeneratesStreamedContent
with 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 File
createZipFileFromFiles(List<File> files, File outDir, String zipFileName)
Packs the given files one zip file which will be placed in the specified output directorystatic String
generateFileName(Datenquelle source)
Generates a file name for the given data sourcestatic String
getContentType(File file)
Returns the content type of the given filestatic String
getContentType(String fileName)
Returns the content type of the file by its filenamestatic byte[]
getData(org.primefaces.model.file.UploadedFile upload)
Returns the data of theUploadedFile
as a byte arraystatic String
getExtension(Datenquelle source)
Returns the file extension for the given data sourcestatic File
getFile(Datenquelle source, File outDir)
Generates aFile
for a given data sourcestatic <E extends IFileDataEntity<?>,T extends IFileProviding<?,E>>
FilegetFile(T entity, File outDir)
Gets theFile
from anIFileProviding
entity placed within the specified output directorystatic org.primefaces.model.StreamedContent
getStreamedContent(List<Datenquelle> sources, String zipFileName)
GeneratesStreamedContent
from the given List of data sources.static <E extends IFileDataEntity<?>,T extends IFileProviding<?,E>>
org.primefaces.model.StreamedContentgetStreamedContent(T entity)
Gets aStreamedContent
for the givenIFileProviding
entitystatic String
getStyleClass(String fileName)
static boolean
isImageFile(String fileName)
-
-
-
Field Detail
-
ENCODING
public static final String ENCODING
- See Also:
- Constant Field Values
-
FILENAME_GENERAL_ZIP
public static final String FILENAME_GENERAL_ZIP
- See Also:
- Constant Field Values
-
-
Method Detail
-
getFile
public static File getFile(Datenquelle source, File outDir) throws IOException
Generates aFile
for a given data source- Parameters:
source
-Datenquelle
for which a file should be generatedoutDir
-File
output directory where resulting file should be placed- Returns:
File
of the given data source- Throws:
IOException
- on errors during writing the file
-
getFile
public static <E extends IFileDataEntity<?>,T extends IFileProviding<?,E>> File getFile(T entity, File outDir) throws IOException
Gets theFile
from anIFileProviding
entity placed within the specified output directory- Parameters:
entity
-IFileProviding
holding the desired fileoutDir
-File
output directory where resulting file should be placed- Returns:
File
of the given entity- Throws:
IOException
- on errors during writing the file
-
createZipFile
public static <E extends IFileDataEntity<?>,T extends IFileProviding<?,E>> File createZipFile(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
-IFileProviding
entities that should be packed into one zip archiveoutDir
-File
output directory where the resulting zip file will be placed- Returns:
File
in 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<?,E>> File createZipFile(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
-IFileProviding
entities that should be packed into one zip archiveoutDir
-File
output directory where the resulting zip file will be placedzipFileName
-String
name of the resulting zip file- Returns:
File
in zip format containing all the files of the entities- 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
-List
files that should be packed into one zip archiveoutDir
-File
output directory where the resulting zip file will be placedzipFileName
-String
name of the resulting zip file- Returns:
File
in zip format containing all the files- Throws:
IOException
- on errors during creating the zip file
-
createZipFileFromDataSources
public static <E extends IFileDataEntity<?>,T extends IFileProviding<?,E>> File createZipFileFromDataSources(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
-IFileProviding
data sources that should be packed into one zip archiveoutDir
-File
output directory where the resulting zip file will be placedzipFileName
-String
name of the resulting zip file- Returns:
File
in zip format containing all the content files of the data sources- Throws:
IOException
- on errors during creating the zip file
-
getStreamedContent
public static <E extends IFileDataEntity<?>,T extends IFileProviding<?,E>> org.primefaces.model.StreamedContent getStreamedContent(T entity)
Gets aStreamedContent
for the givenIFileProviding
entity- 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:
StreamedContent
of the givenIFileProviding
entity ornull
if the entity isnull
-
getStreamedContent
public static org.primefaces.model.StreamedContent getStreamedContent(List<Datenquelle> sources, String zipFileName) throws Exception
GeneratesStreamedContent
from the given List of data sources. If this list contains only a single entry theStreamedContent
for 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 generatedStreamedContent
of the zip file will be returned.- Parameters:
sources
-List
of the data sources to generateStreamedContent
forzipFileName
-String
name of the resulting zip file if more than one data source is contained within the given data source list- Returns:
- the
StreamedContent
of all the marked model data sources - Throws:
Exception
- on errors during creating theStreamedContent
-
createEmptyStreamedContent
public static org.primefaces.model.StreamedContent createEmptyStreamedContent()
GeneratesStreamedContent
with 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
-
getData
public static byte[] getData(org.primefaces.model.file.UploadedFile upload) throws Exception, OutOfMemoryError
Returns the data of theUploadedFile
as a byte array- Parameters:
upload
-UploadedFile
holding the data- Returns:
- byte[] of the data
- Throws:
Exception
- on errors during reading theUploadedFile
OutOfMemoryError
- if Java Virtual Machine is out of memory
-
getContentType
public static String getContentType(File file)
Returns the content type of the given file
-
generateFileName
public static String generateFileName(Datenquelle source)
Generates a file name for the given data source- Parameters:
source
-Datenquelle
- Returns:
String
file name of the given data source
-
getExtension
public static String getExtension(Datenquelle source)
Returns the file extension for the given data source- Parameters:
source
-Datenquelle
- Returns:
String
file extension
-
getContentType
public static String getContentType(String fileName)
Returns the content type of the file by its filename
-
isImageFile
public static boolean isImageFile(String fileName)
-
-