gov.llnl.ontology.util
Class StreamUtil

java.lang.Object
  extended by gov.llnl.ontology.util.StreamUtil

public class StreamUtil
extends Object

This collects a set of commonly used methods accessing data streams and files in and outside of running jars.

Author:
Keith Stevens

Constructor Summary
StreamUtil()
           
 
Method Summary
static File fileFromJar(Class c, String filePath)
          Returns a File object associated with filePath located within the current running jar that has loaded Class c.
static InputStream fromJar(Class c, String filePath)
          Returns an InputStream corresponding to the the file denoted by filePath.
static InputStream fromPath(String filePath)
          Returns a InputStream corresponding to the absolute path name denoted by filePath.
static DataInputStream gzipInputStream(InputStream in)
          Returns a DataInputStream for reading object data from a gzipped InputStream.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StreamUtil

public StreamUtil()
Method Detail

fromJar

public static InputStream fromJar(Class c,
                                  String filePath)
Returns an InputStream corresponding to the the file denoted by filePath. It will be read from the current set of class resources accessible by the given running class's classpath. This classpath has access to not only local files via an absolute path, but also files embedded within a jar.

Parameters:
c - The current Class that requires a resource
filePath - The name of the file which should be read
Returns:
A InputStream for data in filePath

fromPath

public static InputStream fromPath(String filePath)
Returns a InputStream corresponding to the absolute path name denoted by filePath. This will not access any files within the currently running jar or class path.

Parameters:
filePath - The name of the file which should be read
Returns:
A InputStream for data in filePath

fileFromJar

public static File fileFromJar(Class c,
                               String filePath)
Returns a File object associated with filePath located within the current running jar that has loaded Class c. The returned File cannot be read directly but my contain valuable meta data.

Parameters:
c - The current Class that requires a resource
filePath - The name of the file which should be opened
Returns:
A File for data in filePath

gzipInputStream

public static DataInputStream gzipInputStream(InputStream in)
Returns a DataInputStream for reading object data from a gzipped InputStream.

Parameters:
in - An existing InputStream whose data is in the gzipped format
Returns:
A DataInputStream for reading data from the gzipped stream


Copyright © 2010-2011. All Rights Reserved.