Java Code Examples for org.redisson.api.RBinaryStream#getChannel()
The following examples show how to use
org.redisson.api.RBinaryStream#getChannel() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RedissonBinaryStreamTest.java From redisson with Apache License 2.0 | 6 votes |
@Test public void testChannelOverwrite() throws IOException { RBinaryStream stream = redisson.getBinaryStream("test"); SeekableByteChannel c = stream.getChannel(); assertThat(c.write(ByteBuffer.wrap(new byte[]{1, 2, 3, 4, 5, 6, 7}))).isEqualTo(7); c.position(3); assertThat(c.write(ByteBuffer.wrap(new byte[]{0, 9, 10}))).isEqualTo(3); assertThat(c.position()).isEqualTo(6); ByteBuffer b = ByteBuffer.allocate(3); int r = c.read(b); assertThat(c.position()).isEqualTo(7); assertThat(r).isEqualTo(1); b.flip(); byte[] bb = new byte[b.remaining()]; b.get(bb); assertThat(bb).isEqualTo(new byte[]{7}); c.position(0); ByteBuffer state = ByteBuffer.allocate(7); c.read(state); byte[] bb1 = new byte[7]; state.flip(); state.get(bb1); assertThat(bb1).isEqualTo(new byte[]{1, 2, 3, 0, 9, 10, 7}); }
Example 2
Source File: RedissonBinaryStreamTest.java From redisson with Apache License 2.0 | 6 votes |
@Test public void testChannelTruncate() throws IOException { RBinaryStream stream = redisson.getBinaryStream("test"); SeekableByteChannel c = stream.getChannel(); c.write(ByteBuffer.wrap(new byte[]{1, 2, 3, 4, 5, 6, 7})); assertThat(c.size()).isEqualTo(7); c.truncate(3); c.position(0); c.truncate(10); ByteBuffer b = ByteBuffer.allocate(3); c.read(b); byte[] bb = new byte[3]; b.flip(); b.get(bb); assertThat(c.size()).isEqualTo(3); assertThat(bb).isEqualTo(new byte[]{1, 2, 3}); }
Example 3
Source File: RedissonBinaryStreamTest.java From redisson with Apache License 2.0 | 5 votes |
@Test public void testChannelPosition() throws IOException { RBinaryStream stream = redisson.getBinaryStream("test"); SeekableByteChannel c = stream.getChannel(); c.write(ByteBuffer.wrap(new byte[]{1, 2, 3, 4, 5, 6, 7})); c.position(3); ByteBuffer b = ByteBuffer.allocate(3); c.read(b); assertThat(c.position()).isEqualTo(6); byte[] bb = new byte[3]; b.flip(); b.get(bb); assertThat(bb).isEqualTo(new byte[]{4, 5, 6}); }