Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // dsh - Data shell
- import java.io.BufferedReader;
- import java.io.FileInputStream;
- import java.io.IOException;
- import java.io.InputStreamReader;
- import java.io.OutputStream;
- import java.util.regex.Matcher;
- import java.util.regex.Pattern;
- public class DataShell {
- public static class F extends Thread {
- public void run() {
- try {
- sleep(100);
- System.out.flush();
- } catch (InterruptedException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- }
- public static void copyFileToStream(String filename, OutputStream o) throws IOException {
- FileInputStream fis = new FileInputStream(filename);
- int c=0;
- while ((c=fis.read()) != -1) {
- o.write(c);
- }
- fis.close();
- }
- /**
- * @param args
- */
- public static void main(String[] args) {
- InputStreamReader isr = new InputStreamReader(System.in);
- BufferedReader br = new BufferedReader(isr);
- String line;
- try {
- new F().start();
- while ((line = br.readLine()) != null) {
- if (line.startsWith("q")) {
- break;
- } else if (line.startsWith("a")) {
- line = line.substring(1);
- System.out.write(line.getBytes());
- } else if (line.startsWith("h")) {
- Pattern p = Pattern.compile("0x([0-9a-fA-F]{1,2})");
- Matcher m = p.matcher(line);
- while (m.find()) {
- String hexNumber = m.group(1);
- byte b=Byte.parseByte(hexNumber, 16);
- System.out.write(b);
- }
- } else if (line.startsWith("f")) {
- line = line.substring(1);
- copyFileToStream(line, System.out);
- }
- //System.out.write(line.getBytes());
- System.out.flush();
- }
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement