Skip to content

Commit c71a839

Browse files
committed
really 1.6. compatible now. srsly.
1 parent 8c83d1c commit c71a839

File tree

1 file changed

+40
-13
lines changed

1 file changed

+40
-13
lines changed

src/de/littlerolf/sav/SortAlgorithmVisualizer.java

+40-13
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
package de.littlerolf.sav;
22

3+
import java.io.BufferedReader;
34
import java.io.File;
45
import java.io.FileOutputStream;
56
import java.io.IOException;
67
import java.io.InputStream;
7-
import java.lang.ProcessBuilder.Redirect;
8+
import java.io.InputStreamReader;
89
import java.net.MalformedURLException;
910
import java.net.URL;
1011
import java.net.URLClassLoader;
@@ -32,17 +33,21 @@ public static void main(String[] args) {
3233
int remoteVersion = getRemoteVersion();
3334
int localVersion = getLocalVersion();
3435
int downloadedVersion = getDownloadedJarVersion();
35-
36-
if (remoteVersion > downloadedVersion && remoteVersion > localVersion) {
37-
System.out.println("Starting remote version.");
38-
startJar(downloadRemoteJar().getAbsolutePath());
39-
} else if (downloadedVersion > remoteVersion
40-
&& downloadedVersion > localVersion) {
41-
System.out.println("Starting cached version.");
42-
startJar(DOWNLOADED_FILE.getAbsolutePath());
43-
} else {
44-
System.out.println("Starting local version.");
36+
if (localVersion == -1) {
4537
startLocal();
38+
} else {
39+
if (remoteVersion > downloadedVersion
40+
&& remoteVersion > localVersion) {
41+
System.out.println("Starting remote version.");
42+
startJar(downloadRemoteJar().getAbsolutePath());
43+
} else if (downloadedVersion > remoteVersion
44+
&& downloadedVersion > localVersion) {
45+
System.out.println("Starting cached version.");
46+
startJar(DOWNLOADED_FILE.getAbsolutePath());
47+
} else {
48+
System.out.println("Starting local version.");
49+
startLocal();
50+
}
4651
}
4752
/*
4853
* if (getLocalVersion() > -1) { if (isRemoteNewer()) {
@@ -149,10 +154,11 @@ private static void startJar(String path) {
149154
System.out.println("Starting jar " + path + ".");
150155
ProcessBuilder pb = new ProcessBuilder("java", "-classpath", path,
151156
SortAlgorithmVisualizer.class.getName());
152-
pb.redirectInput(Redirect.INHERIT).redirectOutput(Redirect.INHERIT)
153-
.redirectError(Redirect.INHERIT);
154157
try {
155158
Process p = pb.start();
159+
new StreamGobbler(p.getErrorStream()).start();
160+
new StreamGobbler(p.getInputStream()).start();
161+
156162
p.waitFor();
157163

158164
} catch (IOException e) {
@@ -191,4 +197,25 @@ private static void startLocal() {
191197
JOptionPane.ERROR_MESSAGE);
192198
}
193199
}
200+
201+
private static class StreamGobbler extends Thread {
202+
InputStream is;
203+
204+
// reads everything from is until empty.
205+
StreamGobbler(InputStream is) {
206+
this.is = is;
207+
}
208+
209+
public void run() {
210+
try {
211+
InputStreamReader isr = new InputStreamReader(is);
212+
BufferedReader br = new BufferedReader(isr);
213+
String line = null;
214+
while ((line = br.readLine()) != null)
215+
System.out.println(line);
216+
} catch (IOException ioe) {
217+
ioe.printStackTrace();
218+
}
219+
}
220+
}
194221
}

0 commit comments

Comments
 (0)