/** * 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; } }
private void echoAvailableData(NIOReader in, NIOWriter out, char[] buf) throws IOException { while(in.isReady()) { int len = in.read(buf); out.write(buf, 0, len); } }
@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) }); } });