chemaxon.formats
Class MolConverter

java.lang.Object
  extended by chemaxon.formats.MolConverter

public class MolConverter
extends java.lang.Object

Converts between molecule file formats. See supported formats and their import and/or export options on the File Formats in Marvin page. By default, in case of machines with multiple processors processing is concurrent, otherwise single-threaded.

Examples:

Version:
5.3, 07/07/2009
Author:
Peter Csizmadia, Szilveszter Juhos

Nested Class Summary
static class MolConverter.Builder
          MolConverter builder.
static class MolConverter.Options
          Deprecated. as of Marvin 5.2.3, use MolConverter.Builder instead.
 
Constructor Summary
MolConverter(java.io.InputStream in, java.io.OutputStream out, java.lang.String fmtopts, boolean useSysEOL)
          Creates a MolConverter object.
MolConverter(java.io.InputStream in, java.lang.String ofname, java.lang.String fmtopts, boolean useSysEOL)
          Use this constructor if you do not need output buffering but want to determine output file positions.
MolConverter(java.util.List<java.lang.Object> inFiles, java.util.List<java.lang.String> inOptions, java.io.OutputStream out, java.lang.String fmtopts, boolean useSysEOL)
          Deprecated. as of Marvin 5.2.3, replaced by MolConverter(Builder)
MolConverter(java.util.List<java.lang.Object> inFiles, java.util.List<java.lang.String> inOptions, java.io.OutputStream out, java.lang.String fmtopts, boolean useSysEOL, java.lang.String[] incFields)
          Deprecated. as of Marvin 5.2.3, replaced by MolConverter(Builder)
MolConverter(java.util.List<java.lang.Object> inFiles, java.util.List<java.lang.String> inOptions, java.io.OutputStream out, java.lang.String fmtopts, boolean useSysEOL, java.lang.String[] incFields, java.lang.String enc)
          Deprecated. as of Marvin 5.2.3, replaced by MolConverter(Builder)
MolConverter(java.util.List<java.lang.Object> inFiles, java.util.List<java.lang.String> inOptions, java.lang.String ofname, java.lang.String fmtopts, boolean useSysEOL)
          Deprecated. as of Marvin 5.2.3, replaced by MolConverter(Builder)
MolConverter(java.util.List<java.lang.Object> inFiles, java.io.OutputStream out, java.lang.String fmtopts, boolean useSysEOL)
          Deprecated. as of Marvin 5.2.3, replaced by MolConverter(Builder)
MolConverter(java.util.List<java.lang.Object> inFiles, java.lang.String ofname, java.lang.String fmtopts, boolean useSysEOL)
          Deprecated. as of Marvin 5.2.3, replaced by MolConverter(Builder)
MolConverter(MolConverter.Builder mcbld)
          Creates a MolConverter object.
MolConverter(MolConverter.Options opts)
          Deprecated. as of Marvin 5.2.3, use MolConverter.Builder.build() instead.
 
Method Summary
 void close()
          Closes the exporter and the output stream.
 void close(int opts)
          Closes the exporter.
 boolean convert()
          Convert the next molecule.
static MolConverter createMolConverter(java.io.InputStream instream, java.io.OutputStream outstream, java.lang.String[] args, int[] verbosityLevel)
          Creates a MolConverter instance with the attributes specified in the parameters.
static void main(java.lang.String[] args)
          Main method.
static void mainWithoutExit(java.lang.String[] args)
          Same as main(), but never calls System.exit().
 long otell()
          Get the current file position.
 void setIgnoreError(boolean ignoreError)
          Sets the 'ignoreError' option.
 void setThreadCount(int threadCount)
          Sets the number of threads for concurrent processing.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MolConverter

public MolConverter(MolConverter.Builder mcbld)
             throws MolFormatException,
                    MolExportException,
                    java.io.IOException,
                    java.lang.IllegalArgumentException
Creates a MolConverter object.

Parameters:
mcbld - the builder
Throws:
MolFormatException - If the molecule file is in a format that cannot be read
MolExportException - If the molecule cannot be exported in the specified format
java.io.IOException - If I/O error occured when determining the file format.
java.lang.IllegalArgumentException - Invalid format string (fmt).
Since:
Marvin 5.2.3, 05/28/2009

MolConverter

public MolConverter(java.io.InputStream in,
                    java.io.OutputStream out,
                    java.lang.String fmtopts,
                    boolean useSysEOL)
             throws MolFormatException,
                    MolExportException,
                    java.io.IOException,
                    java.lang.IllegalArgumentException
Creates a MolConverter object.

Parameters:
in - the input molecule stream to convert
out - the output stream
fmtopts - output file format with or without options
useSysEOL - write OS dependent line.separators instead of '\n'
Throws:
MolFormatException - If the molecule file is in a format that cannot be read
MolExportException - If the molecule cannot be exported in the specified format
java.io.IOException - If I/O error occured when determining the file format.
java.lang.IllegalArgumentException - Invalid format string (fmt).

MolConverter

