@Test public void testLPackNullOrEmptyString() { assertEquals("0000", NewRpcMessageWriter.LPack("", 4)); assertEquals("0000", NewRpcMessageWriter.LPack(null, 4)); }
public static String LPack(String str, int nDigits) { if (str == null) return String.format("%0" + nDigits + "d", 0); int length = str.length(); int width = Integer.toString(length).length(); if (nDigits < width) throw new IllegalArgumentException("In generation of message to server, send to LPack where length of string '" + str + "' of " + width + " chars exceeds number of chars for output length (" + nDigits + ")"); return String.format("%0" + nDigits + "d%s", length, str); }
NewRpcMessageWriter implements RpcMessageWriter { public static String LPack(String str, int nDigits) { if (str == null) return String.format("%0" + nDigits + "d", 0); int length = str.length(); int width = Integer.toString(length).length(); if (nDigits < width) throw new IllegalArgumentException("In generation of message to server, send to LPack where length of string '" + str + "' of " + width + " chars exceeds number of chars for output length (" + nDigits + ")"); return String.format("%0" + nDigits + "d%s", length, str); } }
NewRpcMessageWriter implements RpcMessageWriter { public static String LPack(String str, int nDigits) { if (str == null) return String.format("%0" + nDigits + "d", 0); int length = str.length(); int width = Integer.toString(length).length(); if (nDigits < width) throw new IllegalArgumentException("In generation of message to server, send to LPack where length of string '" + str + "' of " + width + " chars exceeds number of chars for output length (" + nDigits + ")"); return String.format("%0" + nDigits + "d%s", length, str); } NewRpcMessageWriter(Writer w); }
NewRpcMessageWriter implements RpcMessageWriter { public static String LPack(String str, int nDigits) { if (str == null) return String.format("%0" + nDigits + "d", 0); int length = str.length(); int width = Integer.toString(length).length(); if (nDigits < width) throw new IllegalArgumentException("In generation of message to server, send to LPack where length of string '" + str + "' of " + width + " chars exceeds number of chars for output length (" + nDigits + ")"); return String.format("%0" + nDigits + "d%s", length, str); } NewRpcMessageWriter(Writer w); void writeStartConnection(String hostname, String address, int localPort); void writeStopConnection(); void write(RpcRequest request); void flush(); static String SPack(String str); static String LPack(String str, int nDigits); }
NewRpcMessageWriter implements RpcMessageWriter { public static String LPack(String str, int nDigits) { if (str == null) return String.format("%0" + nDigits + "d", 0); int length = str.length(); int width = Integer.toString(length).length(); if (nDigits < width) throw new IllegalArgumentException("In generation of message to server, send to LPack where length of string '" + str + "' of " + width + " chars exceeds number of chars for output length (" + nDigits + ")"); return String.format("%0" + nDigits + "d%s", length, str); } NewRpcMessageWriter(Writer w); void writeStartConnection(String hostname, String address, int localPort); void writeStopConnection(); void write(RpcRequest request); void flush(); static String SPack(String str); static String LPack(String str, int nDigits); static final String PREFIX; }