/** * Get the next buffer without changing the position * * @return * @throws IOException */ private MessageBuffer getNextBuffer() throws IOException { MessageBuffer next = in.next(); if (next == null) { throw new MessageInsufficientBufferException(); } assert (buffer != null); totalReadBytes += buffer.size(); return next; }
/** * Peeks a Nil byte and reads it if next byte is a nil value. * * The difference from {@link unpackNil} is that unpackNil throws an exception if the next byte is not nil value * while this tryUnpackNil method returns false without changing position. * * @return true if a nil value is read * @throws MessageInsufficientBufferException when the end of file reached * @throws IOException when underlying input throws IOException */ public boolean tryUnpackNil() throws IOException { // makes sure that buffer has at least 1 byte if (!ensureBuffer()) { throw new MessageInsufficientBufferException(); } byte b = buffer.getByte(position); if (b == Code.NIL) { readByte(); return true; } return false; }
/** * Returns format of the next value. * * <p> * Note that this method doesn't consume data from the internal buffer unlike the other unpack methods. * Calling this method twice will return the same value. * * <p> * To not throw {@link MessageInsufficientBufferException}, this method should be called only when * {@link #hasNext()} returns true. * * @return the next MessageFormat * @throws IOException when underlying input throws IOException * @throws MessageInsufficientBufferException when the end of file reached, i.e. {@link #hasNext()} == false. */ public MessageFormat getNextFormat() throws IOException { // makes sure that buffer has at least 1 byte if (!ensureBuffer()) { throw new MessageInsufficientBufferException(); } byte b = buffer.getByte(position); return MessageFormat.valueOf(b); }