protected final In in;
protected final Out out;
- private StringBuffer log = loggingEnabled ? new StringBuffer(16 * 1024) : null;
private String newLine = "\r\n";
private Stream in_next = null;
return this;
}
- //public static boolean loggingEnabled = "true".equals(System.getProperty("ibex.io.stream.logEnabled", "false"));
- public static boolean loggingEnabled = true;
-
public void transcribe(Stream out) { transcribe(out, false); }
public void transcribe(Stream out, boolean close) {
try {
public char getc() {
flush();
char ret = in.getc(false);
- log(ret);
return ret;
}
public String readln() {
flush();
String s = in.readln();
- log(s);
- log('\n');
return s;
}
public void print(String s) {
- logWrite(s);
out.write(s);
flush();
}
public void println(String s) {
- logWrite(s);
- logWrite(newLine);
out.write(s);
out.write(newLine);
flush();
public int read(byte[] b, int off, int len) {
flush();
int ret = in.readBytes(b, off, len);
- if (log != null) log("\n[read " + ret + " bytes of binary data ]\n");
nnl = false;
return ret;
}
public int read(char[] c, int off, int len) {
flush();
int ret = in.read(c, off, len);
- if (log != null && ret != -1) log(new String(c, off, ret));
return ret;
}
/** dumps the connection log into a file */
- public String dumpLog() { if (log==null) return ""; String ret = log.toString(); log = new StringBuffer(16 * 1024); return ret; }
- private void log(String s) { if(log==null) return; if (!nnl) Log.note("\n[read ] "); Log.note(s + "\n"); nnl=false; if (log != null) log.append(s); }
- private void logWrite(String s) { if(log==null) return; if (nnl) Log.note("\n"); Log.note("[write] "+s+"\n"); nnl=false; if (log != null) log.append(s); }
- private void log(char c) { if(log==null) return; if (c == '\r') return; if (!nnl) Log.note("[read ] "); Log.note(c+""); nnl = c != '\n'; if (log != null) log.append(c); }
private boolean nnl = false;
private static class Out extends BufferedOutputStream {
}
}
- public static interface Transformer {
- public Stream transform(Stream in);
- }
-
}