Class CmdlineUtils

java.lang.Object
com.chemaxon.calculations.util.CmdlineUtils

@PublicAPI @Deprecated(forRemoval=true) @SubjectToRemoval(date=JAN_01_2025) public final class CmdlineUtils extends Object
Deprecated, for removal: This API element is subject to removal in a future version.
Will be removed without replacement.
Command line related utilities.

IO is accessed through a CmdlineContext acquired with ServiceLoader. A single service registration is expected.

  • Method Details

    • autoGzip

      public static InputStream autoGzip(InputStream in) throws IOException
      Deprecated, for removal: This API element is subject to removal in a future version.
      Detect gzipped InputStream.

      Checks GZIPInputStream.GZIP_MAGIC and wraps input when match found. Further validity check is not done. See http://stackoverflow.com/questions/1080381/gzipinputstream-reading-line-by-line.

      Parameters:
      in - Input
      Returns:
      Input wrapped in GZIPInputStream when GZIPInputStream.GZIP_MAGIC match, otherwise input, possibly wrapped in a BufferedInputStream.
      Throws:
      IOException - Propagated
    • getOut

      public static PrintStream getOut()
      Deprecated, for removal: This API element is subject to removal in a future version.
      Get stdout to use.
      Returns:
      StdOut specified by the default command line context
    • getErr

      public static PrintStream getErr()
      Deprecated, for removal: This API element is subject to removal in a future version.
      Get stderr to use.
      Returns:
      StdErr specified by the default command line context
    • getIn

      public static InputStream getIn()
      Deprecated, for removal: This API element is subject to removal in a future version.
      Get stdin to use.
      Returns:
      StdIn specified by the default command line context
    • isFileExists

      public static boolean isFileExists(String name)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Check if a file exists.
      Parameters:
      name - Name to delegate
    • openUrlStream

      public static InputStream openUrlStream(String spec) throws IOException
      Deprecated, for removal: This API element is subject to removal in a future version.
      Open an URL connection.
      Parameters:
      spec - URL spec
      Returns:
      Stream
      Throws:
      IOException - Propagated
    • exit

      public static void exit(int status)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Terminate execution with given status code.

      By default, implementation calls System.exit(int). Test time implementations might decide to change this behavior.

      Parameters:
      status - Status code; by convention nonzero status code indicates abnormal termination
    • inputStreamFromLocation

      public static InputStream inputStreamFromLocation(String location) throws FileNotFoundException
      Deprecated, for removal: This API element is subject to removal in a future version.
      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.
      Throws:
      FileNotFoundException - thrown by FileInputStream(java.lang.String)
    • inputStreamFromLocation

      public static InputStream inputStreamFromLocation(String location, boolean autoGzip) throws IOException
      Deprecated, for removal: This API element is subject to removal in a future version.
      Create InputStream from not nullable location.
      Parameters:
      location - File name or "-" for stdin.
      autoGzip - Wrap returned stream through autoGzip(java.io.InputStream).
      Returns:
      Input stream representing given location. Returned input stream should be closed after usage.
      Throws:
      IOException - propagated
    • objectInputStreamFromLocation

      public static ObjectInputStream objectInputStreamFromLocation(String location, boolean autoGzip) throws IOException
      Deprecated, for removal: This API element is subject to removal in a future version.
      Create ObjectInputStream from a not nullable location.
      Parameters:
      location - File name or "-" for stdin
      autoGzip - Wrap returned stream through autoGzip(java.io.InputStream).
      Returns:
      ObjectInputStream to be used
      Throws:
      IOException - re-thrown
    • objectInputStreamFromLocation

      public static ObjectInputStream objectInputStreamFromLocation(String location) throws IOException
      Deprecated, for removal: This API element is subject to removal in a future version.
      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 CloseableLineIterator lineIteratorFromLocation(String location, boolean autoGzip) throws IOException
      Deprecated, for removal: This API element is subject to removal in a future version.
      Create an Iterator that can be closed from a not nullable location.

      Note that the returned instance must be closed by calling AutoCloseable.close().

      Parameters:
      location - File name or "-" for stdin
      autoGzip - Wrap returned stream through autoGzip(java.io.InputStream).
      Returns:
      Iterator for the given location
      Throws:
      IOException - re-thrown
    • lineIteratorFromLocation

      public static CloseableLineIterator lineIteratorFromLocation(String location) throws IOException
      Deprecated, for removal: This API element is subject to removal in a future version.
      Create an Iterator that can be closed from a not nullable location.

      Note that the returned instance must be closed by calling AutoCloseable.close().

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

      public static Optional<InputStream> inputStreamFromNullableLocation(String location, boolean autoGzip) throws IOException
      Deprecated, for removal: This API element is subject to removal in a future version.
      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
      autoGzip - Wrap returned stream through autoGzip(java.io.InputStream).
      Returns:
      Input stream representing given location
      Throws:
      IOException - thrown by FileInputStream(java.lang.String) or by autoGzip(java.io.InputStream).
    • inputStreamFromNullableLocation

      public static Optional<InputStream> inputStreamFromNullableLocation(String location) throws IOException
      Deprecated, for removal: This API element is subject to removal in a future version.
      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:
      IOException - thrown by FileInputStream(java.lang.String) or by autoGzip(java.io.InputStream).
    • objectInputStreamFromNullableLocation

      public static Optional<ObjectInputStream> objectInputStreamFromNullableLocation(String location) throws IOException
      Deprecated, for removal: This API element is subject to removal in a future version.
      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
    • outputStreamFromLocation

      public static OutputStream outputStreamFromLocation(String location) throws FileNotFoundException
      Deprecated, for removal: This API element is subject to removal in a future version.
      OutputStream from a location.
      Parameters:
      location - File name or "-" for stdout, "-2" for stderr. Location "/dev/null" is considered as a OutputStream.nullOutputStream().
      Returns:
      OutputStream for given location which is safe and should be closed explicitly
      Throws:
      FileNotFoundException - thrown by FileOutputStream(java.lang.String)
    • printStreamFromLocation

      public static PrintStream printStreamFromLocation(String location) throws FileNotFoundException
      Deprecated, for removal: This API element is subject to removal in a future version.
      PrintStream from a location.
      Parameters:
      location - File name or "-" for stdout, "-2" for stderr. Location "/dev/null" is considered as a OutputStream.nullOutputStream().
      Returns:
      UTF-8 encoded PrintStream for given location which is safe and should be closed explicitly
      Throws:
      FileNotFoundException - thrown by FileOutputStream(java.lang.String)
    • objectOutputStreamFromLocation

      public static ObjectOutputStream objectOutputStreamFromLocation(String location) throws IOException
      Deprecated, for removal: This API element is subject to removal in a future version.
      ObjectOutputStream from a location.
      Parameters:
      location - File name or "-" for stdout, "-2" for stderr. Location "/dev/null" is considered as a OutputStream.nullOutputStream().
      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, boolean autoGzip) throws IllegalArgumentException
      Deprecated, for removal: This API element is subject to removal in a future version.
      Read the contents of a location into a String.
      Parameters:
      location - Location passed to inputStreamFromLocation(java.lang.String)
      autoGzip - Wrap returned stream through autoGzip(java.io.InputStream).
      Returns:
      Contents read by IOUtils#toString(java.io.InputStream, java.lang.String)
      Throws:
      IllegalArgumentException - When something goes wrong
    • stringFromLocation

      public static String stringFromLocation(String location) throws IllegalArgumentException
      Deprecated, for removal: This API element is subject to removal in a future version.
      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
      Deprecated, for removal: This API element is subject to removal in a future version.
      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(java.lang.String)
    • objectOutputStreamFromNullableLocation

      public static Optional<ObjectOutputStream> objectOutputStreamFromNullableLocation(String location) throws IOException
      Deprecated, for removal: This API element is subject to removal in a future version.
      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, boolean autoGzip)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Read the contents of a location when it is not null.
      Parameters:
      location - A location or null
      autoGzip - Wrap returned stream through autoGzip(java.io.InputStream).
      Returns:
      Contents
    • stringFromNullableLocation

      public static Optional<String> stringFromNullableLocation(String location)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Read the contents of a location when it is not null.
      Parameters:
      location - A location or null
      Returns:
      Contents