org.infoglue.cms.io
Class FileHelper

java.lang.Object
  extended by org.infoglue.cms.io.FileHelper

public class FileHelper
extends java.lang.Object


Constructor Summary
FileHelper()
           
 
Method Summary
static java.lang.String getFileAsString(java.io.File file)
          This method reads a file from the disk into a string.
static byte[] getFileBytes(java.io.File file)
          This method reads a file from the disk and converts it to an byte[].
static java.lang.String getStreamAsString(java.io.InputStream inputStream)
          This method reads a file from the disk into a string.
static java.lang.String readUTF8FromFile(java.io.File file)
          Writes the file to the hard disk.
static java.lang.String tail(java.io.File file, int numberOfLines)
          Reading the x last lines of a file
static void writeToFile(java.io.File file, byte[] data)
          This method writes a file with data from a byte[].
static void writeToFile(java.io.File file, java.lang.String text, boolean isAppend)
          Writes the file to the hard disk.
static void writeUTF8(java.io.File file, java.lang.String text, boolean isAppend)
           
static void writeUTF8ToFile(java.io.File file, java.lang.String text, boolean isAppend)
           
static void writeUTF8ToFileSpecial(java.io.File file, java.lang.String text, boolean isAppend)
          Writes the file to the hard disk.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FileHelper

public FileHelper()
Method Detail

writeToFile

public static void writeToFile(java.io.File file,
                               java.lang.String text,
                               boolean isAppend)
                        throws java.lang.Exception
Writes the file to the hard disk. If the file doesn't exist a new file is created.

Parameters:
text - The text you want to write to the file.
file - The file to save to
is_append - Dictates if the text should be appended to the existing file. If is_append == true; The text will be added to the existing file. If is_append == false; The text will overwrite the existing contents of the file.
Throws:
java.lang.Exception
Since:
2002-12-12

writeUTF8ToFileSpecial

public static void writeUTF8ToFileSpecial(java.io.File file,
                                          java.lang.String text,
                                          boolean isAppend)
                                   throws java.lang.Exception
Writes the file to the hard disk. If the file doesn't exist a new file is created.

Parameters:
text - The text you want to write to the file.
file - The file to save to
is_append - Dictates if the text should be appended to the existing file. If is_append == true; The text will be added to the existing file. If is_append == false; The text will overwrite the existing contents of the file.
Throws:
java.lang.Exception
Since:
2002-12-12

writeUTF8

public static void writeUTF8(java.io.File file,
                             java.lang.String text,
                             boolean isAppend)
                      throws java.lang.Exception
Throws:
java.lang.Exception

writeUTF8ToFile

public static void writeUTF8ToFile(java.io.File file,
                                   java.lang.String text,
                                   boolean isAppend)
                            throws java.lang.Exception
Throws:
java.lang.Exception

readUTF8FromFile

public static java.lang.String readUTF8FromFile(java.io.File file)
                                         throws java.lang.Exception
Writes the file to the hard disk. If the file doesn't exist a new file is created.

Parameters:
text - The text you want to write to the file.
file - The file to save to
is_append - Dictates if the text should be appended to the existing file. If is_append == true; The text will be added to the existing file. If is_append == false; The text will overwrite the existing contents of the file.
Throws:
java.lang.Exception
Since:
2002-12-12

getFileBytes

public static byte[] getFileBytes(java.io.File file)
                           throws java.lang.Exception
This method reads a file from the disk and converts it to an byte[].

Parameters:
file - The file read bytes from
Throws:
java.lang.Exception
Since:
2002-12-12

getFileAsString

public static java.lang.String getFileAsString(java.io.File file)
                                        throws java.lang.Exception
This method reads a file from the disk into a string.

Parameters:
file - The file reads from
Throws:
java.lang.Exception
Since:
2002-12-12

getStreamAsString

public static java.lang.String getStreamAsString(java.io.InputStream inputStream)
                                          throws java.lang.Exception
This method reads a file from the disk into a string.

Parameters:
file - The file reads from
Throws:
java.lang.Exception
Since:
2002-12-12

writeToFile

public static void writeToFile(java.io.File file,
                               byte[] data)
                        throws java.lang.Exception
This method writes a file with data from a byte[].

Parameters:
file - The file to save to
Throws:
java.lang.Exception
Since:
2002-12-12

tail

public static java.lang.String tail(java.io.File file,
                                    int numberOfLines)
                             throws java.lang.Exception
Reading the x last lines of a file

Throws:
java.lang.Exception


Copyright © 2005 InfoGlue.org All Rights Reserved.