summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuke Bratch <l_bratch@yahoo.co.uk>2010-11-01 20:37:11 +0000
committerLuke Bratch <l_bratch@yahoo.co.uk>2010-11-01 20:37:11 +0000
commit633194465907f1b22c6f35d7cb285a214b01a172 (patch)
tree017627ad6727095f003c78500a2f5072e1547512
parent9f3b44133b9febbf27e0f2d8871b737a9ef64844 (diff)
Allow either stdin or command line arguments for the query
-rw-r--r--blasearch.java24
1 files changed, 18 insertions, 6 deletions
diff --git a/blasearch.java b/blasearch.java
index f774600..2cd4032 100644
--- a/blasearch.java
+++ b/blasearch.java
@@ -32,13 +32,25 @@ public class blasearch {
{
String query = "";
- // Incorporate all args in search
- for(int i=0; i<args.length; i++){
- args[i] = args[i].replace(' ','+');
- query = query + args[i] + "+";
+ /* Build query from query or arguments, depending on whether
+ arguments were given. */
+ if (args.length == 0) {
+ try {
+ BufferedReader br =
+ new BufferedReader(new InputStreamReader(System.in));
+ query = br.readLine();
+ } catch (Exception e) {
+ System.err.println("Error:" + e.getMessage());
+ System.exit(1);
+ }
+ } else {
+ for (int i = 0; i < args.length; i++) {
+ query += args[i];
+ }
}
- // Remove trailing +
- query = query.substring(0, query.length()-1);
+
+ // Change all ' ' to '+'
+ query = query.replaceAll(" ", "+");
String[] parts = null;
//URL which provides XML response