diff options
Diffstat (limited to 'tutorials/java/src/DBGThread.java')
-rw-r--r-- | tutorials/java/src/DBGThread.java | 90 |
1 files changed, 0 insertions, 90 deletions
diff --git a/tutorials/java/src/DBGThread.java b/tutorials/java/src/DBGThread.java deleted file mode 100644 index 73e2dc4f91..0000000000 --- a/tutorials/java/src/DBGThread.java +++ /dev/null @@ -1,90 +0,0 @@ - -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.net.Socket; - -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ - -/** - * Manage input and output data - * @author krakjoe - */ -public class DBGThread extends Socket implements Runnable { - private final Boolean reader; - private final Main main; - private Boolean quit; - - public DBGThread(final String host, final Integer port, final Main main, Boolean reader) throws IOException { - super(host, port); - - this.main = main; - this.reader = reader; - this.quit = false; - - main.setConnected(true); - } - - public void quit() { - synchronized(this) { - quit = true; - this.notifyAll(); - } - } - - @Override public void run() { - try { - synchronized(this) { - do { - if (reader) { - String command; - OutputStream output = getOutputStream(); - - this.wait(); - - command = main.getInputField().getText(); - /* send command to stdin socket */ - if (command != null) { - output.write( - command.getBytes()); - output.write("\n".getBytes()); - output.flush(); - } - main.getInputField().setText(null); - } else { - InputStream input = getInputStream(); - /* get data from stdout socket */ - byte[] bytes = new byte[1]; - do { - /* this is some of the laziest programming I ever done */ - if (input.available() == 0) { - this.wait(666); - continue; - } - - if (input.read(bytes, 0, 1) > -1) { - main.getOutputField().setCaretPosition( - main.getOutputField().getText().length()); - main.getOutputField().append(new String(bytes)); - } - } while (!quit); - } - } while(!quit); - } - } catch (IOException | InterruptedException ex) { - if (!quit) { - main.messageBox(ex.getMessage()); - } - } finally { - try { - close(); - } catch (IOException ex) { /* naughty me */ } finally { - main.setConnected(false); - } - } - } -} |