title: Parsing multiple JSONs from ByteBuffer
body: <p>I've got pure and simple Java Nio Socket Server. Data transfer realized with JSON. With 1 clien all work fine, but when i am trying to start workload test - some problem appeared. Here is my method for parsing incoming ByteBuffer (MessageFromBuffer is just a wrapper for byte[]):</p>
  
  <pre><code>private JSONObject parseIncomingMessageToJson(MessageFromBuffer messageFromBuffer) {
          int size = messageFromBuffer.getSize();
          byte[] data = messageFromBuffer.getData();
  
          byte[] dataCopy = new byte[size];
          System.arraycopy(data, 0, dataCopy, 0, size);
  
          JSONParser jsonParser = new JSONParser();
          JSONObject jsonMessage = null;
  
          try {
              jsonMessage = (JSONObject) jsonParser.parse(new String(dataCopy));
          } catch (ParseException pe) {
              System.out.println("Error formatting incoming message to json:  " + new String(messageFromBuffer.getData()));
          }
  
          return jsonMessage;
      }
  </code></pre>
  
  <p>When buffer cosists of only one json entity - all works fine. But during 100 clients attack, buffer can be populated with multiple json enities, as shown (All testing clients send same data):</p>
  
  <pre><code>Error formatting incoming message to json:  {"TYPE":"REGISTRATION","LOGIN":"Padre","PASSWORD":"3214"}
  {"TYPE":"REGISTRATION","LOGIN":"Padre","PASSWORD":"3214"}
  {"TYPE":"REGISTRATION","LOGIN":"Padre","PASSWORD":"3214"}
  {"TYPE":"REGISTRATION","LOGIN":"Padre","PASSWORD":"3214"}
  {"TYPE":"REGISTRATION","LOGIN":"Padre","PASSWORD":"3214"}
  {"TYPE":"REGISTRATION","LOGIN":"Padre","PASSWORD":"3214"}
  {"TYPE":"REGISTRATION","LOGIN":"Padre","PASSWORD":"3214"}
  {"TYPE":"REGISTRATION","LOGIN":"Padre","PASSWORD":"3214"}
  {"TYPE":"REGISTRATION","LOGIN":"Padre","PASSWORD":"3214"}
  </code></pre>
  
  <p>Method throws exception and returns with nothing. After each read from SOcketChanel i clear buffer - so all those messages are lost. Are there some techniques for proper JSON parsing in such situation?</p>