@Test public void testRead() throws Exception { String body = "123ABC"; String header = rightPad("", headerBodyLengthBeginIndex) + leftPad(String.valueOf(body.length()), headerBodyLengthEndIndex - headerBodyLengthBeginIndex, "0") + rightPad("", headerLength - headerBodyLengthEndIndex); byte[] buffer = new byte[header.length() + body.length()]; System.arraycopy(header.getBytes(encoding), 0, buffer, 0, headerLength); System.arraycopy(body.getBytes(encoding), 0, buffer, headerLength, body.length()); ByteArrayInputStream in = new ByteArrayInputStream(buffer); RequestReader.Request request = requestReader.read(in); assertEquals(header, request.getHeader()); assertEquals(body, request.getBody()); }
public Request read(InputStream in) throws IOException { String header = null; String body = null; byte[] headerBytes = new byte[headerLength]; int n = in.read(headerBytes); if (n > 0) { header = new String(headerBytes, encoding); log.debug("header: #{}# ", header); int length = Integer.parseInt(header.substring(headerBodyLengthBeginIndex, headerBodyLengthEndIndex)); log.debug("length: {}", length); byte[] bodyBytes = new byte[length]; in.read(bodyBytes); body = new String(bodyBytes, encoding); log.debug("body: #{}#", body); } log.info("request: #{}#", header + body); return new Request(header, body); }
RequestReader { public Request read(InputStream in) throws IOException { String header = null; String body = null; byte[] headerBytes = new byte[headerLength]; int n = in.read(headerBytes); if (n > 0) { header = new String(headerBytes, encoding); log.debug("header: #{}# ", header); int length = Integer.parseInt(header.substring(headerBodyLengthBeginIndex, headerBodyLengthEndIndex)); log.debug("length: {}", length); byte[] bodyBytes = new byte[length]; in.read(bodyBytes); body = new String(bodyBytes, encoding); log.debug("body: #{}#", body); } log.info("request: #{}#", header + body); return new Request(header, body); } }
RequestReader { public Request read(InputStream in) throws IOException { String header = null; String body = null; byte[] headerBytes = new byte[headerLength]; int n = in.read(headerBytes); if (n > 0) { header = new String(headerBytes, encoding); log.debug("header: #{}# ", header); int length = Integer.parseInt(header.substring(headerBodyLengthBeginIndex, headerBodyLengthEndIndex)); log.debug("length: {}", length); byte[] bodyBytes = new byte[length]; in.read(bodyBytes); body = new String(bodyBytes, encoding); log.debug("body: #{}#", body); } log.info("request: #{}#", header + body); return new Request(header, body); }  }
RequestReader { public Request read(InputStream in) throws IOException { String header = null; String body = null; byte[] headerBytes = new byte[headerLength]; int n = in.read(headerBytes); if (n > 0) { header = new String(headerBytes, encoding); log.debug("header: #{}# ", header); int length = Integer.parseInt(header.substring(headerBodyLengthBeginIndex, headerBodyLengthEndIndex)); log.debug("length: {}", length); byte[] bodyBytes = new byte[length]; in.read(bodyBytes); body = new String(bodyBytes, encoding); log.debug("body: #{}#", body); } log.info("request: #{}#", header + body); return new Request(header, body); }  Request read(InputStream in); }
RequestReader { public Request read(InputStream in) throws IOException { String header = null; String body = null; byte[] headerBytes = new byte[headerLength]; int n = in.read(headerBytes); if (n > 0) { header = new String(headerBytes, encoding); log.debug("header: #{}# ", header); int length = Integer.parseInt(header.substring(headerBodyLengthBeginIndex, headerBodyLengthEndIndex)); log.debug("length: {}", length); byte[] bodyBytes = new byte[length]; in.read(bodyBytes); body = new String(bodyBytes, encoding); log.debug("body: #{}#", body); } log.info("request: #{}#", header + body); return new Request(header, body); }  Request read(InputStream in);  }