* @author niki
*/
abstract class ConnectAction {
+ // We separate each "packet" we send with this character and make sure it
+ // does not occurs in the message itself.
+ static private char STREAM_SEP = '\b';
+ static private String[] STREAM_RAW = new String[] { "\\", "\b" };
+ static private String[] STREAM_CODED = new String[] { "\\\\", "\\b" };
+
private Socket s;
private boolean server;
*/
public void connect() {
try {
- // TODO: assure that \b is never used, make sure \n usage is OK
in = new NextableInputStream(s.getInputStream(),
- new NextableInputStreamStep('\b'));
-
+ new NextableInputStreamStep(STREAM_SEP));
try {
out = new BufferedOutputStream(s.getOutputStream());
-
try {
action();
} finally {
sub = out.open();
}
- // TODO: could be possible to check for non-crypt and only
- // do it for crypt
- sub = new ReplaceOutputStream(sub, //
- new String[] { "\\", "\b" }, //
- new String[] { "\\\\", "\\b" });
-
+ sub = new ReplaceOutputStream(sub, STREAM_RAW, STREAM_CODED);
try {
if (asString) {
sub.write(StringUtils.getBytes(data.toString()));
sub.close();
}
- out.write('\b');
+ out.write(STREAM_SEP);
if (server) {
out.flush();
}
if (in.next() && !in.eof()) {
- // TODO: could be possible to check for non-crypt and only
- // do it for crypt
- InputStream read = new ReplaceInputStream(in.open(), //
- new String[] { "\\\\", "\\b" }, //
- new String[] { "\\", "\b" });
-
+ InputStream read = new ReplaceInputStream(in.open(),
+ STREAM_CODED, STREAM_RAW);
try {
if (crypt != null) {
read = crypt.decrypt64(read);