org.eclipse.mylar.monitor.reports.tests
Class FileTool

java.lang.Object
  extended by org.eclipse.mylar.monitor.reports.tests.FileTool

public class FileTool
extends java.lang.Object

Provides access to files for testing. TODO: Copied from the bugzilla component - consider refactoring as common utility


Field Summary
private static byte[] buffer
          A buffer.
private static int MAX_RETRY
           
 
Constructor Summary
FileTool()
           
 
Method Summary
static java.lang.String changeSeparator(java.lang.String path, char oldSeparator, char newSeparator)
          Returns the given file path with its separator character changed from the given old separator to the given new separator.
static void copy(java.io.File src, java.io.File dst)
          Copies the given source file to the given destination file.
static java.io.File createTempFileInPlugin(org.eclipse.core.runtime.Plugin plugin, org.eclipse.core.runtime.IPath path)
           
static void delete(java.io.File file)
           
static java.io.File getFileInPlugin(org.eclipse.core.runtime.Plugin plugin, org.eclipse.core.runtime.IPath path)
           
static java.lang.StringBuffer read(java.io.Reader reader)
           
static java.lang.StringBuffer read(java.lang.String fileName)
           
static void transferData(java.io.File source, java.io.File destination)
          Copies all bytes in the given source file to the given destination file.
static void transferData(java.io.InputStream source, java.io.OutputStream destination)
          Copies all bytes in the given source stream to the given destination stream.
static void unzip(java.util.zip.ZipFile zipFile, java.io.File dstDir)
          Unzips the given zip file to the given destination directory extracting only those entries the pass through the given filter.
private static void unzip(java.util.zip.ZipFile zipFile, java.io.File rootDstDir, java.io.File dstDir, int depth)
           
static void write(java.lang.String fileName, java.lang.StringBuffer content)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MAX_RETRY

private static final int MAX_RETRY
See Also:
Constant Field Values

buffer

private static byte[] buffer
A buffer.

Constructor Detail

FileTool

public FileTool()
Method Detail

unzip

public static void unzip(java.util.zip.ZipFile zipFile,
                         java.io.File dstDir)
                  throws java.io.IOException
Unzips the given zip file to the given destination directory extracting only those entries the pass through the given filter.

Parameters:
zipFile - the zip file to unzip
dstDir - the destination directory
Throws:
java.io.IOException - in case of problem

unzip

private static void unzip(java.util.zip.ZipFile zipFile,
                          java.io.File rootDstDir,
                          java.io.File dstDir,
                          int depth)
                   throws java.io.IOException
Throws:
java.io.IOException

changeSeparator

public static java.lang.String changeSeparator(java.lang.String path,
                                               char oldSeparator,
                                               char newSeparator)
Returns the given file path with its separator character changed from the given old separator to the given new separator.

Parameters:
path - a file path
oldSeparator - a path separator character
newSeparator - a path separator character
Returns:
the file path with its separator character changed from the given old separator to the given new separator

transferData

public static void transferData(java.io.File source,
                                java.io.File destination)
                         throws java.io.IOException
Copies all bytes in the given source file to the given destination file.

Parameters:
source - the given source file
destination - the given destination file
Throws:
java.io.IOException - in case of error

transferData

public static void transferData(java.io.InputStream source,
                                java.io.OutputStream destination)
                         throws java.io.IOException
Copies all bytes in the given source stream to the given destination stream. Neither streams are closed.

Parameters:
source - the given source stream
destination - the given destination stream
Throws:
java.io.IOException - in case of error

copy

public static void copy(java.io.File src,
                        java.io.File dst)
                 throws java.io.IOException
Copies the given source file to the given destination file.

Parameters:
src - the given source file
dst - the given destination file
Throws:
java.io.IOException - in case of error

getFileInPlugin

public static java.io.File getFileInPlugin(org.eclipse.core.runtime.Plugin plugin,
                                           org.eclipse.core.runtime.IPath path)

createTempFileInPlugin

public static java.io.File createTempFileInPlugin(org.eclipse.core.runtime.Plugin plugin,
                                                  org.eclipse.core.runtime.IPath path)

read

public static java.lang.StringBuffer read(java.lang.String fileName)
                                   throws java.io.IOException
Throws:
java.io.IOException

read

public static java.lang.StringBuffer read(java.io.Reader reader)
                                   throws java.io.IOException
Throws:
java.io.IOException

write

public static void write(java.lang.String fileName,
                         java.lang.StringBuffer content)
                  throws java.io.IOException
Throws:
java.io.IOException

delete

public static void delete(java.io.File file)