@Override public void onDataAvailable() throws Exception { System.out.printf("[onDataAvailable] echoing %d bytes\n", in.readyData()); echoAvailableData(in, out, buf); in.notifyAvailable(this); }
/** * Non-blockingly reads all (non blockingly) available characters of the passed InputReader and * concats those characters to the passed <currentBuffer>, returning a new character array */ private static char[] appendAvailableDataToBuffer(NIOReader in, char currentBuffer[]) throws IOException { // we are not synchronizing here, since we assume that onDataAvailable() is called sequentially char[] readBuffer = new char[in.readyData()]; int numRead = in.read(readBuffer); if (numRead <= 0) { return currentBuffer; } else { char[] retVal = new char[currentBuffer.length + numRead]; System.arraycopy(currentBuffer, 0, retVal, 0, currentBuffer.length); System.arraycopy(readBuffer, 0, retVal, currentBuffer.length, numRead); return retVal; } }
@Override public void onAllDataRead() throws Exception { final char[] chars = new char[nioReader.readyData()]; nioReader.read(chars); formParams.addParameterValues(paramName, new String[] { new String(chars) }); } });
@Override public void onAllDataRead() throws Exception { final char[] chars = new char[nioReader.readyData()]; nioReader.read(chars); formParams.addParameterValues(paramName, new String[] { new String(chars) }); } });
@Override public void onAllDataRead() throws Exception { System.out.printf("[onAllDataRead] length: %d\n", in.readyData()); try { echoAvailableData(in, out, buf); } finally { try { in.close(); } catch (IOException ignored) { } try { out.close(); } catch (IOException ignored) { } response.resume(); } } });