Class WMIOUtils


  • public abstract class WMIOUtils
    extends java.lang.Object
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static void cleanDirectorySilently​(java.io.File dir)  
      static void cleanFolder​(Folder folder)  
      static void cleanFolderSilently​(Folder folder)  
      static void closeByLogging​(java.lang.AutoCloseable e)  
      static void closeSilently​(java.lang.AutoCloseable stream)  
      static boolean compare​(java.io.InputStream i1, java.io.InputStream i2)  
      static void copy​(java.io.File source, java.io.File destination)
      Copy from: file to file, directory to directory, file to directory.
      static void copy​(java.io.File source, java.io.File destination, java.lang.String includedPattern, java.lang.String excludedPattern)  
      static void copy​(java.io.File source, java.io.File destination, java.util.List<java.lang.String> excludes)
      Copy from: file to file, directory to directory, file to directory.
      static void copy​(java.io.File source, java.io.File destination, java.util.List<java.lang.String> includedPatterns, java.util.List<java.lang.String> excludedPatterns)
      Copy from: file to file, directory to directory, file to directory.
      static int copy​(java.io.InputStream is, java.io.OutputStream os)
      copies content of InputStream into OutputStream os.
      static int copy​(java.io.Reader reader, java.io.Writer writer)
      Copies content of reader into Writer.
      static void copyContent​(File sourceFile, File destinationFile)  
      static void copyFile​(File srcFile, File targetFile)  
      static java.io.File createFile​(java.lang.String path)
      Create a file at given location.
      static java.io.File createTempDirectory()
      Create a temporary directory, which will be deleted when the VM exits.
      static java.io.File createTempDirectory​(java.lang.String prefix)
      Create a temporary directory, which will be deleted when the VM exits.
      static File createTempFile​(java.lang.String prefix, java.lang.String suffix)  
      static Folder createTempFolder()  
      static Folder createTempFolder​(java.lang.String prefix)  
      static void deleteDirectorySilently​(java.io.File dir)  
      static void deleteFile​(java.io.File file)  
      static void deleteFileSilently​(java.io.File dir, boolean noLogging)  
      static void deleteRecursive​(java.io.File dir)
      Delete a directory or file; if a directory, delete its children recursively.
      static void deleteResourceSilently​(Resource folder)  
      static void deleteResourceSilently​(Resource resource, boolean noLogging)  
      static java.util.Collection<java.io.File> getFiles​(java.io.File indir)
      Get all files (excluding directories) under dir.
      static java.io.File getJavaIOFile​(Resource resource)  
      static void makeDirectories​(java.io.File newDir, java.io.File topLevel)
      Create intermediate directories so that the File represented by newFile can be created.
      static java.lang.String read​(java.io.File f)
      Read an entire File into a String.
      static java.lang.String tail​(java.io.File f, int lines)
      Read the bottom of a File into a String.
      static java.lang.String toString​(java.io.InputStream is)  
      static java.lang.String toString​(java.io.Reader reader)  
      static void touch​(java.io.File f)
      Touch a file (see touch(1)).
      static void write​(java.io.File f, java.lang.String s)  
      static void write​(java.io.OutputStream outputStream, java.lang.String data)  
      • Methods inherited from class java.lang.Object

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

      • read

        public static java.lang.String read​(java.io.File f)
                                     throws java.io.IOException
        Read an entire File into a String.
        Parameters:
        f - The file to read from.
        Returns:
        The contents of f as a String.
        Throws:
        java.io.IOException
      • tail

        public static java.lang.String tail​(java.io.File f,
                                            int lines)
                                     throws java.io.IOException
        Read the bottom of a File into a String. This probably isn't the proper way to do this in java but my goals here were limited to NOT flooding memory with the entire file, but just to grab the last N lines and never have more than the last N lines in memory
        Throws:
        java.io.IOException
      • write

        public static void write​(java.io.File f,
                                 java.lang.String s)
                          throws java.io.IOException
        Throws:
        java.io.IOException
      • write

        public static void write​(java.io.OutputStream outputStream,
                                 java.lang.String data)
                          throws java.io.IOException
        Throws:
        java.io.IOException
      • compare

        public static boolean compare​(java.io.InputStream i1,
                                      java.io.InputStream i2)
                               throws java.io.IOException
        Throws:
        java.io.IOException
      • copyContent

        public static void copyContent​(File sourceFile,
                                       File destinationFile)
      • copy

        public static int copy​(java.io.InputStream is,
                               java.io.OutputStream os)
                        throws java.io.IOException
        copies content of InputStream into OutputStream os.
        Parameters:
        is - InputStream to read from.
        os - OutputStream to write to.
        Returns:
        returns the number of bytes actually written
        Throws:
        java.io.IOException - Note : This method never closes the parameterized streams;
      • copy

        public static int copy​(java.io.Reader reader,
                               java.io.Writer writer)
                        throws java.io.IOException
        Copies content of reader into Writer.
        Parameters:
        reader - Reader to read from.
        writer - Writer to write to.
        Returns:
        returns the number of characters actually written
        Throws:
        java.io.IOException - Note : This method never closes the parameterized streams;
      • copy

        public static void copy​(java.io.File source,
                                java.io.File destination)
                         throws java.io.IOException
        Copy from: file to file, directory to directory, file to directory. Defaults to exclude nothing, so all files and directories are copied.
        Parameters:
        source - File object representing a file or directory to copy from.
        destination - File object representing the target; can only represent a file if the source is a file.
        Throws:
        java.io.IOException
      • copy

        public static void copy​(java.io.File source,
                                java.io.File destination,
                                java.util.List<java.lang.String> excludes)
                         throws java.io.IOException
        Copy from: file to file, directory to directory, file to directory.
        Parameters:
        source - File object representing a file or directory to copy from.
        destination - File object representing the target; can only represent a file if the source is a file.
        excludes - A list of exclusion filenames.
        Throws:
        java.io.IOException
      • copy

        public static void copy​(java.io.File source,
                                java.io.File destination,
                                java.lang.String includedPattern,
                                java.lang.String excludedPattern)
                         throws java.io.IOException
        Throws:
        java.io.IOException
      • copy

        public static void copy​(java.io.File source,
                                java.io.File destination,
                                java.util.List<java.lang.String> includedPatterns,
                                java.util.List<java.lang.String> excludedPatterns)
                         throws java.io.IOException
        Copy from: file to file, directory to directory, file to directory.
        Parameters:
        source - File object representing a file or directory to copy from.
        destination - File object representing the target; can only represent a file if the source is a file.
        includedPatterns - the ant-style path pattern to be included. Null means that all resources are included.
        excludedPatterns - the ant-style path pattern to be excluded. Null means that no resources are excluded.
        Throws:
        java.io.IOException
      • copyFile

        public static void copyFile​(File srcFile,
                                    File targetFile)
                             throws java.io.IOException
        Throws:
        java.io.IOException
      • createTempFile

        public static File createTempFile​(java.lang.String prefix,
                                          java.lang.String suffix)
      • createTempDirectory

        public static java.io.File createTempDirectory()
                                                throws java.io.IOException
        Create a temporary directory, which will be deleted when the VM exits.
        Returns:
        The newly create temp directory
        Throws:
        java.io.IOException - in case of IOExceptions.
      • createTempFolder

        public static Folder createTempFolder()
      • createTempFolder

        public static Folder createTempFolder​(java.lang.String prefix)
      • createTempDirectory

        public static java.io.File createTempDirectory​(java.lang.String prefix)
                                                throws java.io.IOException
        Create a temporary directory, which will be deleted when the VM exits.
        Parameters:
        prefix - String used for directory name
        Returns:
        The newly create temp directory
        Throws:
        java.io.IOException
      • createFile

        public static java.io.File createFile​(java.lang.String path)
                                       throws java.io.IOException
        Create a file at given location.
        Throws:
        java.io.IOException
      • deleteRecursive

        public static void deleteRecursive​(java.io.File dir)
                                    throws java.io.IOException
        Delete a directory or file; if a directory, delete its children recursively.
        Throws:
        java.io.IOException
      • cleanFolder

        public static void cleanFolder​(Folder folder)
      • cleanFolderSilently

        public static void cleanFolderSilently​(Folder folder)
      • cleanDirectorySilently

        public static void cleanDirectorySilently​(java.io.File dir)
      • deleteDirectorySilently

        public static void deleteDirectorySilently​(java.io.File dir)
      • deleteResourceSilently

        public static void deleteResourceSilently​(Resource folder)
      • deleteResourceSilently

        public static void deleteResourceSilently​(Resource resource,
                                                  boolean noLogging)
      • toString

        public static java.lang.String toString​(java.io.Reader reader)
      • toString

        public static java.lang.String toString​(java.io.InputStream is)
      • deleteFileSilently

        public static void deleteFileSilently​(java.io.File dir,
                                              boolean noLogging)
      • deleteFile

        public static void deleteFile​(java.io.File file)
      • makeDirectories

        public static void makeDirectories​(java.io.File newDir,
                                           java.io.File topLevel)
                                    throws FileAccessException
        Create intermediate directories so that the File represented by newFile can be created.
        Parameters:
        newDir - The directory that will be created; this method will ensure that the intermediate directories exist, and that this File is within the topLevel file.
        topLevel - This file should represent the top-level directory that files will not be created outside of.
        Throws:
        FileAccessException
      • getFiles

        public static java.util.Collection<java.io.File> getFiles​(java.io.File indir)
        Get all files (excluding directories) under dir.
      • touch

        public static void touch​(java.io.File f)
                          throws java.io.IOException
        Touch a file (see touch(1)). If the file doesn't exist, create it as an empty file. If it does exist, update its modification time.
        Parameters:
        f - The File.
        Throws:
        java.io.IOException
      • closeSilently

        public static void closeSilently​(java.lang.AutoCloseable stream)
      • closeByLogging

        public static void closeByLogging​(java.lang.AutoCloseable e)
      • getJavaIOFile

        public static java.io.File getJavaIOFile​(Resource resource)