本文整理汇总了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();
}
};
}
示例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();
}
};
}
示例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();
}
};
}
示例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;
}
示例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;
}
示例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());
}
}
);
}
示例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();
}
}
);
}