return new String(name, StandardCharsets.UTF_8).trim();
}
- /**
- * Read an IPv4 address from a buffer and format it into dotted-quad string.
- *
- * @param buf Input buffer
- * @return Dotted-quad string
- */
- public static String readIpv4Address(final ByteBuf buf) {
- final StringBuilder sb = new StringBuilder(EncodeConstants.GROUPS_IN_IPV4_ADDRESS * 4 - 1);
-
- sb.append(buf.readUnsignedByte());
- for (int i = 1; i < EncodeConstants.GROUPS_IN_IPV4_ADDRESS; i++) {
- sb.append('.');
- sb.append(buf.readUnsignedByte());
- }
-
- return sb.toString();
- }
-
public static Ipv4Address readIetfIpv4Address(final ByteBuf buf) {
final byte[] tmp = new byte[4];
buf.readBytes(tmp);
Assert.assertEquals("Wrong conversion", "", ByteBufUtils.bytesToHexString(empty));
}
- /**
- * Test ipv4 address conversion.
- */
- @Test(expected = IndexOutOfBoundsException.class)
- public void testReadIpv4Address() {
- ByteBuf buffer = PooledByteBufAllocator.DEFAULT.buffer();
- buffer.writeByte(10);
- buffer.writeByte(20);
- buffer.writeByte(30);
- buffer.writeByte(40);
- String ipv4Address = ByteBufUtils.readIpv4Address(buffer);
- Assert.assertEquals("Wrong conversion", "10.20.30.40", ipv4Address);
- Assert.assertTrue("Unexpected data", buffer.readableBytes() == 0);
-
- ByteBuf buffer2 = PooledByteBufAllocator.DEFAULT.buffer();
- buffer.writeByte(10);
- ipv4Address = ByteBufUtils.readIpv4Address(buffer2);
- }
-
@Test
public void testSerializeList() {