ctf: Throw CTFReaderException in the BitBuffer API
[deliverable/tracecompass.git] / org.eclipse.linuxtools.ctf.core / src / org / eclipse / linuxtools / ctf / core / event / io / BitBuffer.java
index d97eb5f3f52fb3a5eec6b3c3f6af199731ff2c2a..8be895442734d12281064975eb89acc8d1215163 100644 (file)
 
 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>
@@ -95,8 +96,11 @@ public final class BitBuffer {
      * 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);
     }
 
@@ -112,8 +116,11 @@ public final class BitBuffer {
      * @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) {
@@ -122,7 +129,9 @@ public final class BitBuffer {
 
         /* 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. */
@@ -294,8 +303,11 @@ public final class BitBuffer {
      *
      * @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);
     }
 
@@ -312,12 +324,16 @@ public final class BitBuffer {
      *            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;
This page took 0.029539 seconds and 5 git commands to generate.