NonBlocking { public static NonBlockingPumpReader nonBlockingPumpReader() { return new NonBlockingPumpReader(); }  static NonBlockingPumpReader nonBlockingPumpReader(); static NonBlockingPumpReader nonBlockingPumpReader(int size); static NonBlockingPumpInputStream nonBlockingPumpInputStream(); static NonBlockingPumpInputStream nonBlockingPumpInputStream(int size); static NonBlockingInputStream nonBlockingStream(NonBlockingReader reader, Charset encoding); static NonBlockingInputStream nonBlocking(String name, InputStream inputStream); static NonBlockingReader nonBlocking(String name, Reader reader); static NonBlockingReader nonBlocking(String name, InputStream inputStream, Charset encoding);  }
@Test public void testNonBlockingPumpReader() throws IOException { NonBlockingPumpReader nbr = NonBlocking.nonBlockingPumpReader(); Writer writer = nbr.getWriter(); assertEquals(NonBlockingReader.READ_EXPIRED, nbr.read(100)); writer.write('中'); assertEquals('中', nbr.read(100)); assertEquals(NonBlockingReader.READ_EXPIRED, nbr.read(100)); long t0 = System.currentTimeMillis(); new Thread(() -> { try { Thread.sleep(100); writer.write('中'); } catch (Exception e) { fail(); } }).start(); int c = nbr.read(0); long t1 = System.currentTimeMillis(); assertEquals('中', c); assertTrue(t1 - t0 >= 100); }