prefuse.util.io
Class IOLib

java.lang.Object
  extended by prefuse.util.io.IOLib

public class IOLib
extends java.lang.Object

Library routines for input/output tasks.

Author:
jeffrey heer

Method Summary
static java.lang.String getExtension(java.io.File f)
          Returns the extension for a file or null if there is none
static java.lang.String getExtension(java.lang.String filename)
          Returns the extension for a file or null if there is none
static Graph getGraphFile(java.awt.Component c)
          Present a file chooser dialog for loading a Graph or Tree data set.
static Table getTableFile(java.awt.Component c)
          Present a file chooser dialog for loading a Table data set.
static boolean isGZipFile(java.lang.String file)
          Indicates if the given file ends with a file extension of ".gz" or ".Z", indicating a GZip file.
static boolean isUrlString(java.lang.String s)
          Indicates if a given String is a URL string.
static boolean isZipFile(java.lang.String file)
          Indicates if the given file ends with a file extension of ".zip", indicating a Zip file.
static ByteArrayList readAsBytes(java.io.InputStream is)
          Reads an input stream into a list of byte values.
static java.lang.String readAsString(java.io.InputStream is)
          Reads an input stream into a single String result.
static java.lang.String readAsString(java.lang.String location)
          Reads data pulled from the given location string into a single String result.
static java.io.InputStream streamFromString(java.lang.String location)
          Get an input string corresponding to the given location string.
static java.net.URL urlFromString(java.lang.String location)
          From a string description, attempt to generate a URL object.
static java.net.URL urlFromString(java.lang.String location, java.lang.Class referrer, boolean includeFileSystem)
          From a string description, attempt to generate a URL object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

isUrlString

public static boolean isUrlString(java.lang.String s)
Indicates if a given String is a URL string. Checks to see if the string begins with the "http:/", "ftp:/", or "file:/" protocol strings.

Parameters:
s - the string to check
Returns:
true if a url string matching the listed protocols, false otherwise

urlFromString

public static java.net.URL urlFromString(java.lang.String location)
From a string description, attempt to generate a URL object. The string may point to an Internet location (e.g., http:// or ftp:// URL), a resource on the class path (resulting in a resource URL that points into the current classpath), or a file on the local filesystem (resulting in a file:// URL). The String will be checked in that order in an attempt to resolve it to a valid URL.

Parameters:
location - the location string for which to get a URL object
Returns:
a URL object, or null if the location string could not be resolved

urlFromString

public static java.net.URL urlFromString(java.lang.String location,
                                         java.lang.Class referrer,
                                         boolean includeFileSystem)
From a string description, attempt to generate a URL object. The string may point to an Internet location (e.g., http:// or ftp:// URL), a resource on the class path (resulting in a resource URL that points into the current classpath), or, if the includeFileSystem flag is true, a file on the local filesystem (resulting in a file:// URL). The String will be checked in that order in an attempt to resolve it to a valid URL.

Parameters:
location - the location string for which to get a URL object
referrer - the class to check for classpath resource items, the location string will be resolved against the package/folder containing this class
includeFileSystem - indicates if the file system should be included in the search to resolve the location String
Returns:
a URL object, or null if the location string could not be resolved

streamFromString

public static java.io.InputStream streamFromString(java.lang.String location)
                                            throws java.io.IOException
Get an input string corresponding to the given location string. The string will first be resolved to a URL and an input stream will be requested from the URL connection. If this fails, the location will be resolved against the file system. Also, if a gzip file is found, the input stream will also be wrapped by a GZipInputStream. If the location string can not be resolved, a null value is returned

Parameters:
location - the location string
Returns:
an InputStream for the resolved location string
Throws:
java.io.IOException - if an input/ouput error occurs

getExtension

public static java.lang.String getExtension(java.io.File f)
Returns the extension for a file or null if there is none

Parameters:
f - the input file
Returns:
the file extension, or null if none

isGZipFile

public static boolean isGZipFile(java.lang.String file)
Indicates if the given file ends with a file extension of ".gz" or ".Z", indicating a GZip file.

Parameters:
file - a String of the filename or URL of the file
Returns:
true if the extension is ".gz" or ".Z", false otherwise

isZipFile

public static boolean isZipFile(java.lang.String file)
Indicates if the given file ends with a file extension of ".zip", indicating a Zip file.

Parameters:
file - a String of the filename or URL of the file
Returns:
true if the extension is ".zip", false otherwise

getExtension

public static java.lang.String getExtension(java.lang.String filename)
Returns the extension for a file or null if there is none

Parameters:
filename - the input filename
Returns:
the file extension, or null if none

readAsBytes

public static ByteArrayList readAsBytes(java.io.InputStream is)
                                 throws java.io.IOException
Reads an input stream into a list of byte values.

Parameters:
is - the input stream to read
Returns:
a ByteArrayList containing the contents of the input stream
Throws:
java.io.IOException - if an input/ouput error occurs

readAsString

public static java.lang.String readAsString(java.io.InputStream is)
                                     throws java.io.IOException
Reads an input stream into a single String result.

Parameters:
is - the input stream to read
Returns:
a String containing the contents of the input stream
Throws:
java.io.IOException - if an input/ouput error occurs

readAsString

public static java.lang.String readAsString(java.lang.String location)
                                     throws java.io.IOException
Reads data pulled from the given location string into a single String result. The method attempts to retrieve an InputStream using the streamFromString(String) method, then read the input stream into a String result.

Parameters:
location - the location String
Returns:
a String with the requested data
Throws:
java.io.IOException - if an input/ouput error occurs
See Also:
streamFromString(String)

getTableFile

public static Table getTableFile(java.awt.Component c)
Present a file chooser dialog for loading a Table data set.

Parameters:
c - user interface component from which the request is being made
Returns:
a newly loaded Table, or null if not found or action canceled

getGraphFile

public static Graph getGraphFile(java.awt.Component c)
Present a file chooser dialog for loading a Graph or Tree data set.

Parameters:
c - user interface component from which the request is being made
Returns:
a newly loaded Graph, or null if not found or action canceled


Copyright © 2007 Regents of the University of California