Package com.wavemaker.commons.util
Class WMIOUtils
- java.lang.Object
-
- com.wavemaker.commons.util.WMIOUtils
-
public abstract class WMIOUtils extends java.lang.Object
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static voidcleanDirectorySilently(java.io.File dir)static voidcleanFolder(Folder folder)static voidcleanFolderSilently(Folder folder)static voidcloseByLogging(java.lang.AutoCloseable e)static voidcloseSilently(java.lang.AutoCloseable stream)static booleancompare(java.io.InputStream i1, java.io.InputStream i2)static voidcopy(java.io.File source, java.io.File destination)Copy from: file to file, directory to directory, file to directory.static voidcopy(java.io.File source, java.io.File destination, java.lang.String includedPattern, java.lang.String excludedPattern)static voidcopy(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 voidcopy(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 intcopy(java.io.InputStream is, java.io.OutputStream os)copies content of InputStream into OutputStream os.static intcopy(java.io.Reader reader, java.io.Writer writer)Copies content of reader into Writer.static voidcopyContent(File sourceFile, File destinationFile)static voidcopyFile(File srcFile, File targetFile)static java.io.FilecreateFile(java.lang.String path)Create a file at given location.static java.io.FilecreateTempDirectory()Create a temporary directory, which will be deleted when the VM exits.static java.io.FilecreateTempDirectory(java.lang.String prefix)Create a temporary directory, which will be deleted when the VM exits.static FilecreateTempFile(java.lang.String prefix, java.lang.String suffix)static FoldercreateTempFolder()static FoldercreateTempFolder(java.lang.String prefix)static voiddeleteDirectorySilently(java.io.File dir)static voiddeleteFile(java.io.File file)static voiddeleteFileSilently(java.io.File dir, boolean noLogging)static voiddeleteRecursive(java.io.File dir)Delete a directory or file; if a directory, delete its children recursively.static voiddeleteResourceSilently(Resource folder)static voiddeleteResourceSilently(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.FilegetJavaIOFile(Resource resource)static voidmakeDirectories(java.io.File newDir, java.io.File topLevel)Create intermediate directories so that the File represented by newFile can be created.static java.lang.Stringread(java.io.File f)Read an entire File into a String.static java.lang.Stringtail(java.io.File f, int lines)Read the bottom of a File into a String.static java.lang.StringtoString(java.io.InputStream is)static java.lang.StringtoString(java.io.Reader reader)static voidtouch(java.io.File f)Touch a file (see touch(1)).static voidwrite(java.io.File f, java.lang.String s)static voidwrite(java.io.OutputStream outputStream, java.lang.String data)
-
-
-
Method Detail
-
read
public static java.lang.String read(java.io.File f) throws java.io.IOExceptionRead 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.IOExceptionRead 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
-
copy
public static int copy(java.io.InputStream is, java.io.OutputStream os) throws java.io.IOExceptioncopies 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.IOExceptionCopies 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.IOExceptionCopy 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.IOExceptionCopy 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.IOExceptionCopy 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.IOExceptionCreate 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.IOExceptionCreate 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.IOExceptionCreate a file at given location.- Throws:
java.io.IOException
-
deleteRecursive
public static void deleteRecursive(java.io.File dir) throws java.io.IOExceptionDelete 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 FileAccessExceptionCreate 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.IOExceptionTouch 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)
-
-