Java Code Examples for org.takes.Request#body()
The following examples show how to use
org.takes.Request#body() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TkRelay.java From jare with MIT License | 6 votes |
/** * The request to send. * @param req Original request * @param path Destination path * @return Request */ private static Request request(final Request req, final String path) { return new Request() { @Override public Iterable<String> head() throws IOException { return new Concat<String>( Collections.singleton( String.format( "GET %s HTTP/1.1", path ) ), new Skipped<>(req.head(), 1) ); } @Override public InputStream body() throws IOException { return req.body(); } }; }
Example 2
Source File: RqChunk.java From takes with MIT License | 5 votes |
/** * Cap the steam. * @param req Request * @return Stream with a cap * @throws IOException If fails */ private static InputStream cap(final Request req) throws IOException { final Iterator<String> hdr = new RqHeaders.Base(req) .header("Transfer-Encoding").iterator(); final InputStream result; if (hdr.hasNext() && "chunked".equalsIgnoreCase(hdr.next())) { result = new ChunkedInputStream(req.body()); } else { result = req.body(); } return result; }
Example 3
Source File: RqLengthAware.java From takes with MIT License | 5 votes |
/** * Cap the steam. * @param req Request * @return Stream with a cap * @throws IOException If fails */ private static InputStream cap(final Request req) throws IOException { final Iterator<String> hdr = new RqHeaders.Base(req) .header("Content-Length").iterator(); InputStream body = req.body(); long length = (long) body.available(); if (hdr.hasNext()) { length = Long.parseLong(hdr.next()); } body = new CapInputStream(body, length); return body; }
Example 4
Source File: RqBuffered.java From takes with MIT License | 5 votes |
/** * Ctor. * @param req Original request */ public RqBuffered(final Request req) { super( new RequestOf( req::head, () -> new BufferedInputStream(req.body()) ) ); }
Example 5
Source File: RqOnce.java From takes with MIT License | 5 votes |
/** * Wrap the request. * @param req Request * @return New request */ private static Request wrap(final Request req) { final AtomicBoolean seen = new AtomicBoolean(false); return new RequestOf( req::head, () -> { if (!seen.getAndSet(true)) { throw new IllegalStateException( "It's not allowed to call body() more than once" ); } return req.body(); } ); }
Example 6
Source File: HmRqTextBody.java From takes with MIT License | 4 votes |
@Override public InputStream itemBody(final Request item) throws IOException { return item.body(); }