Class IOUtil


  • public class IOUtil
    extends java.lang.Object
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static byte[] addJarEntry​(byte[] jarToUpdate, java.lang.String entryName, byte[] entryContent)  
      static boolean checkMD5​(java.io.File md5File, byte[] contentToCheck)  
      static java.io.File createTempDirectory​(java.net.URI directoryPath)  
      static boolean deleteDir​(java.io.File dir)  
      static boolean deleteDir​(java.io.File dir, int attempts, long sleepTime)  
      static boolean deleteFile​(java.io.File file, int attempts, long sleepTime)  
      static byte[] generateJar​(java.lang.Class<?>... classes)  
      static byte[] generateJar​(java.util.Map<java.lang.String,​byte[]> resources)  
      static byte[] generateZip​(java.util.Map<java.lang.String,​byte[]> resources)  
      static byte[] getAllContentFrom​(java.io.File file)
      static byte[] getAllContentFrom​(java.io.InputStream in)
      Return the whole underlying stream content into a single String.
      static byte[] getAllContentFrom​(java.net.URL url)
      Return the whole underlying stream content into a single String.
      static byte[] getBytes​(java.util.zip.ZipInputStream zipInputstream)  
      static java.util.List<java.lang.String> getClassNameList​(byte[] jarContent)  
      static java.lang.String getContentTypeForIcon​(java.lang.String iconFilename)  
      static java.util.Optional<byte[]> getFileContent​(java.lang.String fileName)
      return the content of the file from the classpath, the file must be at the root of the classpath
      static byte[] getPropertyAsString​(java.util.Properties prop, java.lang.String comment)  
      static java.util.Map<java.lang.String,​byte[]> getResources​(java.lang.Class<?>... classes)  
      static byte[] getZipEntryContent​(java.lang.String entryName, byte[] zipFile)  
      static byte[] getZipEntryContent​(java.lang.String entryName, java.io.InputStream inputStream)  
      static java.lang.String md5​(byte[] content)  
      static java.lang.String read​(java.io.File file)
      Read the contents of the given file.
      static java.lang.String read​(java.io.InputStream inputStream)
      Read the contents from the given FileInputStream.
      static java.lang.String readResource​(java.lang.String fileName)  
      static byte[] toByteArray​(org.w3c.dom.Document document)  
      static java.util.Map<java.lang.String,​byte[]> unzip​(byte[] zipFile)  
      static void updatePropertyValue​(java.io.File propertiesFile, java.util.Map<java.lang.String,​java.lang.String> pairs)  
      static void write​(java.io.File file, byte[] fileContent)  
      static void writeFile​(java.io.File file, java.lang.String fileContent)  
      static void writeMD5​(java.io.File file, byte[] bytes)  
      static byte[] zip​(java.util.Map<java.lang.String,​byte[]> files)  
      static byte[] zip​(Pair<java.lang.String,​byte[]>... files)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • TMP_DIRECTORY

        public static final java.lang.String TMP_DIRECTORY
      • MIMETYPES_FILE_TYPE_MAP

        public static final javax.activation.MimetypesFileTypeMap MIMETYPES_FILE_TYPE_MAP
    • Method Detail

      • getClassNameList

        public static java.util.List<java.lang.String> getClassNameList​(byte[] jarContent)
                                                                 throws java.io.IOException
        Throws:
        java.io.IOException
      • write

        public static void write​(java.io.File file,
                                 byte[] fileContent)
                          throws java.io.IOException
        Throws:
        java.io.IOException
      • generateJar

        public static byte[] generateJar​(java.lang.Class<?>... classes)
                                  throws java.io.IOException
        Throws:
        java.io.IOException
      • getResources

        public static java.util.Map<java.lang.String,​byte[]> getResources​(java.lang.Class<?>... classes)
                                                                         throws java.io.IOException
        Throws:
        java.io.IOException
      • generateJar

        public static byte[] generateJar​(java.util.Map<java.lang.String,​byte[]> resources)
                                  throws java.io.IOException
        Throws:
        java.io.IOException
      • generateZip

        public static byte[] generateZip​(java.util.Map<java.lang.String,​byte[]> resources)
                                  throws java.io.IOException
        Throws:
        java.io.IOException
      • getAllContentFrom

        public static byte[] getAllContentFrom​(java.io.InputStream in)
                                        throws java.io.IOException
        Return the whole underlying stream content into a single String. Warning: the whole content of stream will be kept in memory!! Use with care!
        Parameters:
        in - the stream to read
        Returns:
        the whole content of the stream in a single String.
        Throws:
        java.io.IOException - if an I/O exception occurs
      • read

        public static java.lang.String read​(java.io.InputStream inputStream)
        Read the contents from the given FileInputStream. Return the result as a String.
        Parameters:
        inputStream - the stream to read from
        Returns:
        the content read from the inputStream, as a String
      • read

        public static java.lang.String read​(java.io.File file)
                                     throws java.io.IOException
        Read the contents of the given file.
        Parameters:
        file -
        Throws:
        java.io.IOException
      • getAllContentFrom

        public static byte[] getAllContentFrom​(java.io.File file)
                                        throws java.io.IOException
        Parameters:
        file - the file to read
        Returns:
        the whole content of the file in a single String.
        Throws:
        java.io.IOException - If an I/O exception occurs
      • getAllContentFrom

        public static byte[] getAllContentFrom​(java.net.URL url)
                                        throws java.io.IOException
        Return the whole underlying stream content into a single String. Warning: the whole content of stream will be kept in memory!! Use with care!
        Parameters:
        url - the URL to read
        Returns:
        the whole content of the stream in a single String.
        Throws:
        java.io.IOException - if an I/O exception occurs
      • deleteDir

        public static boolean deleteDir​(java.io.File dir)
                                 throws java.io.IOException
        Throws:
        java.io.IOException
      • deleteDir

        public static boolean deleteDir​(java.io.File dir,
                                        int attempts,
                                        long sleepTime)
                                 throws java.io.IOException
        Throws:
        java.io.IOException
      • deleteFile

        public static boolean deleteFile​(java.io.File file,
                                         int attempts,
                                         long sleepTime)
      • writeFile

        public static void writeFile​(java.io.File file,
                                     java.lang.String fileContent)
                              throws java.io.IOException
        Throws:
        java.io.IOException
      • zip

        public static byte[] zip​(java.util.Map<java.lang.String,​byte[]> files)
                          throws java.io.IOException
        Throws:
        java.io.IOException
      • zip

        public static byte[] zip​(Pair<java.lang.String,​byte[]>... files)
                          throws java.io.IOException
        Throws:
        java.io.IOException
      • unzip

        public static final java.util.Map<java.lang.String,​byte[]> unzip​(byte[] zipFile)
                                                                        throws java.io.IOException
        Throws:
        java.io.IOException
      • getZipEntryContent

        public static byte[] getZipEntryContent​(java.lang.String entryName,
                                                java.io.InputStream inputStream)
                                         throws java.io.IOException
        Throws:
        java.io.IOException
      • getBytes

        public static byte[] getBytes​(java.util.zip.ZipInputStream zipInputstream)
                               throws java.io.IOException
        Throws:
        java.io.IOException
      • getZipEntryContent

        public static byte[] getZipEntryContent​(java.lang.String entryName,
                                                byte[] zipFile)
                                         throws java.io.IOException
        Throws:
        java.io.IOException
      • toByteArray

        public static byte[] toByteArray​(org.w3c.dom.Document document)
                                  throws java.io.IOException,
                                         javax.xml.transform.TransformerException
        Throws:
        java.io.IOException
        javax.xml.transform.TransformerException
      • addJarEntry

        public static byte[] addJarEntry​(byte[] jarToUpdate,
                                         java.lang.String entryName,
                                         byte[] entryContent)
                                  throws java.io.IOException
        Throws:
        java.io.IOException
      • getPropertyAsString

        public static byte[] getPropertyAsString​(java.util.Properties prop,
                                                 java.lang.String comment)
                                          throws java.io.IOException
        Throws:
        java.io.IOException
      • readResource

        public static java.lang.String readResource​(java.lang.String fileName)
                                             throws java.io.IOException
        Throws:
        java.io.IOException
      • md5

        public static java.lang.String md5​(byte[] content)
                                    throws java.security.NoSuchAlgorithmException
        Throws:
        java.security.NoSuchAlgorithmException
      • writeMD5

        public static void writeMD5​(java.io.File file,
                                    byte[] bytes)
                             throws java.security.NoSuchAlgorithmException,
                                    java.io.IOException
        Throws:
        java.security.NoSuchAlgorithmException
        java.io.IOException
      • checkMD5

        public static boolean checkMD5​(java.io.File md5File,
                                       byte[] contentToCheck)
                                throws java.security.NoSuchAlgorithmException
        Throws:
        java.security.NoSuchAlgorithmException
      • updatePropertyValue

        public static void updatePropertyValue​(java.io.File propertiesFile,
                                               java.util.Map<java.lang.String,​java.lang.String> pairs)
                                        throws java.io.IOException
        Throws:
        java.io.IOException
      • getContentTypeForIcon

        public static java.lang.String getContentTypeForIcon​(java.lang.String iconFilename)
      • getFileContent

        public static java.util.Optional<byte[]> getFileContent​(java.lang.String fileName)
                                                         throws java.io.IOException
        return the content of the file from the classpath, the file must be at the root of the classpath
        Parameters:
        fileName - name of the file
        Returns:
        the optional, or empty if there is no file with that name
        Throws:
        java.io.IOException - when we are unable to read the file from the classpath
      • createTempDirectory

        public static java.io.File createTempDirectory​(java.net.URI directoryPath)