public MolConverter(java.io.InputStream in,
                    java.lang.String ofname,
                    java.lang.String fmtopts,
                    boolean useSysEOL)
             throws MolFormatException,
                    MolExportException,
                    java.io.IOException,
                    java.lang.IllegalArgumentException
Use this constructor if you do not need output buffering but want to determine output file positions.

Parameters:
in - the input molecule stream to convert
ofname - the output file name
fmtopts - output file format with or without options
useSysEOL - write OS dependent line.separators instead of '\n'
Throws:
MolFormatException - If the molecule file is in a format that cannot be read
MolExportException - If the molecule cannot be exported in the specified format
java.io.IOException - If I/O error occured when determining the file format.
java.lang.IllegalArgumentException - Invalid format string (fmt).
See Also:
otell(), close()

MolConverter

@Deprecated
public MolConverter(java.util.List<java.lang.Object> inFiles,
                               java.io.OutputStream out,
                               java.lang.String fmtopts,
                               boolean useSysEOL)
             throws MolFormatException,
                    MolExportException,
                    java.io.IOException
Deprecated. as of Marvin 5.2.3, replaced by MolConverter(Builder)

Parameters:
inFiles - not used in this method since it is unsupported now.
out - not used in this method since it is unsupported now.
fmtopts - not used in this method since it is unsupported now.
useSysEOL - not used in this method since it is unsupported now.
Throws:
MolFormatException - not thrown from this method since it is unsupported now.
MolExportException - not thrown from this method since it is unsupported now.
java.io.IOException - not thrown from this method since it is unsupported now.

MolConverter

@Deprecated
public MolConverter(java.util.List<java.lang.Object> inFiles,
                               java.lang.String ofname,
                               java.lang.String fmtopts,
                               boolean useSysEOL)
             throws MolFormatException,
                    MolExportException,
                    java.io.IOException
Deprecated. as of Marvin 5.2.3, replaced by MolConverter(Builder)

Parameters:
inFiles - not used in this method since it is unsupported now.
ofname - not used in this method since it is unsupported now.
fmtopts - not used in this method since it is unsupported now.
useSysEOL - not used in this method since it is unsupported now.
Throws:
MolFormatException - not thrown from this method since it is unsupported now.
MolExportException - not thrown from this method since it is unsupported now.
java.io.IOException - not thrown from this method since it is unsupported now.

MolConverter

@Deprecated
public MolConverter(java.util.List<java.lang.Object> inFiles,
                               java.util.List<java.lang.String> inOptions,
                               java.lang.String ofname,
                               java.lang.String fmtopts,
                               boolean useSysEOL)
             throws MolFormatException,
                    MolExportException,
                    java.io.IOException,
                    java.lang.IllegalArgumentException
Deprecated. as of Marvin 5.2.3, replaced by MolConverter(Builder)

Parameters:
inFiles - not used in this method since it is unsupported now.
inOptions - not used in this method since it is unsupported now.
ofname - not used in this method since it is unsupported now.
fmtopts - not used in this method since it is unsupported now.
useSysEOL - not used in this method since it is unsupported now.
Throws:
MolFormatException - not thrown from this method since it is unsupported now.
MolExportException - not thrown from this method since it is unsupported now.
java.io.IOException - not thrown from this method since it is unsupported now.
java.lang.IllegalArgumentException

MolConverter

@Deprecated
public MolConverter(MolConverter.Options opts)
             throws MolFormatException,
                    MolExportException,
                    java.io.IOException,
                    java.lang.IllegalArgumentException
Deprecated. as of Marvin 5.2.3, use MolConverter.Builder.build() instead.

Parameters:
opts - not used in this method since it is unsupported now.
Throws:
MolFormatException - not thrown from this method since it is unsupported now.
MolExportException - not thrown from this method since it is unsupported now.
java.io.IOException - not thrown from this method since it is unsupported now.
java.lang.IllegalArgumentException

MolConverter

@Deprecated
public MolConverter(java.util.List<java.lang.Object> inFiles,
                               java.util.List<java.lang.String> inOptions,
                               java.io.OutputStream out,
                               java.lang.String fmtopts,
                               boolean useSysEOL)
             throws MolFormatException,
                    MolExportException,
                    java.io.IOException
Deprecated. as of Marvin 5.2.3, replaced by MolConverter(Builder)

Parameters:
inFiles - not used in this method since it is unsupported now.
inOptions - not used in this method since it is unsupported now.
out - not used in this method since it is unsupported now.
fmtopts - not used in this method since it is unsupported now.
useSysEOL - not used in this method since it is unsupported now.
Throws:
MolFormatException - not thrown from this method since it is unsupported now.
MolExportException - not thrown from this method since it is unsupported now.
java.io.IOException - not thrown from this method since it is unsupported now.

MolConverter

@Deprecated
public MolConverter(java.util.List<java.lang.Object> inFiles,
                               java.util.List<java.lang.String> inOptions,
                               java.io.OutputStream out,
                               java.lang.String fmtopts,
                               boolean useSysEOL,
                               java.lang.String[] incFields)
             throws MolFormatException,
                    MolExportException,
                    java.io.IOException
