Package es.gob.afirma.mreport.utils
Class FileUtils
- java.lang.Object
-
- es.gob.afirma.mreport.utils.FileUtils
-
public final class FileUtils extends java.lang.ObjectUtility class for managing files.
Project:Library for the integration with the services of @Firma, eVisor and TS@.
- Version:
- 1.1, 18/04/2022.
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringBMP_MEDIA_TYPEAttribute that represents the BMP media type.static java.lang.StringDATA_FILE_EXTENSIONAttribute that represents the extension used for the Binary Files.static java.lang.StringGIF_MEDIA_TYPEAttribute that represents the GIF media type.static java.lang.StringHTML_MEDIA_TYPEAttribute that represents the HTML media type.static java.lang.StringJPEG_MEDIA_TYPEAttribute that represents the JPEG media type.static java.lang.StringMSOFFICE_DOC_MEDIA_TYPEAttribute that represents the microsoft word media type.static java.lang.StringMSOFFICE_DOCX_MEDIA_TYPEAttribute that represents the microsoft word media type (in open xml format).static java.lang.StringMSOFFICE_PPT_MEDIA_TYPEAttribute that represents the microsoft powerpoint media type.static java.lang.StringMSOFFICE_PPTX_MEDIA_TYPEAttribute that represents the microsoft powerpoint media type (in open xml format).static java.lang.StringMSOFFICE_XLS_MEDIA_TYPEAttribute that represents the microsoft excel media type.static java.lang.StringMSOFFICE_XLSX_MEDIA_TYPEAttribute that represents the microsoft excel media type (in open xml format).static java.lang.StringODC_MEDIA_TYPEAttribute that represents the ODC media type.static java.lang.StringODG_MEDIA_TYPEAttribute that represents the ODG media type.static java.lang.StringODP_MEDIA_TYPEAttribute that represents the ODP media type.static java.lang.StringODS_MEDIA_TYPEAttribute that represents the ODS media type.static java.lang.StringODT_MEDIA_TYPEAttribute that represents the ODT media type.static java.lang.StringPDF_MEDIA_TYPEAttribute that represents the PDF media type.static java.lang.StringPNG_MEDIA_TYPEAttribute that represents the PNG media type.static java.lang.StringRTF_MEDIA_TYPEAttribute that represents the RTF media type.static java.lang.StringTIFF_MEDIA_TYPEAttribute that represents the PNG media type.static java.lang.StringTXT_MEDIA_TYPEAttribute that represents the text plain media type.static java.lang.StringXML_MEDIA_TYPEAttribute that represents the XML media type.static java.lang.StringXSLT_MEDIA_TYPEAttribute that represents the XSLT media type.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static byte[]getFile(java.lang.String templatePath)Method that returns the array of bytes of supplied file.static java.lang.StringgetFileExtension(byte[] file)Gets the file extension.static java.lang.StringgetFileExtension(java.lang.String mimeType)Gets the file extension.static java.lang.StringgetMediaType(byte[] document)Detects the media type of the given document.static booleanisImage(java.lang.String mimeType)Checks if the supplied MimeType is a supported image MimeType.static booleanisTextFile(java.lang.String mimeType)Checks if the supplied MimeType is a supported text plain file or XML file.static booleanisXML(byte[] file)Checks if the supplied file is a valid XML.static byte[]toByteArray(java.sql.Blob fromBlob)Method that obtains a bytes array from aBlobobject.
-
-
-
Field Detail
-
ODT_MEDIA_TYPE
public static final java.lang.String ODT_MEDIA_TYPE
Attribute that represents the ODT media type.- See Also:
- Constant Field Values
-
ODG_MEDIA_TYPE
public static final java.lang.String ODG_MEDIA_TYPE
Attribute that represents the ODG media type.- See Also:
- Constant Field Values
-
ODS_MEDIA_TYPE
public static final java.lang.String ODS_MEDIA_TYPE
Attribute that represents the ODS media type.- See Also:
- Constant Field Values
-
ODP_MEDIA_TYPE
public static final java.lang.String ODP_MEDIA_TYPE
Attribute that represents the ODP media type.- See Also:
- Constant Field Values
-
ODC_MEDIA_TYPE
public static final java.lang.String ODC_MEDIA_TYPE
Attribute that represents the ODC media type.- See Also:
- Constant Field Values
-
BMP_MEDIA_TYPE
public static final java.lang.String BMP_MEDIA_TYPE
Attribute that represents the BMP media type.- See Also:
- Constant Field Values
-
GIF_MEDIA_TYPE
public static final java.lang.String GIF_MEDIA_TYPE
Attribute that represents the GIF media type.- See Also:
- Constant Field Values
-
JPEG_MEDIA_TYPE
public static final java.lang.String JPEG_MEDIA_TYPE
Attribute that represents the JPEG media type.- See Also:
- Constant Field Values
-
PNG_MEDIA_TYPE
public static final java.lang.String PNG_MEDIA_TYPE
Attribute that represents the PNG media type.- See Also:
- Constant Field Values
-
TIFF_MEDIA_TYPE
public static final java.lang.String TIFF_MEDIA_TYPE
Attribute that represents the PNG media type.- See Also:
- Constant Field Values
-
PDF_MEDIA_TYPE
public static final java.lang.String PDF_MEDIA_TYPE
Attribute that represents the PDF media type.- See Also:
- Constant Field Values
-
MSOFFICE_DOC_MEDIA_TYPE
public static final java.lang.String MSOFFICE_DOC_MEDIA_TYPE
Attribute that represents the microsoft word media type.- See Also:
- Constant Field Values
-
MSOFFICE_DOCX_MEDIA_TYPE
public static final java.lang.String MSOFFICE_DOCX_MEDIA_TYPE
Attribute that represents the microsoft word media type (in open xml format).- See Also:
- Constant Field Values
-
MSOFFICE_PPT_MEDIA_TYPE
public static final java.lang.String MSOFFICE_PPT_MEDIA_TYPE
Attribute that represents the microsoft powerpoint media type.- See Also:
- Constant Field Values
-
MSOFFICE_PPTX_MEDIA_TYPE
public static final java.lang.String MSOFFICE_PPTX_MEDIA_TYPE
Attribute that represents the microsoft powerpoint media type (in open xml format).- See Also:
- Constant Field Values
-
MSOFFICE_XLS_MEDIA_TYPE
public static final java.lang.String MSOFFICE_XLS_MEDIA_TYPE
Attribute that represents the microsoft excel media type.- See Also:
- Constant Field Values
-
MSOFFICE_XLSX_MEDIA_TYPE
public static final java.lang.String MSOFFICE_XLSX_MEDIA_TYPE
Attribute that represents the microsoft excel media type (in open xml format).- See Also:
- Constant Field Values
-
TXT_MEDIA_TYPE
public static final java.lang.String TXT_MEDIA_TYPE
Attribute that represents the text plain media type.- See Also:
- Constant Field Values
-
RTF_MEDIA_TYPE
public static final java.lang.String RTF_MEDIA_TYPE
Attribute that represents the RTF media type.- See Also:
- Constant Field Values
-
XML_MEDIA_TYPE
public static final java.lang.String XML_MEDIA_TYPE
Attribute that represents the XML media type.- See Also:
- Constant Field Values
-
XSLT_MEDIA_TYPE
public static final java.lang.String XSLT_MEDIA_TYPE
Attribute that represents the XSLT media type.- See Also:
- Constant Field Values
-
HTML_MEDIA_TYPE
public static final java.lang.String HTML_MEDIA_TYPE
Attribute that represents the HTML media type.- See Also:
- Constant Field Values
-
DATA_FILE_EXTENSION
public static final java.lang.String DATA_FILE_EXTENSION
Attribute that represents the extension used for the Binary Files.- See Also:
- Constant Field Values
-
-
Method Detail
-
getFileExtension
public static java.lang.String getFileExtension(byte[] file) throws UtilsExceptionGets the file extension.- Parameters:
file- File.- Returns:
- File extension.
- Throws:
UtilsException- If an error occurs.
-
getFileExtension
public static java.lang.String getFileExtension(java.lang.String mimeType) throws UtilsExceptionGets the file extension.- Parameters:
mimeType- MimeType.- Returns:
- File extension.
- Throws:
UtilsException- If an error occurs.
-
isXML
public static boolean isXML(byte[] file) throws UtilsExceptionChecks if the supplied file is a valid XML.- Parameters:
file- File to check.- Returns:
- True if the file is a XML.
- Throws:
UtilsException- If an error occurs while processing the file.
-
toByteArray
public static byte[] toByteArray(java.sql.Blob fromBlob) throws UtilsExceptionMethod that obtains a bytes array from aBlobobject.- Parameters:
fromBlob- Parameter that represents theBlobobject.- Returns:
- a bytes array from a
Blobobject. - Throws:
UtilsException- If an error occurs.
-
getFile
public static byte[] getFile(java.lang.String templatePath) throws UtilsExceptionMethod that returns the array of bytes of supplied file.- Parameters:
templatePath- Path of file to get.- Returns:
- Array of bytes of file.
- Throws:
UtilsException- If an error occurs while the system is reading the file.
-
getMediaType
public static java.lang.String getMediaType(byte[] document) throws UtilsExceptionDetects the media type of the given document.- Parameters:
document- The document stream.- Returns:
- Detected media type.
- Throws:
UtilsException- if the method fails.
-
isImage
public static boolean isImage(java.lang.String mimeType)
Checks if the supplied MimeType is a supported image MimeType.- Parameters:
mimeType- MimeType.- Returns:
- True if the supplied value is a supported image MimeType. Otherwise, false.
-
isTextFile
public static boolean isTextFile(java.lang.String mimeType)
Checks if the supplied MimeType is a supported text plain file or XML file.- Parameters:
mimeType- MimeType.- Returns:
- True if the supplied value is a supported text plain file or XML file. Otherwise, false.
-
-