use of org.redisson.api.RBinaryStream in project redisson by redisson.
the class RedissonBinaryStreamTest method testRead.
@Test
public void testRead() throws IOException {
RBinaryStream stream = redisson.getBinaryStream("test");
byte[] value = { 1, 2, 3, 4, 5, (byte) 0xFF };
stream.set(value);
InputStream s = stream.getInputStream();
int b = 0;
byte[] readValue = new byte[6];
int i = 0;
while (true) {
b = s.read();
if (b == -1) {
break;
}
readValue[i] = (byte) b;
i++;
}
assertThat(readValue).isEqualTo(value);
}
use of org.redisson.api.RBinaryStream in project redisson by redisson.
the class RedissonBinaryStreamTest method testChannelPosition.
@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 });
}
use of org.redisson.api.RBinaryStream in project redisson by redisson.
the class RedissonBinaryStreamTest method testWriteArrayWithOffset.
@Test
public void testWriteArrayWithOffset() throws IOException {
RBinaryStream stream = redisson.getBinaryStream("test");
OutputStream os = stream.getOutputStream();
byte[] value = { 1, 2, 3, 4, 5, 6 };
os.write(value, 0, 3);
byte[] s = stream.get();
assertThat(s).isEqualTo(new byte[] { 1, 2, 3 });
os.write(value, 3, 3);
s = stream.get();
assertThat(s).isEqualTo(value);
}
use of org.redisson.api.RBinaryStream in project redisson by redisson.
the class RedissonBinaryStreamTest method testChannelTruncate.
@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 });
}
use of org.redisson.api.RBinaryStream in project redisson by redisson.
the class RedissonBinaryStreamTest method testWriteArray.
@Test
public void testWriteArray() throws IOException {
RBinaryStream stream = redisson.getBinaryStream("test");
OutputStream os = stream.getOutputStream();
byte[] value = { 1, 2, 3, 4, 5, 6 };
os.write(value);
byte[] s = stream.get();
assertThat(s).isEqualTo(value);
}
Aggregations