Search in sources :

Example 1 with AmbitIOException

use of ambit2.base.exceptions.AmbitIOException in project ambit-mirror by ideaconsult.

the class Template method save.

public boolean save(Writer writer) throws AmbitIOException {
    Source source;
    try {
        source = new DOMSource(buildDocument());
        Transformer xformer = TransformerFactory.newInstance().newTransformer();
        xformer.setOutputProperty(OutputKeys.INDENT, "Yes");
        xformer.setOutputProperty(OutputKeys.STANDALONE, "Yes");
        Result result = new StreamResult(writer);
        xformer.transform(source, result);
        writer.flush();
        return true;
    } catch (Exception x) {
        throw new AmbitIOException(x);
    }
}
Also used : DOMSource(javax.xml.transform.dom.DOMSource) Transformer(javax.xml.transform.Transformer) StreamResult(javax.xml.transform.stream.StreamResult) AmbitIOException(ambit2.base.exceptions.AmbitIOException) DOMSource(javax.xml.transform.dom.DOMSource) InputSource(org.xml.sax.InputSource) Source(javax.xml.transform.Source) AmbitIOException(ambit2.base.exceptions.AmbitIOException) StreamResult(javax.xml.transform.stream.StreamResult) Result(javax.xml.transform.Result)

Example 2 with AmbitIOException

use of ambit2.base.exceptions.AmbitIOException in project ambit-mirror by ideaconsult.

the class Property method save.

public boolean save(Writer writer) throws AmbitIOException {
    try {
        writer.write("\n");
        writer.write("<field ");
        writer.write("name=\"");
        writer.write(getName());
        writer.write("\" units=\"");
        writer.write(getUnits());
        writer.write("\" class=");
        writer.write(getClazz().getName());
        writer.write("/>");
        return true;
    } catch (IOException x) {
        throw new AmbitIOException(this.getClass().getName(), x);
    }
}
Also used : AmbitIOException(ambit2.base.exceptions.AmbitIOException) AmbitIOException(ambit2.base.exceptions.AmbitIOException) IOException(java.io.IOException)

Example 3 with AmbitIOException

use of ambit2.base.exceptions.AmbitIOException in project ambit-mirror by ideaconsult.

the class FileInputState method getI5DReader.

public static IIteratingChemObjectReader getI5DReader(File file) throws FileNotFoundException, AmbitIOException, CDKException {
    try {
        Class clazz = Class.forName("net.idea.i5.io.I5DReader");
        Constructor constructor = clazz.getConstructor(File.class);
        return (IIteratingChemObjectReader) constructor.newInstance(file);
    } catch (Exception x) {
        return new I5ReaderSimple(new FileReader(file));
    }
}
Also used : IIteratingChemObjectReader(org.openscience.cdk.io.iterator.IIteratingChemObjectReader) Constructor(java.lang.reflect.Constructor) FileReader(java.io.FileReader) AmbitIOException(ambit2.base.exceptions.AmbitIOException) CDKException(org.openscience.cdk.exception.CDKException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException)

Example 4 with AmbitIOException

use of ambit2.base.exceptions.AmbitIOException in project ambit-mirror by ideaconsult.

the class FileOutputState method getWriter.

