/** * Tests if the buffer is full. * @return True if the buffer is full, otherwise false. */ public boolean isFull() { return (size() == capacity()); }
/** * Tests if the buffer is full. * @return True if the buffer is full, otherwise false. */ public boolean isFull() { return (size() == capacity()); }
/** * Gets the number of free bytes this buffer has remaining for writing. * @return The number of bytes available for writing in this buffer. */ public int free() { return capacity()-size(); }
/** * Gets the number of free bytes this buffer has remaining for writing. * @return The number of bytes available for writing in this buffer. */ public int free() { return capacity()-size(); }
/** * Deletes the first N bytes of the buffer. Avoids allocating any memory * since there is no return value for this method. If you want to delete * and also see the deleted data as a return value, please use the remove() * methods. */ public void delete(int count) throws BufferSizeException { if ((count < 0) || (count > capacity())) { throw new IllegalArgumentException("Can only delete between 0 and " + capacity() + " bytes from buffer, you passed in=" + count); } if (count > size()) { throw new BufferSizeException("Buffer size (" + size() + ") not large enough to delete (" + count + ") bytes"); } this.currentReadPosition = (this.currentReadPosition + count) % this.buffer.length; this.currentBufferSize -= count; }
/** * Deletes the first N bytes of the buffer. Avoids allocating any memory * since there is no return value for this method. If you want to delete * and also see the deleted data as a return value, please use the remove() * methods. */ public void delete(int count) throws BufferSizeException { if ((count < 0) || (count > capacity())) { throw new IllegalArgumentException("Can only delete between 0 and " + capacity() + " bytes from buffer, you passed in=" + count); } if (count > size()) { throw new BufferSizeException("Buffer size (" + size() + ") not large enough to delete (" + count + ") bytes"); } this.currentReadPosition = (this.currentReadPosition + count) % this.buffer.length; this.currentBufferSize -= count; }
/** * Gets the byte at the given index relative to the beginning the circular * buffer. The index must be a value between 0 and the buffer capacity. * @param index The index of the byte relative to the beginning the buffer * (a value between 0 and the the current size). * @return The byte at the given position relative to the beginning the buffer. * @throws BufferSizeException If the index is >= size() */ public byte get(int index) throws IllegalArgumentException, BufferSizeException { if ((index < 0) || (index >= capacity())) { throw new IllegalArgumentException("The buffer index must be a value between 0 and " + capacity() + "!"); } if (index >= size()) { throw new BufferSizeException("Index " + index + " is >= buffer size of " + size()); } return this.buffer[(this.currentReadPosition + index) % this.buffer.length]; }
/** * Gets the byte at the given index relative to the beginning the circular * buffer. The index must be a value between 0 and the buffer capacity. * @param index The index of the byte relative to the beginning the buffer * (a value between 0 and the the current size). * @return The byte at the given position relative to the beginning the buffer. * @throws BufferSizeException If the index is >= size() */ public byte get(int index) throws IllegalArgumentException, BufferSizeException { if ((index < 0) || (index >= capacity())) { throw new IllegalArgumentException("The buffer index must be a value between 0 and " + capacity() + "!"); } if (index >= size()) { throw new BufferSizeException("Index " + index + " is >= buffer size of " + size()); } return this.buffer[(this.currentReadPosition + index) % this.buffer.length]; }
/** * 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; }