Deprecated. as of Marvin 5.2.3, replaced by MolConverter(Builder)

Parameters:
inFiles - not used in this method since it is unsupported now.
inOptions - not used in this method since it is unsupported now.
out - not used in this method since it is unsupported now.
fmtopts - not used in this method since it is unsupported now.
useSysEOL - not used in this method since it is unsupported now.
incFields - not used in this method since it is unsupported now.
Throws:
MolFormatException - not thrown from this method since it is unsupported now.
MolExportException - not thrown from this method since it is unsupported now.
java.io.IOException - not thrown from this method since it is unsupported now.

MolConverter

@Deprecated
public MolConverter(java.util.List<java.lang.Object> inFiles,
                               java.util.List<java.lang.String> inOptions,
                               java.io.OutputStream out,
                               java.lang.String fmtopts,
                               boolean useSysEOL,
                               java.lang.String[] incFields,
                               java.lang.String enc)
             throws MolFormatException,
                    MolExportException,
                    java.io.IOException
Deprecated. as of Marvin 5.2.3, replaced by MolConverter(Builder)

Parameters:
inFiles - not used in this method since it is unsupported now.
inOptions - not used in this method since it is unsupported now.
out - not used in this method since it is unsupported now.
fmtopts - not used in this method since it is unsupported now.
useSysEOL - not used in this method since it is unsupported now.
incFields - not used in this method since it is unsupported now.
enc - not used in this method since it is unsupported now.
Throws:
MolFormatException - not thrown from this method since it is unsupported now.
MolExportException - not thrown from this method since it is unsupported now.
java.io.IOException - not thrown from this method since it is unsupported now.
Method Detail

setIgnoreError

public void setIgnoreError(boolean ignoreError)
Sets the 'ignoreError' option. If true then processing is continued with the next molecule on error, otherwise processing is interrupted on error. Default: false.

Parameters:
ignoreError - true if processing should be continued on error
Since:
Marvin 5.3

setThreadCount

public void setThreadCount(int threadCount)
                    throws java.lang.IllegalStateException
Sets the number of threads for concurrent processing. Default: the number of CPUs, single-threaded processing if there is 1 CPU.

Parameters:
threadCount - the number of threads, set 0 for the number of CPUs, 1 for single-threaded mode
Throws:
java.lang.IllegalStateException - if called after call to convert().
Since:
Marvin 5.3

convert

public boolean convert()
                throws java.io.IOException
Convert the next molecule.

Returns:
true if success, false if no more molecules can be read
Throws:
java.io.IOException - If an I/O error has occurred.
java.nio.charset.IllegalCharsetNameException - if the encoding is illegal
java.nio.charset.UnsupportedCharsetException - if the encoding is unsupported

otell

public long otell()
           throws java.io.IOException
Get the current file position.

Returns:
the position
Throws:
java.io.IOException - if the position cannot be determined

close

public void close()
           throws java.io.IOException
Closes the exporter and the output stream.

Throws:
MolExportException - export error.
java.io.IOException - in case of any other I/O error.

close

public void close(int opts)
           throws java.io.IOException
Closes the exporter. If the output stream is specified by the user, then this method only closes it if the MolExporter.C_CLOSE_STREAM option is used. If the input stream was opened internally, then the opts argument has no effect, the output stream is always closed.

Parameters:
opts - closing options for the exporter, applied only if the output stream is specified by the user
Throws:
MolExportException - export error.
java.io.IOException - in case of any other I/O error.
Since:
Marvin 5.2.2, 04/21/2009
See Also:
MolExporter.C_CLOSE_STREAM, MolExporter.C_FLUSH_STREAM

createMolConverter

public static MolConverter createMolConverter(java.io.InputStream instream,
                                              java.io.OutputStream outstream,
                                              java.lang.String[] args,
                                              int[] verbosityLevel)
                                       throws java.io.IOException
Creates a MolConverter instance with the attributes specified in the parameters. Basically allows two usage scenario:

Parameters:
instream - the input stream to take the molecule definition from. It must be null when called for command line usage.
outstream - the output stream to write the result onto. It must be null when called for command line usage.
args - space separated options of attributes/options for the desired MolConverter instance.
verbosityLevel - may be used by the caller to retrieve (as the first element of the array) the verbosity level specified in args. Must be either at least one element long or (if the caller is not interested in this value) null.
Throws:
java.nio.charset.IllegalCharsetNameException - if illegal input or output encoding name specified
java.nio.charset.UnsupportedCharsetException - if the specified input or output encoding is unsupported
java.io.IOException

main

public static void main(java.lang.String[] args)
                 throws java.io.IOException
Main method.

Parameters:
args - command line arguments
Throws:
java.io.IOException

mainWithoutExit

public static void mainWithoutExit(java.lang.String[] args)
                            throws java.io.IOException
Same as main(), but never calls System.exit(). Useful to call from other java programs. Instead of exiting the JVM, a RuntimeException may be thrown with text "molconvert exit:<exit status>"

Parameters:
args - arguments passed to main().
Throws:
java.io.IOException