@Test public void shouldReadInteger() throws Exception { Channel channel = new Channel( new byte[] {(byte) 0xff, 0x01, 0x02, 0x03, 0x04, ':'}, 1 ); EventConsumerThread thread = new EventConsumerThread( "t", channel, new MockEventHandler<Event>(), COUNTDOWN_CLOSEABLE, new MockForkNodeArguments() ); Memento memento = thread.new Memento(); memento.bb.position( 0 ).limit( 0 ); assertThat( thread.readInteger( memento ) ) .isEqualTo( new BigInteger( new byte[] {0x01, 0x02, 0x03, 0x04} ).intValue() ); }
protected Integer readInteger( Memento memento ) throws IOException, MalformedFrameException { read( memento, BYTE_LENGTH ); boolean isNullObject = memento.bb.get() == 0; if ( isNullObject ) { read( memento, DELIMITER_LENGTH ); checkDelimiter( memento ); return null; } return readInt( memento ); }
EventConsumerThread extends CloseableDaemonThread { protected Integer readInteger( Memento memento ) throws IOException, MalformedFrameException { read( memento, BYTE_LENGTH ); boolean isNullObject = memento.bb.get() == 0; if ( isNullObject ) { read( memento, DELIMITER_LENGTH ); checkDelimiter( memento ); return null; } return readInt( memento ); } }
EventConsumerThread extends CloseableDaemonThread { protected Integer readInteger( Memento memento ) throws IOException, MalformedFrameException { read( memento, BYTE_LENGTH ); boolean isNullObject = memento.bb.get() == 0; if ( isNullObject ) { read( memento, DELIMITER_LENGTH ); checkDelimiter( memento ); return null; } return readInt( memento ); } EventConsumerThread( @Nonnull String threadName,
                                @Nonnull ReadableByteChannel channel,
                                @Nonnull EventHandler<Event> eventHandler,
                                @Nonnull CountdownCloseable countdownCloseable,
                                @Nonnull ForkNodeArguments arguments ); }
EventConsumerThread extends CloseableDaemonThread { protected Integer readInteger( Memento memento ) throws IOException, MalformedFrameException { read( memento, BYTE_LENGTH ); boolean isNullObject = memento.bb.get() == 0; if ( isNullObject ) { read( memento, DELIMITER_LENGTH ); checkDelimiter( memento ); return null; } return readInt( memento ); } EventConsumerThread( @Nonnull String threadName,
                                @Nonnull ReadableByteChannel channel,
                                @Nonnull EventHandler<Event> eventHandler,
                                @Nonnull CountdownCloseable countdownCloseable,
                                @Nonnull ForkNodeArguments arguments ); @Override void run(); @Override void disable(); @Override void close(); }
EventConsumerThread extends CloseableDaemonThread { protected Integer readInteger( Memento memento ) throws IOException, MalformedFrameException { read( memento, BYTE_LENGTH ); boolean isNullObject = memento.bb.get() == 0; if ( isNullObject ) { read( memento, DELIMITER_LENGTH ); checkDelimiter( memento ); return null; } return readInt( memento ); } EventConsumerThread( @Nonnull String threadName,
                                @Nonnull ReadableByteChannel channel,
                                @Nonnull EventHandler<Event> eventHandler,
                                @Nonnull CountdownCloseable countdownCloseable,
                                @Nonnull ForkNodeArguments arguments ); @Override void run(); @Override void disable(); @Override void close();  }