Class FileUtils


  • public final class FileUtils
    extends java.lang.Object

    Utility 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.String BMP_MEDIA_TYPE
      Attribute that represents the BMP media type.
      static java.lang.String DATA_FILE_EXTENSION
      Attribute that represents the extension used for the Binary Files.
      static java.lang.String GIF_MEDIA_TYPE
      Attribute that represents the GIF media type.
      static java.lang.String HTML_MEDIA_TYPE
      Attribute that represents the HTML media type.
      static java.lang.String JPEG_MEDIA_TYPE
      Attribute that represents the JPEG media type.
      static java.lang.String MSOFFICE_DOC_MEDIA_TYPE
      Attribute that represents the microsoft word media type.
      static java.lang.String MSOFFICE_DOCX_MEDIA_TYPE
      Attribute that represents the microsoft word media type (in open xml format).
      static java.lang.String MSOFFICE_PPT_MEDIA_TYPE
      Attribute that represents the microsoft powerpoint media type.
      static java.lang.String MSOFFICE_PPTX_MEDIA_TYPE
      Attribute that represents the microsoft powerpoint media type (in open xml format).
      static java.lang.String MSOFFICE_XLS_MEDIA_TYPE
      Attribute that represents the microsoft excel media type.
      static java.lang.String MSOFFICE_XLSX_MEDIA_TYPE
      Attribute that represents the microsoft excel media type (in open xml format).
      static java.lang.String ODC_MEDIA_TYPE
      Attribute that represents the ODC media type.
      static java.lang.String ODG_MEDIA_TYPE
      Attribute that represents the ODG media type.
      static java.lang.String ODP_MEDIA_TYPE
      Attribute that represents the ODP media type.
      static java.lang.String ODS_MEDIA_TYPE
      Attribute that represents the ODS media type.
      static java.lang.String ODT_MEDIA_TYPE
      Attribute that represents the ODT media type.
      static java.lang.String PDF_MEDIA_TYPE
      Attribute that represents the PDF media type.
      static java.lang.String PNG_MEDIA_TYPE
      Attribute that represents the PNG media type.
      static java.lang.String RTF_MEDIA_TYPE
      Attribute that represents the RTF media type.
      static java.lang.String TIFF_MEDIA_TYPE
      Attribute that represents the PNG media type.
      static java.lang.String TXT_MEDIA_TYPE
      Attribute that represents the text plain media type.
      static java.lang.String XML_MEDIA_TYPE
      Attribute that represents the XML media type.
      static java.lang.String XSLT_MEDIA_TYPE
      Attribute 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.String getFileExtension​(byte[] file)
      Gets the file extension.
      static java.lang.String getFileExtension​(java.lang.String mimeType)
      Gets the file extension.
      static java.lang.String getMediaType​(byte[] document)
      Detects the media type of the given document.
      static boolean isImage​(java.lang.String mimeType)
      Checks if the supplied MimeType is a supported image MimeType.
      static boolean isTextFile​(java.lang.String mimeType)
      Checks if the supplied MimeType is a supported text plain file or XML file.
      static boolean isXML​(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 a Blob object.
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • 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 UtilsException
        Gets 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 UtilsException
        Gets the file extension.
        Parameters:
        mimeType - MimeType.
        Returns:
        File extension.
        Throws:
        UtilsException - If an error occurs.
      • isXML

        public static boolean isXML​(byte[] file)
                             throws UtilsException
        Checks 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 UtilsException
        Method that obtains a bytes array from a Blob object.
        Parameters:
        fromBlob - Parameter that represents the Blob object.
        Returns:
        a bytes array from a Blob object.
        Throws:
        UtilsException - If an error occurs.
      • getFile

        public static byte[] getFile​(java.lang.String templatePath)
                              throws UtilsException
        Method 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 UtilsException
        Detects 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.