net.sourceforge.jaulp.file.read
Class ReadFileUtils

java.lang.Object
  extended by net.sourceforge.jaulp.file.read.ReadFileUtils

public class ReadFileUtils
extends java.lang.Object

The Class ReadFileUtils helps you reading files.

Version:
1.0
Author:
Asterios Raptis

Constructor Summary
ReadFileUtils()
           
 
Method Summary
static byte[] getFilecontentAsByteArray(java.io.File tmpFile)
          Get a byte array from the given file.
static java.io.InputStream getInputStream(java.io.File file)
          Gets the input stream from a File object.
static java.io.InputStream getInputStream(java.io.File file, boolean createFile)
          Gets the input stream from a File object.
static java.io.Reader getReader(java.io.File inputFile)
          Gets a Reader from the given file object.
static java.io.Reader getReader(java.io.File inputFile, java.lang.String encoding, boolean createFile)
          Gets a Reader from the given file object.
static java.lang.String inputStream2String(java.io.InputStream inputStream)
          The Method inputStream2String() reads the data from the InputStream into a String.
static java.io.Reader openFileReader(java.lang.String fileName)
          The Method openFileReader() opens a BufferedReader from the given file.
static java.lang.String reader2String(java.io.Reader reader)
          The Method reader2String() reads the data from the Reader into a String.
static byte[] readFileToBytearray(java.io.File file)
          Get a byte array from the given file.
static java.lang.String readFromFile(java.io.File file)
          The Method readFromFile() reads the filecontent to a String.
static java.lang.String readHeadLine(java.lang.String inputFile)
          The Method readHeadLine() opens the File and reads the first line from the file.
static java.util.List<java.lang.String> readLinesInList(java.io.File input)
          Reads every line from the File and puts them to the List.
static java.util.Properties readPropertiesFromFile(java.lang.String filename)
          The Method readFromFile(String) reads from the properties-file all Properties and saves them into a Properties-Object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ReadFileUtils

public ReadFileUtils()
Method Detail

getFilecontentAsByteArray

public static byte[] getFilecontentAsByteArray(java.io.File tmpFile)
Get a byte array from the given file.

Parameters:
tmpFile - The file.
Returns:
Returns a byte array or null.

getInputStream

public static java.io.InputStream getInputStream(java.io.File file)
                                          throws java.io.IOException
Gets the input stream from a File object.

Parameters:
file - the file.
Returns:
the input stream.
Throws:
java.io.IOException - Signals that an I/O exception has occurred.

getInputStream

public static java.io.InputStream getInputStream(java.io.File file,
                                                 boolean createFile)
                                          throws java.io.IOException
Gets the input stream from a File object.

Parameters:
file - the file
createFile - If true and the file does not exist it will be create a new file.
Returns:
the input stream
Throws:
FileDoesNotExistException - the file does not exist exception
java.io.IOException - Signals that an I/O exception has occurred.

getReader

public static java.io.Reader getReader(java.io.File inputFile)
                                throws java.io.IOException
Gets a Reader from the given file object.

Parameters:
inputFile - the input file.
Returns:
the reader.
Throws:
java.io.IOException - Signals that an I/O exception has occurred.

getReader

public static java.io.Reader getReader(java.io.File inputFile,
                                       java.lang.String encoding,
                                       boolean createFile)
                                throws java.io.IOException
Gets a Reader from the given file object.

Parameters:
inputFile - the input file
encoding - The encoding from the file.
createFile - If true and the file does not exist it will be create a new file.
Returns:
the reader
Throws:
java.io.IOException - Signals that an I/O exception has occurred.

inputStream2String

public static java.lang.String inputStream2String(java.io.InputStream inputStream)
The Method inputStream2String() reads the data from the InputStream into a String.

Parameters:
inputStream - The InputStream from where we read.
Returns:
The String that we read from the InputStream.

openFileReader

public static java.io.Reader openFileReader(java.lang.String fileName)
                                     throws java.io.IOException
The Method openFileReader() opens a BufferedReader from the given file.

Parameters:
fileName - The file from where to read.
Returns:
The opened BufferedReader from the specified file.
Throws:
java.io.IOException - Signals that an I/O exception has occurred.

reader2String

public static java.lang.String reader2String(java.io.Reader reader)
The Method reader2String() reads the data from the Reader into a String.

Parameters:
reader - The Reader from where we read.
Returns:
The String that we read from the Reader.

readFileToBytearray

public static byte[] readFileToBytearray(java.io.File file)
Get a byte array from the given file.

Parameters:
file - The file.
Returns:
Returns a byte array or null.

readFromFile

public static java.lang.String readFromFile(java.io.File file)
The Method readFromFile() reads the filecontent to a String.

Parameters:
file - The File to read to a String.
Returns:
The String from the File.

readHeadLine

public static java.lang.String readHeadLine(java.lang.String inputFile)
The Method readHeadLine() opens the File and reads the first line from the file.

Parameters:
inputFile - The Path to the File and name from the file from where we read.
Returns:
The first line from the file.

readLinesInList

public static java.util.List<java.lang.String> readLinesInList(java.io.File input)
                                                        throws java.io.IOException
Reads every line from the File and puts them to the List.

Parameters:
input - The File from where the input comes.
Returns:
The List with all lines from the file.
Throws:
java.io.IOException - When a io-problem occurs.

readPropertiesFromFile

public static java.util.Properties readPropertiesFromFile(java.lang.String filename)
The Method readFromFile(String) reads from the properties-file all Properties and saves them into a Properties-Object.

Parameters:
filename - The Filename from the Properties-file.
Returns:
The Properties or null if an error occurs.


Copyright © 2010. All Rights Reserved.