X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;ds=sidebyside;f=src%2Fbe%2Fnikiroo%2Futils%2Fserial%2Fserver%2FConnectAction.java;h=8dbc7aa22ce195383f2c82cd225dd9f042e25b14;hb=4d31956549a05df6dca42d58a1150a348a58dcd1;hp=a377ced597f2a6bd84d01fd008f7f5099b9409a3;hpb=9af739b58e2cd5357a21d6fd0410049ab2a2bff3;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 a377ced..8dbc7aa 100644 --- a/src/be/nikiroo/utils/serial/server/ConnectAction.java +++ b/src/be/nikiroo/utils/serial/server/ConnectAction.java @@ -199,8 +199,9 @@ abstract class ConnectAction { * @param data * the data to send * - * @return the answer (which can be NULL) if this action is a client, always - * NULL if it is a server + * @return the answer (which can be NULL if no answer, or NULL for an answer + * which is NULL) if this action is a client, always NULL if it is a + * server * * @throws IOException * in case of I/O error @@ -216,10 +217,18 @@ abstract class ConnectAction { protected Object sendObject(Object data) throws IOException, NoSuchFieldException, NoSuchMethodException, ClassNotFoundException { synchronized (lock) { - String rep = sendString(new Exporter().append(data).toString(true, - true)); - if (rep != null) { - return new Importer().read(rep).getValue(); + new Exporter(out).append(data); + + if (server) { + out.flush(); + return null; + } + + contentToSend = true; + try { + return recObject(); + } catch (NullPointerException e) { + // We accept no data here } return null; @@ -253,12 +262,18 @@ abstract class ConnectAction { protected Object recObject() throws IOException, NoSuchFieldException, NoSuchMethodException, ClassNotFoundException, java.lang.NullPointerException { - String str = recString(); - if (str == null) { - throw new NullPointerException("No more data available"); - } + synchronized (lock) { + if (server || contentToSend) { + if (contentToSend) { + out.flush(); + contentToSend = false; + } - return new Importer().read(str).getValue(); + return new Importer().read(in).getValue(); + } + + return null; + } } /** @@ -365,15 +380,15 @@ abstract class ConnectAction { */ private void writeLine(OutputStream out, String line) throws IOException { if (crypt == null) { - out.write(line.getBytes()); + out.write(line.getBytes("UTF-8")); bytesSent += line.length(); } else { // TODO: how NOT to create so many big Strings? String b64 = crypt.encrypt64(line, false); - out.write(b64.getBytes()); + out.write(b64.getBytes("UTF-8")); bytesSent += b64.length(); } - out.write("\n".getBytes()); + out.write("\n".getBytes("UTF-8")); bytesSent++; } } \ No newline at end of file