apollo.util
Class IOUtil

java.lang.Object
  extended by apollo.util.IOUtil

public class IOUtil
extends java.lang.Object

I can't believe these basic IO utilities didn't already exist somewhere, but I didn't see them. Methods to read a text file, write a text file, and copy a text file. readFile and writeFile throw IOExceptions. copyFile returns true or false depending on whether it succeeded in copying the file. 4/2006: Moved getStreamFromUrl here (from GAMEAdapter) so that ChadoXMLAdapter can use it too.


Field Summary
protected static org.apache.log4j.Logger logger
           
 
Constructor Summary
IOUtil()
           
 
Method Summary
static boolean canWriteToDirectory(java.lang.String path)
          Check whether specified directory is writeable
static boolean copyFile(java.lang.String from, java.lang.String to)
           
static void errorDialog(java.lang.String msg)
          Put up a dialog box if we're not running in batch mode or in headless mode.
static java.lang.String expandSquiggle(java.lang.String name)
           
static java.lang.String findFile(java.lang.String name)
          Look in various sensible places for the file with a given name (which may be a full path, a relative path, or just a filename).
static java.lang.String findFile(java.lang.String name, boolean canCreate)
           
static java.lang.String getRootDir()
          Apollo root directory is defined by system property APOLLO_ROOT; if that's not defined, try .
static java.io.InputStream getStreamFromUrl(java.net.URL url, java.lang.String badUrlMessage)
           
static java.io.InputStream getStreamFromUrl(java.net.URL url, java.lang.String badUrlMessage, java.lang.String notFoundMessage)
          Makes InputStream from URL - throws DataAdapterException with badUrlMessage if URL is not found, or with notFoundMessage if stream is empty (i.e., requested region is not found).
static void informationDialog(java.lang.String msg)
          Display an information dialog box (if not running in headless mode or command line mode and outputs information to logger).
static boolean isMac()
           
static boolean isUnix()
           
static boolean isWebStart()
          Try to determine whether we're running as a webstart application
static boolean isWindows()
           
static java.lang.String readFile(java.lang.String fileName)
          Any IO errors will be thrown back to the caller to catch
static java.lang.String stripControlChars(java.lang.String s)
           
static void writeFile(java.lang.String fileName, java.lang.String text)
          Any IO errors will be thrown back to the caller to catch
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logger

protected static final org.apache.log4j.Logger logger
Constructor Detail

IOUtil

public IOUtil()
Method Detail

getRootDir

public static java.lang.String getRootDir()
Apollo root directory is defined by system property APOLLO_ROOT; if that's not defined, try . (see if there's a conf directory in .). Failing that, use ~/.apollo NOTE that this could be problematic if we're running in webstart mode and the user has just a few things in their config (e.g. FrameOrientation "horizontal") but not everything--we'll say "oh, cool, we found apollo.cfg,", and not realize that it's not really the whole thing and we need to unjar the default apollo.cfg. Maybe we need an "are we in webstart?" test.


readFile

public static java.lang.String readFile(java.lang.String fileName)
                                 throws java.io.IOException
Any IO errors will be thrown back to the caller to catch

Throws:
java.io.IOException

writeFile

public static void writeFile(java.lang.String fileName,
                             java.lang.String text)
                      throws java.io.IOException
Any IO errors will be thrown back to the caller to catch

Throws:
java.io.IOException

copyFile

public static boolean copyFile(java.lang.String from,
                               java.lang.String to)

stripControlChars

public static java.lang.String stripControlChars(java.lang.String s)

findFile

public static java.lang.String findFile(java.lang.String name)
Look in various sensible places for the file with a given name (which may be a full path, a relative path, or just a filename).


findFile

public static java.lang.String findFile(java.lang.String name,
                                        boolean canCreate)

expandSquiggle

public static java.lang.String expandSquiggle(java.lang.String name)

canWriteToDirectory

public static boolean canWriteToDirectory(java.lang.String path)
Check whether specified directory is writeable


isWindows

public static boolean isWindows()

isMac

public static boolean isMac()

isUnix

public static boolean isUnix()

isWebStart

public static boolean isWebStart()
Try to determine whether we're running as a webstart application


errorDialog

public static void errorDialog(java.lang.String msg)
Put up a dialog box if we're not running in batch mode or in headless mode. If we are, then just print the message to stdout.


informationDialog

public static void informationDialog(java.lang.String msg)
Display an information dialog box (if not running in headless mode or command line mode and outputs information to logger).

Parameters:
msg - - Message to be displayed

getStreamFromUrl

public static java.io.InputStream getStreamFromUrl(java.net.URL url,
                                                   java.lang.String badUrlMessage,
                                                   java.lang.String notFoundMessage)
                                            throws ApolloAdapterException
Makes InputStream from URL - throws DataAdapterException with badUrlMessage if URL is not found, or with notFoundMessage if stream is empty (i.e., requested region is not found).

Throws:
ApolloAdapterException

getStreamFromUrl

public static java.io.InputStream getStreamFromUrl(java.net.URL url,
                                                   java.lang.String badUrlMessage)
                                            throws ApolloAdapterException
Throws:
ApolloAdapterException