List of usage examples for io.netty.buffer ByteBuf release
boolean release();
From source file:com.github.spapageo.jannel.channel.ChannelBufferUtilsTest.java
License:Open Source License
@Test public void testReadOctetStringToString_when_octet_string_size_is_positive_and_utf8_encoded_reads_string_correctly() throws Exception { byte[] stringBytes = STRING_TO_ENCODE.getBytes(StandardCharsets.UTF_8); ByteBuf encodedString = Unpooled.buffer(stringBytes.length + 4); encodedString.writeInt(stringBytes.length); encodedString.writeBytes(stringBytes); String decodedString = ChannelBufferUtils.readOctetStringToString(encodedString, StandardCharsets.UTF_8); assertEquals("Decoded string and encoded string are not the same", STRING_TO_ENCODE, decodedString); encodedString.release(); }
From source file:com.github.spapageo.jannel.channel.ChannelBufferUtilsTest.java
License:Open Source License
@Test public void testReadOctetStringToString_when_octet_string_size_is_positive_and_utf16_encoded_reads_string_correctly() throws Exception { byte[] stringBytes = STRING_TO_ENCODE.getBytes(StandardCharsets.UTF_16); ByteBuf encodedString = Unpooled.buffer(stringBytes.length + 4); encodedString.writeInt(stringBytes.length); encodedString.writeBytes(stringBytes); String decodedString = ChannelBufferUtils.readOctetStringToString(encodedString, StandardCharsets.UTF_16); assertEquals("Decoded string and encoded string are not the same", STRING_TO_ENCODE, decodedString); encodedString.release(); }
From source file:com.github.spapageo.jannel.channel.ChannelBufferUtilsTest.java
License:Open Source License
@Test(expected = InvalidUUIDException.class) public void testReadUUIDWhenInputIsAMalformedUUIDStringThrowsInvalidUUIDException() throws Exception { String UUIDString = UUID.randomUUID().toString().replace('-', '1'); byte[] stringBytes = UUIDString.getBytes(StandardCharsets.UTF_16); ByteBuf encodedUUID = Unpooled.buffer(stringBytes.length + 4); encodedUUID.writeInt(stringBytes.length); encodedUUID.writeBytes(stringBytes); try {/*from w w w . j a va 2s . c om*/ ChannelBufferUtils.readUUID(encodedUUID, StandardCharsets.UTF_16); } finally { encodedUUID.release(); } }
From source file:com.github.spapageo.jannel.channel.ChannelBufferUtilsTest.java
License:Open Source License
@Test(expected = NotEnoughDataDecoderException.class) public void testReadIntWhenInputBufferIsSmallThan4BytesThrowsNotEnoughDataException() throws Exception { byte[] input = { 0x00, 0x00, 0x00 }; ByteBuf inputBuffer = Unpooled.copiedBuffer(input); try {/*w ww . j a v a2s . co m*/ ChannelBufferUtils.readInt(inputBuffer); } finally { inputBuffer.release(); } }
From source file:com.github.spapageo.jannel.channel.ChannelBufferUtilsTest.java
License:Open Source License
@Test public void testReadIntWhenInputBufferCorrectlyReadInteger() throws Exception { byte[] input = { (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xf0 }; ByteBuf inputBuffer = Unpooled.copiedBuffer(input); int readInt = ChannelBufferUtils.readInt(inputBuffer); assertEquals("Encoded and decoded ints are not the same", -16, readInt); inputBuffer.release(); }
From source file:com.github.spapageo.jannel.channel.ChannelBufferUtilsTest.java
License:Open Source License
@Test(expected = NotEnoughDataDecoderException.class) public void testReadOctetStringToBytesWhenInputBufferSizeLessThan4ThrowNotEnoughDataException() throws Exception { ByteBuf inputBuffer = Unpooled.buffer(1); try {/*from ww w.j a v a 2 s .c o m*/ ChannelBufferUtils.readOctetStringToBytes(inputBuffer); } finally { inputBuffer.release(); } }
From source file:com.github.spapageo.jannel.channel.ChannelBufferUtilsTest.java
License:Open Source License
@Test public void testReadOctetStringToBytesWhenOctetStringSizeIsMinus1ReturnsEmptyString() throws Exception { byte[] input = { (byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff }; ByteBuf inputBuffer = Unpooled.copiedBuffer(input); ByteBuf readBytes = ChannelBufferUtils.readOctetStringToBytes(inputBuffer); assertEquals("Decoded byte array size is not 0", 0, readBytes.readableBytes()); inputBuffer.release(); }
From source file:com.github.spapageo.jannel.channel.ChannelBufferUtilsTest.java
License:Open Source License
@Test(expected = StringSizeException.class) public void testReadOctetStringToBytesWhenOctetStringSizeIsOtherNegativeNumberThrowsStringSizeException() throws Exception { byte[] input = { (byte) 0xff, (byte) 0xff, (byte) 0xff, 0x00 }; ByteBuf inputBuffer = Unpooled.copiedBuffer(input); try {// w w w .j ava 2 s . com ChannelBufferUtils.readOctetStringToBytes(inputBuffer); } finally { inputBuffer.release(); } }
From source file:com.github.spapageo.jannel.channel.ChannelBufferUtilsTest.java
License:Open Source License
@Test(expected = StringSizeException.class) public void testReadOctetStringToBytesWhenOctetStringSizeIsGreaterThanBufferSizeThrowsStringSizeException() throws Exception { byte[] input = { 0x00, 0x00, 0x00, 0x02, 0x14 }; ByteBuf inputBuffer = Unpooled.copiedBuffer(input); try {//from ww w . ja v a 2 s. c om ChannelBufferUtils.readOctetStringToBytes(inputBuffer); } finally { inputBuffer.release(); } }
From source file:com.github.spapageo.jannel.channel.ChannelBufferUtilsTest.java
License:Open Source License
@Test public void testReadOctetStringToBytesWhenOctetStringSizeIsZeroReturnsEmptyArray() throws Exception { byte[] input = { 0x00, 0x00, 0x00, 0x00 }; ByteBuf inputBuffer = Unpooled.copiedBuffer(input); ByteBuf readBytes = ChannelBufferUtils.readOctetStringToBytes(inputBuffer); assertEquals("Read byte array size is not 0", 0, readBytes.readableBytes()); inputBuffer.release(); }