Skip to content

Commit

Permalink
really 1.6. compatible now. srsly.
Browse files Browse the repository at this point in the history
  • Loading branch information
jhbruhn committed Mar 6, 2014
1 parent 8c83d1c commit c71a839
Showing 1 changed file with 40 additions and 13 deletions.
53 changes: 40 additions & 13 deletions src/de/littlerolf/sav/SortAlgorithmVisualizer.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package de.littlerolf.sav;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.lang.ProcessBuilder.Redirect;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLClassLoader;
Expand Down Expand Up @@ -32,17 +33,21 @@ public static void main(String[] args) {
int remoteVersion = getRemoteVersion();
int localVersion = getLocalVersion();
int downloadedVersion = getDownloadedJarVersion();

if (remoteVersion > downloadedVersion && remoteVersion > localVersion) {
System.out.println("Starting remote version.");
startJar(downloadRemoteJar().getAbsolutePath());
} else if (downloadedVersion > remoteVersion
&& downloadedVersion > localVersion) {
System.out.println("Starting cached version.");
startJar(DOWNLOADED_FILE.getAbsolutePath());
} else {
System.out.println("Starting local version.");
if (localVersion == -1) {
startLocal();
} else {
if (remoteVersion > downloadedVersion
&& remoteVersion > localVersion) {
System.out.println("Starting remote version.");
startJar(downloadRemoteJar().getAbsolutePath());
} else if (downloadedVersion > remoteVersion
&& downloadedVersion > localVersion) {
System.out.println("Starting cached version.");
startJar(DOWNLOADED_FILE.getAbsolutePath());
} else {
System.out.println("Starting local version.");
startLocal();
}
}
/*
* if (getLocalVersion() > -1) { if (isRemoteNewer()) {
Expand Down Expand Up @@ -149,10 +154,11 @@ private static void startJar(String path) {
System.out.println("Starting jar " + path + ".");
ProcessBuilder pb = new ProcessBuilder("java", "-classpath", path,
SortAlgorithmVisualizer.class.getName());
pb.redirectInput(Redirect.INHERIT).redirectOutput(Redirect.INHERIT)
.redirectError(Redirect.INHERIT);
try {
Process p = pb.start();
new StreamGobbler(p.getErrorStream()).start();
new StreamGobbler(p.getInputStream()).start();

p.waitFor();

} catch (IOException e) {
Expand Down Expand Up @@ -191,4 +197,25 @@ private static void startLocal() {
JOptionPane.ERROR_MESSAGE);
}
}

private static class StreamGobbler extends Thread {
InputStream is;

// reads everything from is until empty.
StreamGobbler(InputStream is) {
this.is = is;
}

public void run() {
try {
InputStreamReader isr = new InputStreamReader(is);
BufferedReader br = new BufferedReader(isr);
String line = null;
while ((line = br.readLine()) != null)
System.out.println(line);
} catch (IOException ioe) {
ioe.printStackTrace();
}
}
}
}

0 comments on commit c71a839

Please sign in to comment.