Terrier IR Platform
1.1.1

uk.ac.gla.terrier.utility
Class Files

java.lang.Object
  extended by uk.ac.gla.terrier.utility.Files

public class Files
extends java.lang.Object

Utililty class for opening readers/writers and input/output streams to files. Handles gzipped files on the fly, ie if a file ends in ".gz" or ".GZ", then it will be opened using a GZipInputStream/GZipOutputStream. All returned Streams, Readers, Writers etc are Buffered. If a charset encoding is not specified, then the system default is used.


Constructor Summary
Files()
           
 
Method Summary
static java.lang.Long copyFile(java.io.File srcFile, java.io.File destFile)
          Copy a file from srcFile to destFile.
static java.lang.Long copyFile(java.lang.String srcFilename, java.lang.String destFilename)
          Copy a file from srcFile to destFile.
static java.lang.Long createChecksum(java.io.File file)
          Returns the CRC checksum of denoted file
static java.io.BufferedReader openFileReader(java.io.File file)
          Opens a reader to the file called file.
static java.io.BufferedReader openFileReader(java.io.File file, java.lang.String charset)
          Opens a reader to the file called filename.
static java.io.BufferedReader openFileReader(java.lang.String filename)
          Opens a reader to the file called filename.
static java.io.BufferedReader openFileReader(java.lang.String filename, java.lang.String charset)
          Opens a reader to the file called filename.
static java.io.InputStream openFileStream(java.io.File file)
          Opens an InputStream to a file called file.
static java.io.InputStream openFileStream(java.lang.String filename)
          Opens an InputStream to a file called filename.
static java.io.OutputStream writeFileStream(java.io.File file)
          Opens an OutputStream to a file called file.
static java.io.OutputStream writeFileStream(java.lang.String filename)
          Opens an OutputStream to a file called filename.
static java.io.Writer writeFileWriter(java.io.File file)
          Opens an Writer to a file called file.
static java.io.Writer writeFileWriter(java.io.File file, java.lang.String charset)
          Opens an Writer to a file called file.
static java.io.Writer writeFileWriter(java.lang.String filename)
          Opens an Writer to a file called file.
static java.io.Writer writeFileWriter(java.lang.String filename, java.lang.String charset)
          Opens an Writer to a file called file.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Files

public Files()
Method Detail

openFileReader

public static java.io.BufferedReader openFileReader(java.io.File file)
                                             throws java.io.IOException
Opens a reader to the file called file. Provided for easy overriding for encoding support etc in child classes. Called from openNextFile().

Parameters:
file - File to open.
Returns:
BufferedReader of the file
Throws:
java.io.IOException

openFileReader

public static java.io.BufferedReader openFileReader(java.io.File file,
                                                    java.lang.String charset)
                                             throws java.io.IOException
Opens a reader to the file called filename. Provided for easy overriding for encoding support etc in child classes. Called from openNextFile().

Parameters:
file - File to open.
charset - Character set encoding of file. null for system default.
Returns:
BufferedReader of the file
Throws:
java.io.IOException

openFileReader

public static java.io.BufferedReader openFileReader(java.lang.String filename)
                                             throws java.io.IOException
Opens a reader to the file called filename. Provided for easy overriding for encoding support etc in child classes. Called from openNextFile().

Parameters:
filename - File to open.
Returns:
BufferedReader of the file
Throws:
java.io.IOException

openFileReader

public static java.io.BufferedReader openFileReader(java.lang.String filename,
                                                    java.lang.String charset)
                                             throws java.io.IOException
Opens a reader to the file called filename. Provided for easy overriding for encoding support etc in child classes. Called from openNextFile().

Parameters:
filename - File to open.
charset - Character set encoding of file. null for system default.
Returns:
BufferedReader of the file
Throws:
java.io.IOException

openFileStream

public static java.io.InputStream openFileStream(java.io.File file)
                                          throws java.io.IOException
Opens an InputStream to a file called file.

Parameters:
file - File to open.
Returns:
InputStream of the file
Throws:
java.io.IOException

openFileStream

public static java.io.InputStream openFileStream(java.lang.String filename)
                                          throws java.io.IOException
Opens an InputStream to a file called filename.

Parameters:
filename - File to open.
Returns:
InputStream of the file
Throws:
java.io.IOException

writeFileStream

public static java.io.OutputStream writeFileStream(java.io.File file)
                                            throws java.io.IOException
Opens an OutputStream to a file called file.

Parameters:
file - File to open.
Returns:
OutputStream of the file
Throws:
java.io.IOException

writeFileStream

public static java.io.OutputStream writeFileStream(java.lang.String filename)
                                            throws java.io.IOException
Opens an OutputStream to a file called filename.

Parameters:
filename - File to open.
Returns:
OutputStream of the file
Throws:
java.io.IOException

writeFileWriter

public static java.io.Writer writeFileWriter(java.io.File file)
                                      throws java.io.IOException
Opens an Writer to a file called file. System default encoding will be used.

Parameters:
file - File to open.
Returns:
Writer of the file
Throws:
java.io.IOException

writeFileWriter

public static java.io.Writer writeFileWriter(java.io.File file,
                                             java.lang.String charset)
                                      throws java.io.IOException
Opens an Writer to a file called file.

Parameters:
file - File to open.
charset - Character set encoding of file. null for system default.
Returns:
Writer of the file
Throws:
java.io.IOException

writeFileWriter

public static java.io.Writer writeFileWriter(java.lang.String filename)
                                      throws java.io.IOException
Opens an Writer to a file called file. System default encoding will be used.

Parameters:
filename - File to open.
Returns:
Writer of the file
Throws:
java.io.IOException

writeFileWriter

public static java.io.Writer writeFileWriter(java.lang.String filename,
                                             java.lang.String charset)
                                      throws java.io.IOException
Opens an Writer to a file called file.

Parameters:
filename - File to open.
charset - Character set encoding of file. null for system default.
Returns:
Writer of the file
Throws:
java.io.IOException

copyFile

public static java.lang.Long copyFile(java.lang.String srcFilename,
                                      java.lang.String destFilename)
                               throws java.io.IOException
Copy a file from srcFile to destFile.

Returns:
null if OK
Throws:
java.io.IOException - if there was a problem copying

copyFile

public static java.lang.Long copyFile(java.io.File srcFile,
                                      java.io.File destFile)
                               throws java.io.IOException
Copy a file from srcFile to destFile.

Returns:
null if OK
Throws:
java.io.IOException - if there was a problem copying

createChecksum

public static java.lang.Long createChecksum(java.io.File file)
                                     throws java.io.IOException
Returns the CRC checksum of denoted file

Throws:
java.io.IOException

Terrier IR Platform
1.1.1

Terrier Information Retrieval Platform 1.1.1. Copyright 2004-2007 University of Glasgow