Class IOUtils


  • public class IOUtils
    extends java.lang.Object
    • Constructor Summary

      Constructors 
      Constructor Description
      IOUtils()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static void close​(java.io.Closeable c)
      Close some xStream for good :)
      static void close​(java.util.zip.ZipFile file)
      A special version of close() for ZipFiles, which don't implement Closeable.
      static void copy​(java.io.InputStream in, java.io.OutputStream out)
      Copy an InputStream to an OutputStream and close the InputStream afterwards.
      static void copyAndDoNotCloseInputStream​(java.io.InputStream in, java.io.OutputStream out)
      Copy an InputStream to an OutputStream and do not close the InputStream afterwards.
      static boolean deleteRecursive​(java.io.File root)
      Do rm -rf
      static java.io.OutputStream getOutputStream​(java.io.File outputDir, java.lang.String relativePath)  
      static void jarUp​(java.io.File rootDir, java.io.File targetFile, java.util.jar.Manifest manifest)
      Jar up all the contents of rootDir (recursively) into targetFile and add the manifest
      static boolean unpackZip​(IFile zip, java.io.File outputDir)
      Unpack the zip file into the outputDir
      static void writeOut​(java.io.File outputDir, java.lang.String relativePath, java.io.InputStream content)
      Write the given InputStream to a file given by a root directory (outputDir) and a relative directory.
      static void writeOutAndDontCloseInputStream​(java.io.File outputDir, java.lang.String relativePath, java.io.InputStream content)
      Write the given InputStream to a file given by a root directory (outputDir) and a relative directory.
      static void zipUp​(java.io.File rootDir, java.io.File targetFile)
      Zip up all contents of rootDir (recursively) into targetFile
      static void zipUp​(java.io.File rootDir, java.io.OutputStream targetStream)
      Zip up all contents of rootDir (recursively) into targetStream
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • IOUtils

        public IOUtils()
    • Method Detail

      • copy

        public static void copy​(java.io.InputStream in,
                                java.io.OutputStream out)
                         throws java.io.IOException
        Copy an InputStream to an OutputStream and close the InputStream afterwards.
        Throws:
        java.io.IOException
      • copyAndDoNotCloseInputStream

        public static void copyAndDoNotCloseInputStream​(java.io.InputStream in,
                                                        java.io.OutputStream out)
                                                 throws java.io.IOException
        Copy an InputStream to an OutputStream and do not close the InputStream afterwards.
        Throws:
        java.io.IOException
      • close

        public static void close​(java.io.Closeable c)
        Close some xStream for good :)
      • close

        public static void close​(java.util.zip.ZipFile file)
                          throws java.io.IOException
        A special version of close() for ZipFiles, which don't implement Closeable.
        Parameters:
        file - the file to close. ZipFiles seem prone to file locking problems on Windows, so to aid diagnostics we throw, not swallow, any exceptions.
        Throws:
        java.io.IOException
      • getOutputStream

        public static java.io.OutputStream getOutputStream​(java.io.File outputDir,
                                                           java.lang.String relativePath)
                                                    throws java.io.IOException
        Throws:
        java.io.IOException
      • writeOut

        public static void writeOut​(java.io.File outputDir,
                                    java.lang.String relativePath,
                                    java.io.InputStream content)
                             throws java.io.IOException
        Write the given InputStream to a file given by a root directory (outputDir) and a relative directory. Necessary subdirectories will be created. This method will close the supplied InputStream.
        Throws:
        java.io.IOException
      • writeOutAndDontCloseInputStream

        public static void writeOutAndDontCloseInputStream​(java.io.File outputDir,
                                                           java.lang.String relativePath,
                                                           java.io.InputStream content)
                                                    throws java.io.IOException
        Write the given InputStream to a file given by a root directory (outputDir) and a relative directory. Necessary subdirectories will be created. This method will not close the supplied InputStream.
        Throws:
        java.io.IOException
      • zipUp

        public static void zipUp​(java.io.File rootDir,
                                 java.io.OutputStream targetStream)
                          throws java.io.IOException
        Zip up all contents of rootDir (recursively) into targetStream
        Throws:
        java.io.IOException
      • zipUp

        public static void zipUp​(java.io.File rootDir,
                                 java.io.File targetFile)
                          throws java.io.IOException
        Zip up all contents of rootDir (recursively) into targetFile
        Throws:
        java.io.IOException
      • jarUp

        public static void jarUp​(java.io.File rootDir,
                                 java.io.File targetFile,
                                 java.util.jar.Manifest manifest)
                          throws java.io.IOException
        Jar up all the contents of rootDir (recursively) into targetFile and add the manifest
        Throws:
        java.io.IOException
      • deleteRecursive

        public static boolean deleteRecursive​(java.io.File root)
        Do rm -rf
      • unpackZip

        public static boolean unpackZip​(IFile zip,
                                        java.io.File outputDir)
                                 throws java.io.IOException
        Unpack the zip file into the outputDir
        Parameters:
        zip -
        outputDir -
        Returns:
        true if the zip was expanded, false if the zip was found not to be a zip
        Throws:
        java.io.IOException - when there are unexpected issues handling the zip files.