com.jaxfront.core.util.io
Class FileHelper

java.lang.Object
  extended by com.jaxfront.core.util.io.FileHelper

public class FileHelper
extends java.lang.Object

The FileHelper class defines a set of convenience methods for file handling!

Version:
1.60

Field Summary
static java.lang.String ESCPAE_HTML
           
static java.lang.String PROTOCOL_FILE
           
 
Constructor Summary
FileHelper()
          Constructor of FileHelper
FileHelper(java.io.File file)
          Constructor of FileHelper
FileHelper(java.io.File file, boolean createDirs)
          Constructor of FileHelper
FileHelper(java.lang.String resourceURL)
          Constructor of FileHelper
FileHelper(java.lang.String resourceURL, boolean createDirs)
           
FileHelper(java.net.URL resourceURL)
          Constructor of FileHelper
FileHelper(java.net.URL resourceURL, boolean createDirs)
          Constructor of FileHelper
 
Method Summary
 void closeFileEntry()
          Close all output streams of the FileHelper instance.
static void copy(java.io.File source, java.io.File destination)
          Copy a file from source to destination
static void copy(java.net.URL source, java.io.File destination)
          Copy a file from source to destination
static void copy(java.net.URL source, java.net.URL destination)
          Copy a file from source to destination
static byte[] decodeBase64Ziped(java.lang.String value)
           
static void deleteDir(java.io.File[] file, boolean deep)
           
static void deleteDir(java.io.File file, boolean deep)
           
static java.lang.String encodeBase64Ziped(byte[] value)
           
static java.lang.String encodeBase64Ziped(java.io.InputStream is)
           
static boolean fileExist(java.io.File file)
          check if a file exists.
static boolean fileExist(java.lang.String file)
          check if a file exists.
static java.io.File getDirectory(java.io.File source)
           
static java.io.File getDirectory(java.net.URL fileToOpen)
           
static java.lang.String getFileNameExtension(java.io.File file)
           
static java.lang.String getFileNameExtension(java.io.File file, boolean includeDot)
           
static boolean mkdirs(java.io.File file, boolean includingLeaf)
          Creates the directory named by this abstract pathname, including any necessary but nonexistent parent directories.
 void openFileEntry(java.net.URL filename)
          Open a FileOutputStream for the given URL.
 void openFileEntry(java.net.URL filename, boolean createDirs)
          Open a FileOutputStream for the given URL.
static byte[] read(java.io.InputStream in)
          Reads a file and returns the content as bytearray.
static java.lang.String readAsString(java.io.InputStream in, java.lang.String encoding)
          Reads a file and returns the content as String.
static java.lang.String[][] readDelimFile(java.net.URL fileUrl, java.lang.String delim)
           
static byte[] readFile(java.io.File file)
          Reads a file and returns the content as bytearray.
static byte[] readFile(java.lang.String filename)
          Reads a file and returns the content as bytearray.
static byte[] readFile(java.net.URL fileUrl)
          Reads a file and returns the content as bytearray.
static java.lang.String readFileAsString(org.w3c.dom.ls.LSInput xsdInput)
           
static java.lang.String readFileAsString(java.net.URL fileUrl)
           
static java.lang.String readFileAsString(java.net.URL fileUrl, java.lang.String encoding)
          Reads a file and returns the content as String.
static java.lang.String removeFileNameExtension(java.lang.String fileName)
           
static void save(java.lang.Object myObject, java.lang.String filename)
          Save a Java object into a file using java.io.ObjectOutputStream.
static void save(java.lang.StringBuffer buffer, java.io.File file, java.lang.String encoding)
           
static void save(java.lang.String buffer, java.io.File file, java.lang.String encoding)
           
static java.lang.String tail(java.lang.String fileName, int lineCount)
           
static void tail(java.lang.String fileName, int lineCount, int bufferSize, java.io.Writer pw, java.lang.String escapeAs)
           
static void tail(java.lang.String fileName, int lineCount, java.io.PrintWriter writer, java.lang.String escapeAs)
           
static java.io.OutputStream write(java.io.InputStream inStream, java.io.OutputStream outstream)
           
static java.io.Writer write(java.io.Reader inReader, java.io.Writer outwriter)
           
static void write(java.lang.String buffer, java.io.Writer writer)
           
 FileHelper writeIntoFile(byte[] in)
          Write's the byte sequence into the opened outputstream.
 FileHelper writeIntoFile(char[] in)
          Write's the char sequence into the opened outputstream.
 FileHelper writeIntoFile(java.io.InputStream in)
          Streams the InputStream into the opened outputstream.
 FileHelper writeIntoFile(java.io.Reader in)
          Streams the Reader into the opened outputstream.
 FileHelper writeIntoFile(java.lang.String in)
          Write's the String into the opened outputstream.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PROTOCOL_FILE

