DefaultRpcMessageReader implements RpcMessageReader { public String readServerPacket() throws RpcException { try { int numChars = reader.read(); if (numChars < 0) { try { Thread.sleep(100); } catch (InterruptedException e) { } numChars = reader.read(); if (numChars < 0) { throw new EOFException(); } } if (numChars == 0) return ""; char[] buf = new char[numChars]; reader.read(buf); return new String(buf); } catch (InterruptedIOException e) { throw new TimeoutWaitingForRpcResponseException(e); } catch (IOException e) { throw new RpcIoException("unable to read server packet", e); } } DefaultRpcMessageReader(final Reader r); RpcResponse readResponse(); String readServerPacket();  }
@Test public void testReadServerPacket() throws RpcException { StringReader s = new StringReader("\u0003foo\u0003bar"); DefaultRpcMessageReader r = new DefaultRpcMessageReader(s); assertEquals("foo", r.readServerPacket()); assertEquals("bar", r.readServerPacket()); }
@Test public void testReadServerPacketZeroLength() throws RpcException { StringReader s = new StringReader("\u0000"); DefaultRpcMessageReader r = new DefaultRpcMessageReader(s); assertEquals("", r.readServerPacket()); }