public Message peek ( ) throws IOException { Messages msgs = peek ( 1 ) ; Message msg ; try { msg = msgs . getMessage ( 0 ) ; } catch ( IndexOutOfBoundsException e ) { throw new EmptyQueueException ( ) ; } return msg ; }
Peeking at a queue returns the next messages on the queue but it does not reserve them . If there are no items on the queue an EmptyQueueException is thrown .