X-Git-Url: http://git.nikiroo.be/?p=nikiroo-utils.git;a=blobdiff_plain;f=src%2Fbe%2Fnikiroo%2Futils%2Fserial%2Fserver%2FConnectAction.java;h=cef10adf1c80736a4603c8d99c1fe4c82710d480;hp=39417a77fca5c7671afd7d932d12cc22d4115397;hb=4bb7e88e5165691ed1c14d93b4bb0a9fbe811090;hpb=5795c978b9308afeb07e1cd41b0067c8278427c3 diff --git a/src/be/nikiroo/utils/serial/server/ConnectAction.java b/src/be/nikiroo/utils/serial/server/ConnectAction.java index 39417a7..cef10ad 100644 --- a/src/be/nikiroo/utils/serial/server/ConnectAction.java +++ b/src/be/nikiroo/utils/serial/server/ConnectAction.java @@ -32,6 +32,9 @@ abstract class ConnectAction { private OutputStreamWriter out; private boolean contentToSend; + private long bytesReceived; + private long bytesSent; + /** * Method that will be called when an action is performed on either the * client or server this {@link ConnectAction} represent. @@ -99,13 +102,31 @@ abstract class ConnectAction { return version; } + /** + * The total amount of bytes received. + * + * @return the amount of bytes received + */ + public long getBytesReceived() { + return bytesReceived; + } + + /** + * The total amount of bytes sent. + * + * @return the amount of bytes sent + */ + public long getBytesSent() { + return bytesSent; + } + /** * Actually start the process (this is synchronous). */ public void connect() { try { - in = new BufferedReader( - new InputStreamReader(s.getInputStream(), "UTF-8")); + in = new BufferedReader(new InputStreamReader(s.getInputStream(), + "UTF-8")); try { out = new OutputStreamWriter(s.getOutputStream(), "UTF-8"); try { @@ -151,11 +172,10 @@ abstract class ConnectAction { ciphers += cipher; } - e = new SSLException( - "SSL error (available SSL ciphers: " + ciphers + ")", - e); + e = new SSLException("SSL error (available SSL ciphers: " + + ciphers + ")", e); } - + onError(e); } finally { try { @@ -188,12 +208,11 @@ abstract class ConnectAction { * @throws ClassNotFoundException * if a class described in the serialised data cannot be found */ - protected Object sendObject(Object data) - throws IOException, NoSuchFieldException, NoSuchMethodException, - ClassNotFoundException { + protected Object sendObject(Object data) throws IOException, + NoSuchFieldException, NoSuchMethodException, ClassNotFoundException { synchronized (lock) { - String rep = sendString( - new Exporter().append(data).toString(true, true)); + String rep = sendString(new Exporter().append(data).toString(true, + true)); if (rep != null) { return new Importer().read(rep).getValue(); } @@ -226,9 +245,9 @@ abstract class ConnectAction { * @throws java.lang.NullPointerException * if the counter part has no data to send */ - protected Object recObject() - throws IOException, NoSuchFieldException, NoSuchMethodException, - ClassNotFoundException, java.lang.NullPointerException { + protected Object recObject() throws IOException, NoSuchFieldException, + NoSuchMethodException, ClassNotFoundException, + java.lang.NullPointerException { String str = recString(); if (str == null) { throw new NullPointerException("No more data available"); @@ -254,6 +273,7 @@ abstract class ConnectAction { synchronized (lock) { out.write(line); out.write("\n"); + bytesSent += line.length() + 1; if (server) { out.flush(); @@ -287,7 +307,12 @@ abstract class ConnectAction { contentToSend = false; } - return in.readLine(); + String line = in.readLine(); + if (line != null) { + bytesReceived += line.length(); + } + + return line; } return null;