-
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.
- Loading branch information
Showing
3 changed files
with
62 additions
and
2 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
50 changes: 50 additions & 0 deletions
50
src/main/java/com/fathzer/jchess/bot/uci/StdErrReader.java
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,50 @@ | ||
package com.fathzer.jchess.bot.uci; | ||
|
||
import java.io.BufferedReader; | ||
import java.io.Closeable; | ||
import java.io.EOFException; | ||
import java.io.IOException; | ||
|
||
class StdErrReader implements Closeable, Runnable { | ||
private final BufferedReader errorReader; | ||
private final Thread spyThread; | ||
private boolean stopped; | ||
|
||
StdErrReader(Process process) { | ||
this.errorReader = process.errorReader(); | ||
this.spyThread = new Thread(this); | ||
this.spyThread.setDaemon(true); | ||
this.spyThread.start(); | ||
} | ||
|
||
@Override | ||
public void run() { | ||
while (!stopped) { | ||
try { | ||
final String line = errorReader.readLine(); | ||
if (line!=null) { | ||
System.err.println (line); //TODO | ||
} | ||
} catch (EOFException e) { | ||
if (!stopped) { | ||
log(e); | ||
} | ||
} catch (IOException e) { | ||
log(e); | ||
} | ||
} | ||
} | ||
|
||
private void log(IOException e) { | ||
synchronized(System.err) { | ||
System.err.println("An error occured, stopped is "+ stopped); | ||
e.printStackTrace(); //TODO | ||
} | ||
} | ||
|
||
@Override | ||
public void close() throws IOException { | ||
this.stopped = true; | ||
this.errorReader.close(); | ||
} | ||
} |
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