import java.nio.ByteBuffer;
import java.nio.ByteOrder;
+import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.linuxtools.ctf.core.event.io.BitBuffer;
import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException;
import org.junit.Before;
/**
* Perform pre-test initialization.
- * @throws CTFReaderException An error that cannot happen (position is under 128)
+ *
+ * @throws CTFReaderException
+ * An error that cannot happen (position is under 128)
*/
@Before
public void setUp() throws CTFReaderException {
ByteOrder byteOrder = ByteOrder.BIG_ENDIAN;
fixture.setByteOrder(byteOrder);
}
+
+ /**
+ * Test the get function
+ */
+ @Test
+ public void testGetBytes() {
+ @NonNull byte[] data = new byte[2];
+ ByteBuffer bb = ByteBuffer.allocate(10);
+ bb.put((byte) 0);
+ bb.put((byte) 1);
+ bb.put((byte) 1);
+ bb.put((byte) 0);
+ fixture = new BitBuffer(bb);
+ fixture.get(data);
+ assertEquals(0, data[0]);
+ assertEquals(1, data[1]);
+ fixture.get(data);
+ assertEquals(1, data[0]);
+ assertEquals(0, data[1]);
+ }
+
+ /**
+ * Test the get function
+ *
+ * @throws CTFReaderException
+ * won't happen but we seek in a buffer
+ */
+ @Test
+ public void testGetBytesMiddle() throws CTFReaderException {
+ @NonNull byte[] data = new byte[5];
+ // this string has been carefully selected and tested... don't change
+ // the string and expect the result to be the same.
+ ByteBuffer bb = ByteBuffer.wrap(new String("hello world").getBytes());
+ fixture = new BitBuffer(bb);
+ fixture.position(6 * 8);
+ fixture.get(data);
+ String actual = new String(data);
+ assertEquals("world", actual);
+ }
}
\ No newline at end of file
Bundle-ManifestVersion: 2
Bundle-Name: %Bundle-Name
Bundle-Vendor: %Bundle-Vendor
-Bundle-Version: 3.0.0.qualifier
+Bundle-Version: 3.1.0.qualifier
Bundle-Localization: plugin
Bundle-SymbolicName: org.eclipse.linuxtools.ctf.core;singleton:=true
Bundle-Activator: org.eclipse.linuxtools.internal.ctf.core.Activator
package org.eclipse.linuxtools.ctf.core.event.io;
+import java.nio.BufferUnderflowException;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
+import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.linuxtools.ctf.core.trace.CTFReaderException;
/**
// ------------------------------------------------------------------------
private ByteBuffer fBuffer;
+
+ /**
+ * Bit-buffer's position, maximum value = Integer.MAX_VALUE * 8
+ */
private long fPosition;
private ByteOrder fByteOrder;
return (signed ? retVal : (retVal & 0xFFFFFFFFL));
}
+ /**
+ * Relative bulk <i>get</i> method.
+ *
+ * <p>
+ * This method transfers <strong>bytes</strong> from this buffer into the
+ * given destination array. This method currently only supports reads
+ * aligned to 8 bytes. It is up to the developer to shift the bits in
+ * post-processing to do unaligned reads.
+ *
+ * @param dst
+ * the bytes to write to
+ * @throws BufferUnderflowException
+ * - If there are fewer than length bytes remaining in this
+ * buffer
+ * @since 3.1
+ */
+ public void get(@NonNull byte[] dst) {
+ fBuffer.position((int) (fPosition / 8));
+ fBuffer.get(dst);
+ fPosition += dst.length * 8;
+ }
+
/**
* Relative <i>get</i> method for reading integer of <i>length</i> bits.
*