/** * Counts {@link #processRequests(java.util.List)}. send and received bytes. * * @thread it assumes that client is not run in paralel. */ public long getCounter() { long ret = 0; if (loggedDataInputStream != null) { ret += loggedDataInputStream.getCounter(); } if (loggedDataOutputStream != null) { ret += loggedDataOutputStream.getCounter(); } return ret; }
/** * Handle the response from a request. * * @throws ResponseException if there is a problem reading the response */ private void handleResponse() throws ResponseException, CommandAbortedException { try { LoggedDataInputStream dis = connection.getInputStream(); loggedDataInputStream = dis; int ch = -1; try { ch = dis.read(); } catch (InterruptedIOException ex) { abort(); } while (!abort && ch != -1) { StringBuffer responseNameBuffer = new StringBuffer(); // read in the response name while (ch != -1 && (char) ch != '\n' && (char) ch != ' ') { responseNameBuffer.append((char) ch); try { ch = dis.read(); } catch (InterruptedIOException ex) { abort(); break; } } String responseString = responseNameBuffer.toString(); Response response = getResponseFactory().createResponse(responseString); // Logger.logInput(new String("<" + responseString + " processing start>\n").getBytes()); // // NOI18N response.process(dis, this); boolean terminal = response.isTerminalResponse(); // handle SpecialResponses if (terminal && response instanceof ErrorMessageResponse) { ErrorMessageResponse errorResponce = (ErrorMessageResponse) response; String errMsg = errorResponce.getMessage(); throw new CommandAbortedException(errMsg, errMsg); } // Logger.logInput(new String("<" + responseString + " processed " + terminal + // ">\n").getBytes()); // NOI18N if (terminal || abort) { break; } try { ch = dis.read(); } catch (InterruptedIOException ex) { abort(); break; } } if (abort) { String localMsg = CommandException.getLocalMessage("Client.commandAborted", null); // NOI18N throw new CommandAbortedException("Aborted during request processing", localMsg); // NOI18N } } catch (EOFException ex) { throw new ResponseException( ex, ResponseException.getLocalMessage("CommandException.EndOfFile", null)); // NOI18N } catch (IOException ex) { throw new ResponseException(ex); } }