org.semwebcentral.sweetrules.util
Class SweetFileIO

java.lang.Object
  extended byorg.semwebcentral.sweetrules.util.SweetFileIO

public class SweetFileIO
extends java.lang.Object


Utility for dealing with files

Modified on: Aug 25, 2004, 2:05:22 PM

Author:
Shashidhara K Ganjugunte, Dr. Benjamin Grosof, Dr. Said Tabet, Chitravanu Neogy

Field Summary
private static Logger logger
          The logger object for this class
 
Constructor Summary
SweetFileIO()
           
 
Method Summary
static java.io.File createTempFileFromURL(java.lang.String urlString, java.lang.String filePattern, java.lang.String fileExtension, boolean deleteOnExit)
          Creates a temporary file based on contents of the specified URL
static java.io.File createTempFileWithContents(java.lang.String fileContents, java.lang.String filePattern, java.lang.String fileExtension, boolean deleteOnExit)
          Creates a temporary file based on the contents specified
static java.lang.String readStringFromFile(java.lang.String fileName)
          Reads the contents of a file and returns them as a string
static java.lang.String readStringFromInputStream(java.io.InputStream inputStream)
          Reads the contents of an inputStream and returns them as a string
static java.lang.String readStringFromURL(java.lang.String urlString)
          Utility function to read a URL (part of Jar file) and return its contents
static void writeStringToFile(java.io.File file, java.lang.String data)
          Writes the given string to a file, with File parameter
static void writeStringToFile(java.lang.String fileName, java.lang.String data)
          Writes the given string to a file
private static void writeStringToFile(java.io.Writer writer, java.lang.String data)
          The method which does the actual writing, given a writer
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logger

private static Logger logger
The logger object for this class

Constructor Detail

SweetFileIO

public SweetFileIO()
Method Detail

readStringFromFile

public static java.lang.String readStringFromFile(java.lang.String fileName)
                                           throws java.io.IOException
Reads the contents of a file and returns them as a string

Parameters:
fileName - The name of the file to read
Returns:
The contents of the file read
Throws:
java.io.IOException

readStringFromURL

public static java.lang.String readStringFromURL(java.lang.String urlString)
                                          throws java.io.IOException
Utility function to read a URL (part of Jar file) and return its contents

Parameters:
urlString - The url of the file
Returns:
contents of the file
Throws:
java.io.IOException - if an error occurs

readStringFromInputStream

public static java.lang.String readStringFromInputStream(java.io.InputStream inputStream)
                                                  throws java.io.IOException
Reads the contents of an inputStream and returns them as a string

Parameters:
inputStream - The input stream to read from
Returns:
The contents of the file read
Throws:
java.io.IOException

writeStringToFile

public static void writeStringToFile(java.lang.String fileName,
                                     java.lang.String data)
                              throws java.io.IOException
Writes the given string to a file

Parameters:
fileName - The name of the file to be written to
data - The string data to be written to the file
Throws:
java.io.IOException - if an error occurs

writeStringToFile

public static void writeStringToFile(java.io.File file,
                                     java.lang.String data)
                              throws java.io.IOException
Writes the given string to a file, with File parameter

Parameters:
file - The File object to be written to
data - The string data to be written to the file
Throws:
java.io.IOException - if an error occurs

writeStringToFile

private static void writeStringToFile(java.io.Writer writer,
                                      java.lang.String data)
                               throws java.io.IOException
The method which does the actual writing, given a writer

Parameters:
writer - The writer object to write the data to
data - The string data to be written to the file
Throws:
java.io.IOException - if an error occurs

createTempFileFromURL

public static java.io.File createTempFileFromURL(java.lang.String urlString,
                                                 java.lang.String filePattern,
                                                 java.lang.String fileExtension,
                                                 boolean deleteOnExit)
                                          throws java.io.IOException
Creates a temporary file based on contents of the specified URL

Parameters:
urlString - The URL to read from
filePattern - The pattern of the file to be passed to createTempFile API
fileExtension - The extension of the file to be passed to createTempFile API
deleteOnExit - If true this means the deleteOnExit option will be set for the temp file otherwise it will not be set
Returns:
The file handle of the temporary file
Throws:
java.io.IOException - If an error occurs

createTempFileWithContents

public static java.io.File createTempFileWithContents(java.lang.String fileContents,
                                                      java.lang.String filePattern,
                                                      java.lang.String fileExtension,
                                                      boolean deleteOnExit)
                                               throws java.io.IOException
Creates a temporary file based on the contents specified

Parameters:
fileContents - The contents of the temporary file (to be written)
filePattern - The pattern of the file to be passed to createTempFile API
fileExtension - The extension of the file to be passed to createTempFile API
deleteOnExit - If true this means the deleteOnExit option will be set for the temp file otherwise it will not be set
Returns:
The file handle of the temporary file
Throws:
java.io.IOException - If an error occurs