/** * Adds one byte to the buffer and throws an exception if the buffer is * full. * @param b Byte to add to the buffer. * @throws BufferIsFullException If the buffer is full and the byte cannot * be stored. */ public void add(byte b) throws BufferIsFullException { if (isFull()) { throw new BufferIsFullException("Buffer is full and has reached maximum capacity (" + capacity() + ")"); } // buffer is not full this.buffer[this.currentWritePosition] = b; this.currentWritePosition = (this.currentWritePosition + 1) % this.buffer.length; this.currentBufferSize += 1; }
/** * Adds one byte to the buffer and throws an exception if the buffer is * full. * @param b Byte to add to the buffer. * @throws BufferIsFullException If the buffer is full and the byte cannot * be stored. */ public void add(byte b) throws BufferIsFullException { if (isFull()) { throw new BufferIsFullException("Buffer is full and has reached maximum capacity (" + capacity() + ")"); } // buffer is not full this.buffer[this.currentWritePosition] = b; this.currentWritePosition = (this.currentWritePosition + 1) % this.buffer.length; this.currentBufferSize += 1; }