Util { public static String truncate(byte[] payload, int length) { if (payload.length <= length) { return new String(payload); } return new String(payload, 0, length) + "[...]"; } private  Util(); static byte[] addressToBytes(String address); static boolean identical(byte[] b, byte[] b2); static void validatePort(int port); static InetSocketAddress computeLocalEndpoint(
            NetworkInterface ni, InetAddress localAddress, Integer localPort, InetAddress address, Integer port); static boolean isIPv4(InetAddress a); static boolean isIPv6(InetAddress a); static String inetAddressToString(InetAddress a); static void displayInfo(); static void dumpState(Configuration c, DatagramSocket s, DatagramPacket p); static String truncate(byte[] payload, int length); static final Pattern IPv4_FORMAT; }
@Test public void truncate() throws Exception { String s = Util.truncate(new byte[] { 't', 'e', 's', 't' }, 4); assertEquals("test", s); }
@Test public void truncate_Longer() throws Exception { String s = Util.truncate(new byte[]{'t', 'e', 's', 't'}, 3); assertEquals("tes[...]", s); }