[Swift-commit] r7872 - trunk/src/org/griphyn/vdl/mapping/file

hategan at ci.uchicago.edu hategan at ci.uchicago.edu
Sat May 17 21:08:48 CDT 2014


Author: hategan
Date: 2014-05-17 21:08:47 -0500 (Sat, 17 May 2014)
New Revision: 7872

Modified:
   trunk/src/org/griphyn/vdl/mapping/file/ExternalMapper.java
Log:
read output of external mapper progressively instead of buffering all output and then processing it

Modified: trunk/src/org/griphyn/vdl/mapping/file/ExternalMapper.java
===================================================================
--- trunk/src/org/griphyn/vdl/mapping/file/ExternalMapper.java	2014-05-15 19:19:57 UTC (rev 7871)
+++ trunk/src/org/griphyn/vdl/mapping/file/ExternalMapper.java	2014-05-18 02:08:47 UTC (rev 7872)
@@ -81,7 +81,8 @@
 		    if (logger.isDebugEnabled()) {
 		        logger.debug("invoking external mapper: " + cmd);
 		    }
-			Process p = Runtime.getRuntime().exec(cmd.toArray(STRING_ARRAY));
+			Process p = Runtime.getRuntime().exec(cmd.toArray(STRING_ARRAY));
+			process(p.getInputStream());
 			List<String> lines = fetchOutput(p.getInputStream());
 			if (logger.isDebugEnabled()) {
 			    logger.debug("external mapper output: " + lines);
@@ -91,7 +92,6 @@
 				throw new RuntimeException("External executable failed. Exit code: " + ec + "\n\t"
 						+ join(lines) + "\n\t" + join(fetchOutput(p.getErrorStream())));
 			}
-			processLines(cp, lines);
 		}
 		catch (IOException e) {
 			throw new RuntimeException(e);
@@ -109,6 +109,15 @@
 			sb.append('\t');
 		}
 		return sb.toString();
+	}
+	
+	private void process(InputStream is) throws IOException {
+		BufferedReader br = new BufferedReader(new InputStreamReader(is));
+		String line = br.readLine();
+        while (line != null) {
+            processLine(line);
+            line = br.readLine();
+        }
 	}
 
 	private List<String> fetchOutput(InputStream is) throws IOException {
@@ -122,20 +131,18 @@
 		return lines;
 	}
 
-	private void processLines(ExternalMapperParams cp, List<String> lines) {
-		for (String line : lines) {
-			int s = line.indexOf(' ');
-			int t = line.indexOf('\t');
-			int m = Math.min(s == -1 ? t : s, t == -1 ? s : t);
-			if (m == -1) {
-				throw new RuntimeException("Invalid line in mapper script output: " + line);
-			}
-			String spath = line.substring(0, m);
-			Path p = Path.parse(spath);
-			AbsFile f = new AbsFile(line.substring(m + 1).trim());
-			map.put(p, f);
-			rmap.put(spath, p);
+	private void processLine(String line) {
+		int s = line.indexOf(' ');
+		int t = line.indexOf('\t');
+		int m = Math.min(s == -1 ? t : s, t == -1 ? s : t);
+		if (m == -1) {
+			throw new RuntimeException("Invalid line in mapper script output: " + line);
 		}
+		String spath = line.substring(0, m);
+		Path p = Path.parse(spath);
+		AbsFile f = new AbsFile(line.substring(m + 1).trim());
+		map.put(p, f);
+		rmap.put(spath, p);
 	}
 
 	@Override




More information about the Swift-commit mailing list