X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2Fjalview%2Fws%2Febi%2FEBIFetchClient.java;h=3e8c55ed621b8f9d3a60c1d3f81911122211b139;hb=a862a922bf20918fc3f5066ac92e4c69da07e105;hp=dd3cc16222324f50c9d4e5949161639d7b5a2a2f;hpb=65d7b70ce9788fd1680a5e81b1eaae30126b8ed2;p=jalview.git diff --git a/src/jalview/ws/ebi/EBIFetchClient.java b/src/jalview/ws/ebi/EBIFetchClient.java index dd3cc16..3e8c55e 100644 --- a/src/jalview/ws/ebi/EBIFetchClient.java +++ b/src/jalview/ws/ebi/EBIFetchClient.java @@ -91,7 +91,7 @@ public class EBIFetchClient * @param format * the format wanted * @param extension - * for the temporary file to hold response + * for the temporary file to hold response (without separator) * @return the file holding the response * @throws OutOfMemoryError */ @@ -102,7 +102,7 @@ public class EBIFetchClient File outFile = null; try { - outFile = File.createTempFile("jalview", ext); + outFile = File.createTempFile("jalview", "." + ext); outFile.deleteOnExit(); fetchData(ids, format, outFile); if (outFile.length() == 0) @@ -116,28 +116,33 @@ public class EBIFetchClient return outFile; } - String[] fetchData(String ids, String f, File outFile) + /** + * Fetches queries and either saves the response to a file or returns as + * string data + * + * @param ids + * @param format + * @param outFile + * @return + * @throws OutOfMemoryError + */ + String[] fetchData(String ids, String format, File outFile) throws OutOfMemoryError { - String[] rslts = new String[0]; StringBuilder querystring = new StringBuilder(ids.length()); - String db = parseIds(ids, querystring); - if (db == null) + String database = parseIds(ids, querystring); + if (database == null) { System.err.println("Invalid Query string : '" + ids + "'"); System.err.println("Should be of form 'dbname:q1;q2;q3;q4'"); return null; } - String[] rslt = fetchBatch(querystring.toString(), db, f, outFile); - if (rslt != null) - { - String[] nrslts = new String[rslt.length + rslts.length]; - System.arraycopy(rslts, 0, nrslts, 0, rslts.length); - System.arraycopy(rslt, 0, nrslts, rslts.length, rslt.length); - rslts = nrslts; - } - return (rslts.length == 0 ? null : rslts); + // note: outFile is currently always specified, so return value is null + String[] rslt = fetchBatch(querystring.toString(), database, format, + outFile); + + return (rslt != null && rslt.length > 0 ? rslt : null); } /** @@ -179,11 +184,22 @@ public class EBIFetchClient return database; } - String[] fetchBatch(String ids, String dbPath, String format, + /** + * Fetches queries and either saves the response to a file or (if no file + * specified) returns as string data + * + * @param ids + * @param database + * @param format + * @param outFile + * @return + * @throws OutOfMemoryError + */ + String[] fetchBatch(String ids, String database, String format, File outFile) throws OutOfMemoryError { // long time = System.currentTimeMillis(); - String url = buildUrl(ids, dbPath, format); + String url = buildUrl(ids, database, format); try { @@ -215,8 +231,7 @@ public class EBIFetchClient } } catch (OutOfMemoryError er) { - - System.out.println("OUT OF MEMORY DOWNLOADING QUERY FROM " + dbPath + System.out.println("OUT OF MEMORY DOWNLOADING QUERY FROM " + database + ":\n" + ids); throw er; } catch (Exception ex) @@ -227,8 +242,7 @@ public class EBIFetchClient return null; } System.err.println("Unexpected exception when retrieving from " - + dbPath - + "\nQuery was : '" + ids + "'"); + + database + "\nQuery was : '" + ids + "'"); ex.printStackTrace(System.err); return null; } finally