public static IChemObjectWriter getWriter(OutputStream stream, String ext) throws AmbitIOException {
    String fname = ext.toLowerCase();
    IChemObjectWriter writer = null;
    try {
        if (fname.endsWith(_FILE_TYPE.SDF_INDEX.getExtension())) {
            writer = new SDFWriter(stream);
        } else if (fname.endsWith(_FILE_TYPE.CSV_INDEX.getExtension()))
            writer = new DelimitedFileWriter(stream);
        else if ((fname.endsWith(_FILE_TYPE.TXT_INDEX.getExtension())))
            writer = new DelimitedFileWriter(stream, new DelimitedFileFormat("\t", '"'));
        else if ((fname.endsWith(_FILE_TYPE.SMI_INDEX.getExtension())))
            writer = new SMILESWriter(stream);
        else /*
			else if ((fname.endsWith(extensions[HTML_INDEX]))) 
				writer = new HTMLTableWriter(stream);
			else if ((fname.endsWith(extensions[JPG_INDEX]))) 			
				writer = new ImageWriter(stream);
			else if ((fname.endsWith(extensions[PNG_INDEX])))  
				writer = new ImageWriter(stream);
				*/
        if ((fname.endsWith(_FILE_TYPE.PDF_INDEX.getExtension()))) {
            try {
                writer = createWriterByReflection("ambit2.core.io.PDFWriter", stream);
            } catch (Exception x) {
                throw new AmbitIOException(x);
            }
        } else if ((fname.endsWith(_FILE_TYPE.XYZ_INDEX.getExtension())))
            writer = new XYZWriter(stream);
        else if ((fname.endsWith(_FILE_TYPE.HIN_INDEX.getExtension())))
            writer = new HINWriter(stream);
        else if ((fname.endsWith(_FILE_TYPE.MOL_INDEX.getExtension())))
            writer = new SDFWriter(stream);
        else if ((fname.endsWith(_FILE_TYPE.VW_INDEX.getExtension()))) {
            writer = new DelimitedFileWriter(stream, new DelimitedFileFormat("|", '"'));
            ((DelimitedFileWriter) writer).setAddSMILEScolumn(false);
        } else /*
			else if ((fname.endsWith(extensions[SVG_INDEX]))) 
				writer = new SVGWriter(stream);
				*/
        if ((fname.endsWith(_FILE_TYPE.XLS_INDEX.getExtension())))
            try {
                writer = createXLSXWriterByReflection("ambit2.core.io.XLSFileWriter", stream, true);
            } catch (Exception x) {
                throw new AmbitIOException(x);
            }
        else if ((fname.endsWith(_FILE_TYPE.XLSX_INDEX.getExtension())))
            try {
                writer = createXLSXWriterByReflection("ambit2.core.io.XLSFileWriter", stream, false);
            } catch (Exception x) {
                throw new AmbitIOException(x);
            }
        else
            throw new AmbitIOException(MSG_UNSUPPORTEDFORMAT + ext);
    } catch (Exception x) {
        // logger.error(MSG_ERRORSAVE,filename);
        throw new AmbitIOException(MSG_ERRORSAVE, x);
    }
    return writer;
}
Also used : XYZWriter(org.openscience.cdk.io.XYZWriter) AmbitIOException(ambit2.base.exceptions.AmbitIOException) SMILESWriter(org.openscience.cdk.io.SMILESWriter) HINWriter(org.openscience.cdk.io.HINWriter) SDFWriter(org.openscience.cdk.io.SDFWriter) IChemObjectWriter(org.openscience.cdk.io.IChemObjectWriter) AmbitIOException(ambit2.base.exceptions.AmbitIOException)

Example 5 with AmbitIOException

use of ambit2.base.exceptions.AmbitIOException in project ambit-mirror by ideaconsult.

the class ZipReader method unzip.

public File[] unzip(File zipfile, File directory, OPTIONS options) throws AmbitIOException {
    List<File> files = new ArrayList<File>();
    ZipFile zipFile = null;
    try {
        zipFile = new ZipFile(zipfile);
        Enumeration<? extends ZipEntry> zEntries = zipFile.entries();
        while (zEntries.hasMoreElements()) {
            ZipEntry zipEntry = zEntries.nextElement();
            if (zipEntry.isDirectory())
                continue;
            File file = unzipEntry(zipEntry, zipFile.getInputStream(zipEntry), directory);
            if (file != null)
                files.add(file);
        }
        return files == null ? null : files.size() == 0 ? null : files.toArray(new File[files.size()]);
    } catch (Exception x) {
        throw new AmbitIOException(x);
    } finally {
        if (zipFile != null)
            try {
                zipFile.close();
            } catch (Exception x) {
            }
    }
}
Also used : ZipFile(java.util.zip.ZipFile) AmbitIOException(ambit2.base.exceptions.AmbitIOException) ZipEntry(java.util.zip.ZipEntry) ArrayList(java.util.ArrayList) File(java.io.File) ZipFile(java.util.zip.ZipFile) AmbitIOException(ambit2.base.exceptions.AmbitIOException) AmbitException(net.idea.modbcum.i.exceptions.AmbitException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException)

Aggregations

AmbitIOException (ambit2.base.exceptions.AmbitIOException)18 FileNotFoundException (java.io.FileNotFoundException)11 IOException (java.io.IOException)11 CDKException (org.openscience.cdk.exception.CDKException)8 FileInputState (ambit2.core.io.FileInputState)6 InteractiveIteratingMDLReader (ambit2.core.io.InteractiveIteratingMDLReader)5 IAtomContainer (org.openscience.cdk.interfaces.IAtomContainer)5 IChemObjectReaderErrorHandler (org.openscience.cdk.io.IChemObjectReaderErrorHandler)5 File (java.io.File)4 AmbitException (net.idea.modbcum.i.exceptions.AmbitException)4 IIteratingChemObjectReader (org.openscience.cdk.io.iterator.IIteratingChemObjectReader)4 Constructor (java.lang.reflect.Constructor)3 ZipFile (java.util.zip.ZipFile)3 DataOutputStream (java.io.DataOutputStream)2 InputStreamReader (java.io.InputStreamReader)2 ArrayList (java.util.ArrayList)2 ZipEntry (java.util.zip.ZipEntry)2 InputSource (org.xml.sax.InputSource)2 RawIteratingCSVReader (ambit2.core.io.RawIteratingCSVReader)1 RawIteratingFolderReader (ambit2.core.io.RawIteratingFolderReader)1