X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Futils%2Fserial%2Fserver%2FConnectAction.java;h=0f2f1b4319fa799950119815c31dd9bf81043ee8;hb=29fd216d455363af8bd4adb1e3325645b0ba7fb5;hp=c02d734f8a95ee34fc9b3e116c5f8357dbd02940;hpb=bd86c2218b4a8befeb9b2789b62e1697993f0b5b;p=nikiroo-utils.git diff --git a/src/be/nikiroo/utils/serial/server/ConnectAction.java b/src/be/nikiroo/utils/serial/server/ConnectAction.java index c02d734..0f2f1b4 100644 --- a/src/be/nikiroo/utils/serial/server/ConnectAction.java +++ b/src/be/nikiroo/utils/serial/server/ConnectAction.java @@ -28,6 +28,12 @@ import be.nikiroo.utils.streams.ReplaceOutputStream; * @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; @@ -99,13 +105,10 @@ abstract class ConnectAction { */ 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 { @@ -294,12 +297,7 @@ abstract class ConnectAction { 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())); @@ -310,7 +308,7 @@ abstract class ConnectAction { sub.close(); } - out.write('\b'); + out.write(STREAM_SEP); if (server) { out.flush(); @@ -376,13 +374,9 @@ abstract class ConnectAction { contentToSend = false; } - if (in.next()) { - // 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" }); - + if (in.next() && !in.eof()) { + InputStream read = new ReplaceInputStream(in.open(), + STREAM_CODED, STREAM_RAW); try { if (crypt != null) { read = crypt.decrypt64(read);