@Test public void testMarshal() throws Envelope.ParserException { Envelope envelope = new Envelope("Test", "{}"); envelope.addHeader("header1", "1"); checkMarshaling(envelope, "Test 14 2\r\n" + "header1: 1\r\n" + "\r\n" + "{}"); }
public String marshal() { checkNotNull(protocolTag); StringWriter headers = new StringWriter(); Iterator<Entry<String, String>> it = headersMap.entrySet().iterator(); while (it.hasNext()) { Entry<String, String> pair = it.next(); headers.write(String.format("%s: %s\r\n", pair.getKey(), pair.getValue())); } headers.write("\r\n"); String headerStr = headers.toString(); if (payload != null) { return String.format("%s %d %d\r\n%s%s", protocolTag, headerStr.length(), payload.length(), headerStr, payload); } return String.format("%s %d 0\r\n%s", protocolTag, headerStr.length(), headerStr); }
Envelope { public String marshal() { checkNotNull(protocolTag); StringWriter headers = new StringWriter(); Iterator<Entry<String, String>> it = headersMap.entrySet().iterator(); while (it.hasNext()) { Entry<String, String> pair = it.next(); headers.write(String.format("%s: %s\r\n", pair.getKey(), pair.getValue())); } headers.write("\r\n"); String headerStr = headers.toString(); if (payload != null) { return String.format("%s %d %d\r\n%s%s", protocolTag, headerStr.length(), payload.length(), headerStr, payload); } return String.format("%s %d 0\r\n%s", protocolTag, headerStr.length(), headerStr); } }
Envelope { public String marshal() { checkNotNull(protocolTag); StringWriter headers = new StringWriter(); Iterator<Entry<String, String>> it = headersMap.entrySet().iterator(); while (it.hasNext()) { Entry<String, String> pair = it.next(); headers.write(String.format("%s: %s\r\n", pair.getKey(), pair.getValue())); } headers.write("\r\n"); String headerStr = headers.toString(); if (payload != null) { return String.format("%s %d %d\r\n%s%s", protocolTag, headerStr.length(), payload.length(), headerStr, payload); } return String.format("%s %d 0\r\n%s", protocolTag, headerStr.length(), headerStr); } protected  Envelope(String tag, String payload); protected  Envelope(String tag, Map<String, String> headersMap, String payload); }
Envelope { public String marshal() { checkNotNull(protocolTag); StringWriter headers = new StringWriter(); Iterator<Entry<String, String>> it = headersMap.entrySet().iterator(); while (it.hasNext()) { Entry<String, String> pair = it.next(); headers.write(String.format("%s: %s\r\n", pair.getKey(), pair.getValue())); } headers.write("\r\n"); String headerStr = headers.toString(); if (payload != null) { return String.format("%s %d %d\r\n%s%s", protocolTag, headerStr.length(), payload.length(), headerStr, payload); } return String.format("%s %d 0\r\n%s", protocolTag, headerStr.length(), headerStr); } protected  Envelope(String tag, String payload); protected  Envelope(String tag, Map<String, String> headersMap, String payload); boolean equals(Object obj); String getPayload(); String getHeader(String header); void addHeader(String header, String value); String marshal(); static Envelope parse(String message); }
Envelope { public String marshal() { checkNotNull(protocolTag); StringWriter headers = new StringWriter(); Iterator<Entry<String, String>> it = headersMap.entrySet().iterator(); while (it.hasNext()) { Entry<String, String> pair = it.next(); headers.write(String.format("%s: %s\r\n", pair.getKey(), pair.getValue())); } headers.write("\r\n"); String headerStr = headers.toString(); if (payload != null) { return String.format("%s %d %d\r\n%s%s", protocolTag, headerStr.length(), payload.length(), headerStr, payload); } return String.format("%s %d 0\r\n%s", protocolTag, headerStr.length(), headerStr); } protected  Envelope(String tag, String payload); protected  Envelope(String tag, Map<String, String> headersMap, String payload); boolean equals(Object obj); String getPayload(); String getHeader(String header); void addHeader(String header, String value); String marshal(); static Envelope parse(String message);  }