@Override public void onDataAvailable() throws Exception { System.out.printf("[onDataAvailable] echoing %d bytes\n", in.readyData()); echoAvailableData(in, out, buf); in.notifyAvailable(this); }
@Override public void onError(Throwable t) { try { nioReader.close(); } catch (IOException ignored) {} }
/** * 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 onDataAvailable() throws Exception { inputBuffer = appendAvailableDataToBuffer(in, inputBuffer); in.notifyAvailable(this); }
@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(); } } });
final StringBuffer value = new StringBuffer(); final NIOReader nr = me.getNIOReader(); nr.notifyAvailable(new ReadHandler()
in.notifyAvailable(new ReadHandler() { private char[] inputBuffer = new char[0];
@Override public void onError(Throwable t) { try { nioReader.close(); } catch (IOException ignored) {} }
in.notifyAvailable(new ReadHandler() {
String incomingMessageAsString = new String(inputBuffer); try { in.close(); } catch (Exception ignored) {
nioReader.notifyAvailable(new ReadHandler() { @Override public void onDataAvailable() throws Exception {
nioReader.notifyAvailable(new ReadHandler() { @Override public void onDataAvailable() throws Exception {