while ((c = read()) != -1) { b[off++] = (byte)c; count++;
@Override public int read(byte[] b) throws IOException { int count = this.is.read(b); writeToCache(b, 0, count); return count; }
@Override public int read(final byte[] b, final int off, final int len) throws IOException { int count = this.is.read(b, off, len); writeToCache(b, off, count); return count; }
@Override public int read() throws IOException { int ch = this.is.read(); if (ch != -1 && !this.overflow) { if (contentCacheLimit != null && cachedContent.size() == contentCacheLimit) { this.overflow = true; handleContentOverflow(contentCacheLimit); } else { cachedContent.write(ch); } } return ch; }
@Override public int read(final byte[] b, final int off, final int len) throws IOException { int count = this.is.read(b, off, len); writeToCache(b, off, count); return count; }
@Override public int read(byte[] b) throws IOException { int count = this.is.read(b); writeToCache(b, 0, count); return count; }
@Override public int read() throws IOException { int ch = this.is.read(); if (ch != -1 && !this.overflow) { if (contentCacheLimit != null && cachedContent.size() == contentCacheLimit) { this.overflow = true; handleContentOverflow(contentCacheLimit); } else { cachedContent.write(ch); } } return ch; }
/** * Read from the request body InputStream and return a DataBuffer. * Invoked only when {@link ServletInputStream#isReady()} returns "true". * @return a DataBuffer with data read, or {@link #EOF_BUFFER} if the input * stream returned -1, or null if 0 bytes were read. */ @Nullable DataBuffer readFromInputStream() throws IOException { int read = this.request.getInputStream().read(this.buffer); logBytesRead(read); if (read > 0) { DataBuffer dataBuffer = this.bufferFactory.allocateBuffer(read); dataBuffer.write(this.buffer, 0, read); return dataBuffer; } if (read == -1) { return EOF_BUFFER; } return null; }
int inputLen = in.read (postedBytes, offset, len - offset); if (inputLen <= 0) { String msg = lStrings.getString("err.io.short_read");
@Override public void onDataAvailable() throws IOException { Log.trace("Data is available to be read from [" + remoteAddress + "]"); final ServletInputStream inputStream = context.getRequest().getInputStream(); byte b[] = new byte[1024]; int length; while (inputStream.isReady() && (length = inputStream.read(b)) != -1) { outStream.write(b, 0, length); } }
public void handle(String s, Request r, HttpServletRequest httpRequest, HttpServletResponse httpResponse) throws IOException, ServletException { int size = 10 * 1024; if (httpRequest.getContentLength() > 0) { size = httpRequest.getContentLength(); } byte[] bytes = new byte[size]; if (bytes.length > 0) { final int read = httpRequest.getInputStream().read(bytes); httpResponse.getOutputStream().write(bytes, 0, read); } httpResponse.setStatus(200); httpResponse.getOutputStream().flush(); } }
public void handle(String s, Request r, HttpServletRequest httpRequest, HttpServletResponse httpResponse) throws IOException, ServletException { int size = 10 * 1024; if (httpRequest.getContentLength() > 0) { size = httpRequest.getContentLength(); } byte[] bytes = new byte[size]; if (bytes.length > 0) { httpRequest.getInputStream().read(bytes); httpResponse.getOutputStream().write(bytes); } httpResponse.setStatus(200); httpResponse.getOutputStream().flush(); } }
/** * Read from the request body InputStream and return a DataBuffer. * Invoked only when {@link ServletInputStream#isReady()} returns "true". * @return a DataBuffer with data read, or {@link #EOF_BUFFER} if the input * stream returned -1, or null if 0 bytes were read. */ @Nullable DataBuffer readFromInputStream() throws IOException { int read = this.request.getInputStream().read(this.buffer); logBytesRead(read); if (read > 0) { DataBuffer dataBuffer = this.bufferFactory.allocateBuffer(read); dataBuffer.write(this.buffer, 0, read); return dataBuffer; } if (read == -1) { return EOF_BUFFER; } return null; }
public void handle(String target, Request baseRequest, HttpServletRequest req, HttpServletResponse resp) throws IOException { ServletInputStream in = req.getInputStream(); byte[] b = new byte[8192]; int count; int total = 0; while ((count = in.read(b)) != -1) { b = new byte[8192]; total += count; } resp.setStatus(200); resp.addHeader("X-TRANSFERRED", String.valueOf(total)); resp.getOutputStream().flush(); resp.getOutputStream().close(); baseRequest.setHandled(true); } };
public void handle(String target, Request baseRequest, HttpServletRequest req, HttpServletResponse resp) throws IOException { ServletInputStream in = req.getInputStream(); byte[] b = new byte[8192]; int count; int total = 0; while ((count = in.read(b)) != -1) { b = new byte[8192]; total += count; } resp.setStatus(200); resp.addHeader("X-TRANFERED", String.valueOf(total)); resp.getOutputStream().flush(); resp.getOutputStream().close(); baseRequest.setHandled(true); } };
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException { int MAX_BODY_SIZE = 1024; // Can only handle bodies of up to 1024 bytes. byte[] b = new byte[MAX_BODY_SIZE]; int offset = 0; int numBytesRead; try (ServletInputStream is = request.getInputStream()) { while ((numBytesRead = is.read(b, offset, MAX_BODY_SIZE - offset)) != -1) { offset += numBytesRead; } } assertEquals(request.getContentLength(), offset); response.setStatus(200); response.setCharacterEncoding(request.getCharacterEncoding()); response.setContentLength(request.getContentLength()); try (ServletOutputStream os = response.getOutputStream()) { os.write(b, 0, offset); } } });
public void handle(String s, Request r, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { if ("POST".equalsIgnoreCase(request.getMethod())) { byte[] bytes = new byte[3]; ByteArrayOutputStream bos = new ByteArrayOutputStream(); int read = 0; while (read > -1) { read = request.getInputStream().read(bytes); if (read > 0) { bos.write(bytes, 0, read); } } response.setStatus(HttpServletResponse.SC_OK); response.addHeader("X-Param", new String(bos.toByteArray())); } else { // this handler is to handle POST request response.sendError(HttpServletResponse.SC_FORBIDDEN); } response.getOutputStream().flush(); response.getOutputStream().close(); } }
public void handle(String s, org.eclipse.jetty.server.Request r, HttpServletRequest httpRequest, HttpServletResponse httpResponse) throws IOException, ServletException { Enumeration<?> e = httpRequest.getHeaderNames(); String param; while (e.hasMoreElements()) { param = e.nextElement().toString(); httpResponse.addHeader("X-" + param, httpRequest.getHeader(param)); } int size = 10 * 1024; if (httpRequest.getContentLength() > 0) { size = httpRequest.getContentLength(); } byte[] bytes = new byte[size]; if (bytes.length > 0) { int read = 0; while (read != -1) { read = httpRequest.getInputStream().read(bytes); if (read > 0) { httpResponse.getOutputStream().write(bytes, 0, read); } } } httpResponse.setStatus(200); httpResponse.getOutputStream().flush(); httpResponse.getOutputStream().close(); } }
public void handle(String s, Request r, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { if (request.getHeader("X-401") != null) { response.setStatus(401); response.setContentLength(0); } else { response.addHeader("X-Auth", request.getHeader("Authorization")); response.addHeader("X-" + CONTENT_LENGTH, String.valueOf(request.getContentLength())); response.setIntHeader("X-" + CONTENT_LENGTH, request.getContentLength()); response.setStatus(200); int size = 10 * 1024; byte[] bytes = new byte[size]; int contentLength = 0; int read; do { read = request.getInputStream().read(bytes); if (read > 0) { contentLength += read; response.getOutputStream().write(bytes, 0, read); } } while (read >= 0); response.setContentLength(contentLength); } response.getOutputStream().flush(); response.getOutputStream().close(); } }
@Test public void noContent() throws IOException { assertEquals(-1, request.getContentLength()); assertEquals(-1, request.getInputStream().read()); assertNull(request.getContentAsByteArray()); }