@Test public void shouldCloseChannelWhenEndOfStreamIsReached() throws Exception { expectEndOfInputStream(); mockery.checking(new Expectations() { { one(readableByteChannel).isOpen(); will(returnValue(true)); one(readableByteChannel).close(); one(connectionObserver).connectionClosed(); } }); inputStreamReader.blockingStart(readableByteChannel); }
public void blockingStart(final ReadableByteChannel readableByteChannel) { try { while ((readableByteChannel.read(buffer)) != -1) { blocker.mayWait(); buffer.flip(); byteStreamMessageParser.parse(buffer); buffer.clear(); } } catch (final ClosedChannelException e) { } catch (final IOException e) { LOGGER.error("An error occurred trying to read from the socket", e); } finally { if (readableByteChannel != null) { try { if (readableByteChannel.isOpen()) { readableByteChannel.close(); } } catch (IOException e) { } connectionObserver.connectionClosed(); } } }
ByteChannelReader { public void blockingStart(final ReadableByteChannel readableByteChannel) { try { while ((readableByteChannel.read(buffer)) != -1) { blocker.mayWait(); buffer.flip(); byteStreamMessageParser.parse(buffer); buffer.clear(); } } catch (final ClosedChannelException e) { } catch (final IOException e) { LOGGER.error("An error occurred trying to read from the socket", e); } finally { if (readableByteChannel != null) { try { if (readableByteChannel.isOpen()) { readableByteChannel.close(); } } catch (IOException e) { } connectionObserver.connectionClosed(); } } } }
ByteChannelReader { public void blockingStart(final ReadableByteChannel readableByteChannel) { try { while ((readableByteChannel.read(buffer)) != -1) { blocker.mayWait(); buffer.flip(); byteStreamMessageParser.parse(buffer); buffer.clear(); } } catch (final ClosedChannelException e) { } catch (final IOException e) { LOGGER.error("An error occurred trying to read from the socket", e); } finally { if (readableByteChannel != null) { try { if (readableByteChannel.isOpen()) { readableByteChannel.close(); } } catch (IOException e) { } connectionObserver.connectionClosed(); } } } ByteChannelReader(final ByteStreamMessageParser byteStreamMessageParser, final Blocker blocker, final ConnectionObserver connectionObserver); }
ByteChannelReader { public void blockingStart(final ReadableByteChannel readableByteChannel) { try { while ((readableByteChannel.read(buffer)) != -1) { blocker.mayWait(); buffer.flip(); byteStreamMessageParser.parse(buffer); buffer.clear(); } } catch (final ClosedChannelException e) { } catch (final IOException e) { LOGGER.error("An error occurred trying to read from the socket", e); } finally { if (readableByteChannel != null) { try { if (readableByteChannel.isOpen()) { readableByteChannel.close(); } } catch (IOException e) { } connectionObserver.connectionClosed(); } } } ByteChannelReader(final ByteStreamMessageParser byteStreamMessageParser, final Blocker blocker, final ConnectionObserver connectionObserver); void blockingStart(final ReadableByteChannel readableByteChannel); }
ByteChannelReader { public void blockingStart(final ReadableByteChannel readableByteChannel) { try { while ((readableByteChannel.read(buffer)) != -1) { blocker.mayWait(); buffer.flip(); byteStreamMessageParser.parse(buffer); buffer.clear(); } } catch (final ClosedChannelException e) { } catch (final IOException e) { LOGGER.error("An error occurred trying to read from the socket", e); } finally { if (readableByteChannel != null) { try { if (readableByteChannel.isOpen()) { readableByteChannel.close(); } } catch (IOException e) { } connectionObserver.connectionClosed(); } } } ByteChannelReader(final ByteStreamMessageParser byteStreamMessageParser, final Blocker blocker, final ConnectionObserver connectionObserver); void blockingStart(final ReadableByteChannel readableByteChannel);  }