-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
4 changed files
with
50 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package davidkhala.common; | ||
|
||
import java.io.IOException; | ||
|
||
public class CLI { | ||
public static void exec(String... command) throws IOException, InterruptedException { | ||
Process p = Runtime.getRuntime().exec(command); | ||
p.getInputStream().transferTo(System.out); | ||
p.getErrorStream().transferTo(System.err); | ||
p.waitFor(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,6 @@ | |
|
||
|
||
import java.io.*; | ||
import java.net.URI; | ||
import java.util.Objects; | ||
|
||
public class FileTool { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,36 @@ | ||
package davidkhala.common; | ||
|
||
import java.io.ByteArrayInputStream; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.io.*; | ||
|
||
public class Stream { | ||
public static String read(InputStream is) throws IOException { | ||
int size = is.available(); | ||
byte[] buffer = new byte[size]; | ||
while (true) { | ||
if (is.read(buffer) < 0) { | ||
break; | ||
} | ||
} | ||
public interface InputCallback { | ||
void onData(int _byte); | ||
} | ||
|
||
is.close(); | ||
return new String(buffer); | ||
public static String read(InputStream is) throws IOException { | ||
int size = is.available(); | ||
byte[] buffer = new byte[size]; | ||
while (true) { | ||
if (is.read(buffer) < 0) { | ||
break; | ||
} | ||
} | ||
|
||
public static InputStream from(String string) { | ||
return new ByteArrayInputStream(string.getBytes()); | ||
is.close(); | ||
return new String(buffer); | ||
} | ||
|
||
public static void read(InputStream is, InputCallback callback) throws IOException { | ||
while (true) { | ||
int b = is.read(); | ||
if (b == -1) { | ||
break; | ||
} | ||
callback.onData(b); | ||
} | ||
} | ||
|
||
public static InputStream from(String string) { | ||
return new ByteArrayInputStream(string.getBytes()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import davidkhala.common.CLI; | ||
import org.junit.Test; | ||
|
||
import java.io.IOException; | ||
|
||
public class CLITest { | ||
@Test | ||
public void jVersion() throws IOException, InterruptedException { | ||
CLI.exec("java", "-version"); | ||
} | ||
} |