jklustor-overlap-0.0.2-20140619012940 (ChemAxon)


com.chemaxon.calculations.util
Class CmdlineUtils

Object
  extended by com.chemaxon.calculations.util.CmdlineUtils

public final class CmdlineUtils
extends Object

Command line related utilities.

Author:
Gabor Imre

Field Summary
static String UTF8ENCODING
          UTF-8 encoding String literal.
 
Method Summary
static InputStream inputStreamFromLocation(String location)
          Create InputStream from not nullable location.
static Optional<InputStream> inputStreamFromNullableLocation(String location)
          Create in input stream from nullable location.
static org.apache.commons.io.LineIterator lineIteratorFromLocation(String location)
          Create a LineIterator from a not nullable location.
static ObjectInputStream objectInputStreamFromLocation(String location)
          Create ObjectInputStream from a not nullable location.
static Optional<ObjectInputStream> objectInputStreamFromNullableLocation(String location)
          Create in object input stream from nullable location.
static ObjectOutputStream objectOutputStreamFromLocation(String location)
          ObjectOutputStream from a location.
static Optional<ObjectOutputStream> objectOutputStreamFromNullableLocation(String location)
          ObjectOutputStream from a nullable location.
static PrintStream printStreamFromLocation(String location)
          PrintStream from a location.
static Optional<PrintStream> printStreamFromNullableLocation(String location)
          PrintStream from a nullable location.
static String stringFromLocation(String location)
          Read the contents of a location into a String.
static Optional<String> stringFromNullableLocation(String location)
          Read the contents of a location when it is not null.
 
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

UTF8ENCODING

public static final String UTF8ENCODING
UTF-8 encoding String literal.

See Also:
Constant Field Values
Method Detail

inputStreamFromLocation

public static InputStream inputStreamFromLocation(String location)
                                           throws FileNotFoundException
Create InputStream from not nullable location.

Parameters:
location - File name or "-" for stdin.
Returns:
Input stream representing given location. Returned input stream should be closed after usage. If stdin requested it is wrapped in a CloseShieldInputStream
Throws:
FileNotFoundException - thrown by FileInputStream.FileInputStream(java.lang.String)

objectInputStreamFromLocation

public static ObjectInputStream objectInputStreamFromLocation(String location)
                                                       throws IOException
Create ObjectInputStream from a not nullable location.

Parameters:
location - File name or "-" for stdin
Returns:
ObjectInputStream to be used
Throws:
IOException - re-thrown

lineIteratorFromLocation

public static org.apache.commons.io.LineIterator lineIteratorFromLocation(String location)
                                                                   throws IOException
Create a LineIterator from a not nullable location.

Note that the returned instance must be closed by calling LineIterator.close() or LineIterator.closeQuietly(org.apache.commons.io.LineIterator), preferably in a finally block

Parameters:
location - File name or "-" for stdin
Returns:
LineIterator for the given location
Throws:
IOException - re-thrown

inputStreamFromNullableLocation

public static Optional<InputStream> inputStreamFromNullableLocation(String location)
                                                             throws FileNotFoundException
Create in input stream from nullable location.

The returned InputStream should be closed in a proper finally block by invoking its InputStream.close() method. If stdin used then a CloseShieldInputStream is returned which is safe to close.

Parameters:
location - File name or "-" for stdin
Returns:
Input stream representing given location
Throws:
FileNotFoundException - thrown by FileInputStream.FileInputStream(java.lang.String)

objectInputStreamFromNullableLocation

public static Optional<ObjectInputStream> objectInputStreamFromNullableLocation(String location)
                                                                         throws IOException
Create in object input stream from nullable location.

The returned Object should be closed in a proper finally block by invoking its ObjectInputStream.close() method. If stdin used then a CloseShieldInputStream is used which is safe to close.

Parameters:
location - File name or "-" for stdin
Returns:
ObjectInputStream representing given location
Throws:
IOException - re-thrown

printStreamFromLocation

public static PrintStream printStreamFromLocation(String location)
                                           throws FileNotFoundException
PrintStream from a location.

Parameters:
location - File name or "-" for stdout, "-2" for stderr. Location "/dev/null" is considered as a NullOutputStream. Note that NullOutputStream is available both in apache commons io and in Guava, however Guava version is marked with Beta, so apache version is used.
Returns:
UTF-8 encoded PrintStream for given location which is safe and should be closed explicitly
Throws:
FileNotFoundException - thrown by FileOutputStream.FileOutputStream(java.lang.String)

objectOutputStreamFromLocation

public static ObjectOutputStream objectOutputStreamFromLocation(String location)
                                                         throws IOException
ObjectOutputStream from a location.

Parameters:
location - File name or "-" for stdout, "-2" for stderr. Location "/dev/null" is considered as a NullOutputStream. Note that NullOutputStream is available both in apache commons io and in Guava, however Guava version is marked with Beta, so apache version is used.
Returns:
ObjectOutputStream for given location which is safe and should be closed explicitly
Throws:
IOException - thrown by underlying streams

stringFromLocation

public static String stringFromLocation(String location)
                                 throws IllegalArgumentException
Read the contents of a location into a String.

Parameters:
location - Location passed to inputStreamFromLocation(java.lang.String)
Returns:
Contents read by IOUtils.toString(java.io.InputStream, java.lang.String)
Throws:
IllegalArgumentException - When something goes wrong

printStreamFromNullableLocation

public static Optional<PrintStream> printStreamFromNullableLocation(String location)
                                                             throws FileNotFoundException
PrintStream from a nullable location.

Parameters:
location - File name or "-" for stdout, "-2" for stderr
Returns:
UTF-8 encoded PrintStream for given location which is safe and should be closed explicitly when not null given
Throws:
FileNotFoundException - thrown by FileOutputStream.FileOutputStream(java.lang.String)

objectOutputStreamFromNullableLocation

public static Optional<ObjectOutputStream> objectOutputStreamFromNullableLocation(String location)
                                                                           throws IOException
ObjectOutputStream from a nullable location.

Parameters:
location - File name or "-" for stdout, "-2" for stderr
Returns:
ObjectOutputStream for given location which is safe and should be closed explicitly when not null given
Throws:
IOException - re-thrown

stringFromNullableLocation

public static Optional<String> stringFromNullableLocation(String location)
Read the contents of a location when it is not null.

Parameters:
location - A location or null
Returns:
Contents

jklustor-overlap-0.0.2-20140619012940 (ChemAxon)