public static final java.lang.String PROTOCOL_FILE
See Also:
Constant Field Values

ESCPAE_HTML

public static final java.lang.String ESCPAE_HTML
See Also:
Constant Field Values
Constructor Detail

FileHelper

public FileHelper(java.lang.String resourceURL)
           throws java.io.FileNotFoundException,
                  java.net.MalformedURLException
Constructor of FileHelper

Parameters:
resourceURL -
Throws:
java.io.FileNotFoundException
java.net.MalformedURLException

FileHelper

public FileHelper(java.lang.String resourceURL,
                  boolean createDirs)
           throws java.io.FileNotFoundException,
                  java.net.MalformedURLException
Throws:
java.io.FileNotFoundException
java.net.MalformedURLException

FileHelper

public FileHelper(java.net.URL resourceURL)
           throws java.io.FileNotFoundException
Constructor of FileHelper

Parameters:
resourceURL -
Throws:
java.io.FileNotFoundException

FileHelper

public FileHelper(java.net.URL resourceURL,
                  boolean createDirs)
           throws java.io.FileNotFoundException
Constructor of FileHelper

Parameters:
resourceURL -
Throws:
java.io.FileNotFoundException

FileHelper

public FileHelper(java.io.File file)
           throws java.io.FileNotFoundException,
                  java.net.MalformedURLException
Constructor of FileHelper

Parameters:
file -
Throws:
java.io.FileNotFoundException
java.net.MalformedURLException

FileHelper

public FileHelper(java.io.File file,
                  boolean createDirs)
           throws java.io.FileNotFoundException,
                  java.net.MalformedURLException
Constructor of FileHelper

Parameters:
file -
Throws:
java.io.FileNotFoundException
java.net.MalformedURLException

FileHelper

public FileHelper()
           throws java.io.FileNotFoundException
Constructor of FileHelper

Throws:
java.io.FileNotFoundException
Method Detail

save

public static void save(java.lang.Object myObject,
                        java.lang.String filename)
Save a Java object into a file using java.io.ObjectOutputStream.

Parameters:
myObject -
filename -
See Also:
ObjectOutputStream

readFile

public static byte[] readFile(java.lang.String filename)
                       throws java.io.IOException
Reads a file and returns the content as bytearray.

Parameters:
filename -
Returns:
Throws:
java.io.IOException

readFile

public static byte[] readFile(java.io.File file)
                       throws java.io.IOException
Reads a file and returns the content as bytearray.

Parameters:
file -
Returns:
Throws:
java.io.IOException

readFile

public static byte[] readFile(java.net.URL fileUrl)
                       throws java.io.IOException
Reads a file and returns the content as bytearray.

Parameters:
fileUrl -
Returns:
Throws:
java.io.IOException

read

public static byte[] read(java.io.InputStream in)
                   throws java.io.IOException
Reads a file and returns the content as bytearray.

Parameters:
fileUrl -
Returns:
Throws:
java.io.IOException

removeFileNameExtension

public static java.lang.String removeFileNameExtension(java.lang.String fileName)

getFileNameExtension

public static java.lang.String getFileNameExtension(java.io.File file)

getFileNameExtension

public static java.lang.String getFileNameExtension(java.io.File file,
                                                    boolean includeDot)

readFileAsString

public static java.lang.String readFileAsString(java.net.URL fileUrl)
                                         throws java.io.IOException
Throws:
java.io.IOException

readDelimFile

public static java.lang.String[][] readDelimFile(java.net.URL fileUrl,
                                                 java.lang.String delim)
                                          throws java.io.IOException
Throws:
java.io.IOException

readFileAsString

public static java.lang.String readFileAsString(java.net.URL fileUrl,
                                                java.lang.String encoding)
                                         throws java.io.IOException
Reads a file and returns the content as String.

Parameters:
fileUrl -
Returns:
Throws:
java.io.IOException

readFileAsString

public static java.lang.String readFileAsString(org.w3c.dom.ls.LSInput xsdInput)
                                         throws java.io.IOException
Throws:
java.io.IOException

readAsString

public static java.lang.String readAsString(java.io.InputStream in,
                                            java.lang.String encoding)
                                     throws java.io.IOException
Reads a file and returns the content as String.

Parameters:
fileUrl -
Returns:
Throws:
java.io.IOException

write

public static java.io.OutputStream write(java.io.InputStream inStream,
                                         java.io.OutputStream outstream)
                                  throws java.io.IOException
Throws:
java.io.IOException

write

public static java.io.Writer write(java.io.Reader inReader,
                                   java.io.Writer outwriter)
                            throws java.io.IOException
Throws:
java.io.IOException

save

