Anonymous avatar Anonymous committed 7823673 Merge

Merge with gigadot

Comments (0)

Files changed (4)

gigatools-extra/src/main/java/gigatools/extra/inchi/InChIConverter.java

 package gigatools.extra.inchi;
 
+import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
 import java.io.File;
 import java.io.IOException;
+import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.HashMap;
 import java.util.HashSet;
 import org.apache.commons.exec.Executor;
 import org.apache.commons.exec.PumpStreamHandler;
 import org.apache.commons.io.FileUtils;
+import org.apache.commons.io.IOUtils;
 import org.apache.commons.lang.SystemUtils;
 import org.xmlcml.cml.element.CMLAtom;
 import org.xmlcml.cml.element.CMLMolecule;
     }
 
     protected static String getInChI(String cmlMolecule, String... options) throws InChIException {
-        File inchi = convert(cmlMolecule, options);
-        try {
-            List<String> lines = FileUtils.readLines(inchi, "UTF-8");
-            for (String line : lines) {
-                if (line.startsWith("InChI")) {
-                    return line;
-                }
+        List<String> lines = convert(cmlMolecule, options);
+        for (String line : lines) {
+            if (line.startsWith("InChI")) {
+                return line;
             }
-            throw new InChIException("InChI not found in " + inchi.getAbsolutePath());
-        } catch (IOException ex) {
-            throw new InChIException("Unable to read inchi file at " + inchi.getAbsolutePath(), ex);
         }
+        throw new InChIException("InChI not found.");
     }
 
     public static String getInChIKey(CMLMolecule molecule, String... options) throws InChIException {
     }
 
     protected static String getInChIKey(String cmlMolecule, String... options) throws InChIException {
-        File inchi = convert(cmlMolecule, options);
-        try {
-            List<String> lines = FileUtils.readLines(inchi, "UTF-8");
-            for (String line : lines) {
-                if (line.startsWith("InChIKey")) {
-                    return line;
-                }
+        List<String> lines = convert(cmlMolecule, options);
+        for (String line : lines) {
+            if (line.startsWith("InChIKey")) {
+                return line;
             }
-            throw new InChIException("InChIKey not found in " + inchi.getAbsolutePath());
-        } catch (IOException ex) {
-            throw new InChIException("Unable to read inchi file at " + inchi.getAbsolutePath(), ex);
         }
-
+        throw new InChIException("InChIKey not found in.");
     }
 
-    private static File convert(CMLMolecule molecule, String... options) throws InChIException {
+    private static List<String> convert(CMLMolecule molecule, String... options) throws InChIException {
         return convert(molecule.toXML(), options);
     }
 
-    private static File convert(String cmlMolecule, String... options) throws InChIException {
+    private static List<String> convert(String cmlMolecule, String... options) throws InChIException {
         if (!executableExists) {
             throw new InChIException("inchi-1 command not found on your system. If you have just"
                     + " installed InChI, please restart your application or redeploy your web application"
         PumpStreamHandler psh = new PumpStreamHandler(stdout);
         executor.setStreamHandler(psh);
         executor.setWatchdog(watchdog);
+        List<String> lines = new ArrayList<String>();
         try {
             exitValue = executor.execute(commandLine);
+            lines = FileUtils.readLines(output, "UTF-8");
         } catch (Exception ex) {
             throw new InChIException("Failed to execute command (exit value = " + exitValue + ") : " + commandLine.toString(), ex);
+        } finally {
+            FileUtils.deleteQuietly(tempDir);
         }
-        try {
-            FileUtils.writeByteArrayToFile(stdoutfile, stdout.toByteArray());
-        } catch (IOException ex) {
-        }
-        return output;
+//        try {
+//            FileUtils.writeByteArrayToFile(stdoutfile, stdout.toByteArray());
+//        } catch (IOException ex) {
+//        }
+        return lines;
     }
 }

gigatools-extra/src/main/java/gigatools/extra/openbabel/OpenBabelConverter.java

         } catch (Exception ex) {
             throw new OpenBabelException("Failed to execute command (exit value = " + exitValue + ") : " + commandLine.toString(), ex);
         }
-        try {
-            FileUtils.writeByteArrayToFile(stdoutfile, stdout.toByteArray());
-        } catch (IOException ex) {
-        }
+//        try {
+//            FileUtils.writeByteArrayToFile(stdoutfile, stdout.toByteArray());
+//        } catch (IOException ex) {
+//        }
         try {
             String outstring = FileUtils.readFileToString(output, "UTF-8");
             switch (obformat) {
             }
         } catch (IOException ex) {
             throw new OpenBabelException("Unable to read output file at " + output.getAbsolutePath(), ex);
+        } finally {
+            FileUtils.deleteQuietly(tempDir);
         }
     }
 }

gigatools-extra/src/test/java/gigatools/extra/inchi/InChIConverterTest.java

             InChIConverter.setHomeDir(new File("target"));
             String cmlMolecule = IOUtils.toString(getClass().getResourceAsStream("molecule.cml"), "UTF-8");
             String result = InChIConverter.getInChI(cmlMolecule);
-            assertEquals(result, "InChI=1S/C2H6O/c1-2-3/h3H,2H2,1H3");
+            assertEquals("InChI=1S/C2H6O/c1-2-3/h3H,2H2,1H3", result);
             System.out.println("OUTPUT: " + result);
         } catch (InChIException ex) {
             System.out.println(ex.getMessage());
 				<enabled>true</enabled>
 			</snapshots>
 		</repository>
-		<repository>
+        <repository>
+            <id>gigadot.net</id>
+            <url>http://maven2.gigadot.net/</url>
+        </repository>
+		<!--repository>
 			<id>como-repo</id>
 			<name>CoMo Maven2</name>
 			<url>http://como.cheng.cam.ac.uk/maven2</url>
 			<snapshots>
 				<enabled>true</enabled>
 			</snapshots>
-		</repository>
+		</repository-->
 	</repositories>
     <properties>
         <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.