当前位置: 首页>>代码示例>>Java>>正文


Java Request.body方法代码示例

本文整理汇总了Java中org.takes.Request.body方法的典型用法代码示例。如果您正苦于以下问题:Java Request.body方法的具体用法?Java Request.body怎么用?Java Request.body使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.takes.Request的用法示例。


在下文中一共展示了Request.body方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: request

import org.takes.Request; //导入方法依赖的package包/类
/**
 * 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();
        }
    };
}
 
开发者ID:yegor256,项目名称:jare,代码行数:27,代码来源:TkRelay.java

示例2: wrap

import org.takes.Request; //导入方法依赖的package包/类
/**
 * Wrap the request.
 * @param req Request
 * @return New request
 */
private static Request wrap(final Request req) {
    final AtomicBoolean seen = new AtomicBoolean(false);
    return new Request() {
        @Override
        public Iterable<String> head() throws IOException {
            return req.head();
        }
        @Override
        public InputStream body() throws IOException {
            if (!seen.getAndSet(true)) {
                throw new IllegalStateException(
                    "It's not allowed to call body() more than once"
                );
            }
            return req.body();
        }
    };
}
 
开发者ID:yegor256,项目名称:takes,代码行数:24,代码来源:RqOnce.java

示例3: request

import org.takes.Request; //导入方法依赖的package包/类
/**
 * The request to send.
 * @param req Original request
 * @param uri Destination URI
 * @return Request
 */
private static Request request(final Request req, final URI uri) {
    final StringBuilder path = new StringBuilder(0);
    path.append(uri.getRawPath());
    if (path.length() == 0) {
        path.append('/');
    }
    if (uri.getQuery() != null) {
        path.append('?').append(uri.getRawQuery());
    }
    if (uri.getFragment() != null) {
        path.append('#').append(uri.getRawFragment());
    }
    return new Request() {
        @Override
        public Iterable<String> head() throws IOException {
            return new Concat<>(
                Collections.singleton(
                    String.format(
                        "%s %s HTTP/1.1",
                        new RqMethod.Base(req).method(),
                        path
                    )
                ),
                new Skipped<>(req.head(), 1)
            );
        }
        @Override
        public InputStream body() throws IOException {
            return req.body();
        }
    };
}
 
开发者ID:yegor256,项目名称:rehttp,代码行数:39,代码来源:DyTake.java

示例4: cap

import org.takes.Request; //导入方法依赖的package包/类
/**
 * 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;
}
 
开发者ID:yegor256,项目名称:takes,代码行数:18,代码来源:RqChunk.java

示例5: cap

import org.takes.Request; //导入方法依赖的package包/类
/**
 * 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;
}
 
开发者ID:yegor256,项目名称:takes,代码行数:18,代码来源:RqLengthAware.java

示例6: RqBuffered

import org.takes.Request; //导入方法依赖的package包/类
/**
 * Ctor.
 * @param req Original request
 */
public RqBuffered(final Request req) {
    super(
        new Request() {
            @Override
            public Iterable<String> head() throws IOException {
                return req.head();
            }
            @Override
            public InputStream body() throws IOException {
                return new BufferedInputStream(req.body());
            }
        }
    );
}
 
开发者ID:yegor256,项目名称:takes,代码行数:19,代码来源:RqBuffered.java

示例7: RqWithoutHeader

import org.takes.Request; //导入方法依赖的package包/类
/**
 * Ctor.
 * @param req Original request
 * @param name Header name
 */
public RqWithoutHeader(final Request req, final CharSequence name) {
    super(
        // @checkstyle AnonInnerLengthCheck (50 lines)
        new Request() {
            @Override
            public Iterable<String> head() throws IOException {
                final String prefix = String.format(
                    "%s:", new EnglishLowerCase(name.toString()).string()
                );
                return new Select<String>(
                    req.head(),
                    new Condition<String>() {
                        @Override
                        public boolean fits(final String header) {
                            return !new EnglishLowerCase(header).string()
                                .startsWith(prefix);
                        }
                    }
                );
            }
            @Override
            public InputStream body() throws IOException {
                return req.body();
            }
        }
    );
}
 
开发者ID:yegor256,项目名称:takes,代码行数:33,代码来源:RqWithoutHeader.java


注:本文中的org.takes.Request.body方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。