public static void save(java.lang.StringBuffer buffer,
                        java.io.File file,
                        java.lang.String encoding)
                 throws java.io.IOException
Throws:
java.io.IOException

save

public static void save(java.lang.String buffer,
                        java.io.File file,
                        java.lang.String encoding)
                 throws java.io.IOException
Throws:
java.io.IOException

write

public static void write(java.lang.String buffer,
                         java.io.Writer writer)
                  throws java.io.IOException
Throws:
java.io.IOException

fileExist

public static boolean fileExist(java.io.File file)
check if a file exists.

Parameters:
file -
Returns:

fileExist

public static boolean fileExist(java.lang.String file)
check if a file exists.

Parameters:
file -
Returns:

openFileEntry

public void openFileEntry(java.net.URL filename)
                   throws java.io.FileNotFoundException
Open a FileOutputStream for the given URL.

Parameters:
filename -
Throws:
java.io.FileNotFoundException

openFileEntry

public void openFileEntry(java.net.URL filename,
                          boolean createDirs)
                   throws java.io.FileNotFoundException
Open a FileOutputStream for the given URL.

Parameters:
filename -
Throws:
java.io.FileNotFoundException

closeFileEntry

public void closeFileEntry()
                    throws java.io.IOException
Close all output streams of the FileHelper instance.

Throws:
java.io.IOException

writeIntoFile

public FileHelper writeIntoFile(java.io.InputStream in)
                         throws java.io.IOException
Streams the InputStream into the opened outputstream.

Parameters:
in -
Throws:
java.io.IOException

writeIntoFile

public FileHelper writeIntoFile(java.io.Reader in)
                         throws java.io.IOException
Streams the Reader into the opened outputstream.

Parameters:
in -
Throws:
java.io.IOException

writeIntoFile

public FileHelper writeIntoFile(char[] in)
                         throws java.io.IOException
Write's the char sequence into the opened outputstream.

Parameters:
in -
Throws:
java.io.IOException

writeIntoFile

public FileHelper writeIntoFile(byte[] in)
                         throws java.io.IOException
Write's the byte sequence into the opened outputstream.

Parameters:
in -
Throws:
java.io.IOException

writeIntoFile

public FileHelper writeIntoFile(java.lang.String in)
                         throws java.io.IOException
Write's the String into the opened outputstream.

Parameters:
in -
Throws:
java.io.IOException

encodeBase64Ziped

public static java.lang.String encodeBase64Ziped(java.io.InputStream is)
                                          throws java.io.IOException
Throws:
java.io.IOException

encodeBase64Ziped

public static java.lang.String encodeBase64Ziped(byte[] value)
                                          throws java.io.IOException
Throws:
java.io.IOException

decodeBase64Ziped

public static byte[] decodeBase64Ziped(java.lang.String value)
                                throws java.io.IOException
Throws:
java.io.IOException

copy

public static void copy(java.io.File source,
                        java.io.File destination)
                 throws java.io.IOException
Copy a file from source to destination

Parameters:
source - java.net.URL
destination - java.net.URL
Throws:
java.io.IOException

copy

public static void copy(java.net.URL source,
                        java.io.File destination)
                 throws java.io.IOException
Copy a file from source to destination

Parameters:
source - java.net.URL
destination - java.net.URL
Throws:
java.io.IOException

copy

public static void copy(java.net.URL source,
                        java.net.URL destination)
                 throws java.io.IOException
Copy a file from source to destination

Parameters:
source - java.net.URL
destination - java.net.URL
Throws:
java.io.IOException

deleteDir

public static void deleteDir(java.io.File file,
                             boolean deep)

deleteDir

public static void deleteDir(java.io.File[] file,
                             boolean deep)

mkdirs

public static boolean mkdirs(java.io.File file,
                             boolean includingLeaf)
Creates the directory named by this abstract pathname, including any necessary but nonexistent parent directories. Note that if this operation fails it may have succeeded in creating some of the necessary parent directories.

Returns:
true if and only if the directory was created, along with all necessary parent directories; false otherwise
Throws:
java.lang.SecurityException - If a security manager exists and its SecurityManager.checkWrite(java.lang.String) method does not permit the named directory and all necessary parent directories and to be created

getDirectory

public static java.io.File getDirectory(java.net.URL fileToOpen)

getDirectory

public static java.io.File getDirectory(java.io.File source)

tail

public static java.lang.String tail(java.lang.String fileName,
                                    int lineCount)

tail

public static void tail(java.lang.String fileName,
                        int lineCount,
                        java.io.PrintWriter writer,
                        java.lang.String escapeAs)

tail

public static void tail(java.lang.String fileName,
                        int lineCount,
                        int bufferSize,
                        java.io.Writer pw,
                        java.lang.String escapeAs)
                 throws java.io.IOException
Throws:
java.io.IOException