package org.eclipse.linuxtools.ctf.core.event.io;
-import java.nio.BufferOverflowException;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
+import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException;
+
/**
* <b><u>BitBuffer</u></b>
* <p>
* byte order.
*
* @return The int value read from the buffer
+ * @throws CTFReaderException
+ * An error occurred reading the data. When the buffer is read
+ * beyond its end, this exception will be raised.
*/
- public int getInt() {
+ public int getInt() throws CTFReaderException {
return getInt(BIT_INT, true);
}
* @param signed
* The sign extended flag
* @return The int value read from the buffer
+ * @throws CTFReaderException
+ * An error occurred reading the data. When the buffer is read
+ * beyond its end, this exception will be raised.
*/
- public int getInt(int length, boolean signed) {
+ public int getInt(int length, boolean signed) throws CTFReaderException {
/* Nothing to read. */
if (length == 0) {
/* Validate that the buffer has enough bits. */
if (!canRead(length)) {
- throw new BufferOverflowException();
+ throw new CTFReaderException("Cannot read the integer, " + //$NON-NLS-1$
+ "the buffer does not have enough remaining space. " + //$NON-NLS-1$
+ "Requested:" + length); //$NON-NLS-1$
}
/* Get the value from the byte buffer. */
*
* @param value
* The int value to write
+ * @throws CTFReaderException
+ * An error occurred writing the data. If the buffer is written
+ * beyond its end, this exception will be raised.
*/
- public void putInt(int value) {
+ public void putInt(int value) throws CTFReaderException {
putInt(BIT_INT, value);
}
* The number of bits to write
* @param value
* The value to write
+ * @throws CTFReaderException
+ * An error occurred writing the data. If the buffer is written
+ * beyond its end, this exception will be raised.
*/
- public void putInt(int length, int value) {
+ public void putInt(int length, int value) throws CTFReaderException {
final long curPos = this.pos;
if (!canRead(length)) {
- throw new BufferOverflowException();
+ throw new CTFReaderException("Cannot write to bitbuffer, " //$NON-NLS-1$
+ + "insufficient space. Requested: " + length); //$NON-NLS-1$
}
if (length == 0) {
return;