本文整理了Java中org.restlet.Request.setRanges
方法的一些代码示例,展示了Request.setRanges
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Request.setRanges
方法的具体详情如下:
包路径:org.restlet.Request
类名称:Request
方法名:setRanges
[英]Sets the modifiable list of ranges to return from the target resource's representation. Note that when used with HTTP connectors, this property maps to the "Range" header. This method clears the current list and adds all entries in the parameter list.
[中]设置要从目标资源的表示返回的范围的可修改列表。请注意,当与HTTP连接器一起使用时,此属性映射到“Range”头。此方法清除当前列表并添加参数列表中的所有条目。
代码示例来源:origin: org.restlet.osgi/org.restlet
@Override
public void setRanges(List<Range> ranges) {
wrappedRequest.setRanges(ranges);
}
代码示例来源:origin: org.restlet.osgi/org.restlet
/**
* Sets the ranges to return from the target resource's representation.
*
* @param ranges
* The ranges.
* @see Request#setRanges(List)
*/
public void setRanges(List<Range> ranges) {
getRequest().setRanges(ranges);
}
代码示例来源:origin: stackoverflow.com
public String readFirstChunk(String urlString, int byteCount) {
String text = null;
if (urlString != null) {
org.restlet.Client restletClient = new org.restlet.Client(Protocol.HTTP);
Request request = new Request(Method.GET, urlString);
List<Range> ranges = Collections.singletonList(new Range(0, byteCount));
request.setRanges(ranges);
Response response = restletClient.handle(request);
if (Status.SUCCESS_OK.equals(response.getStatus())) {
text = processSuccessfulChunkRequest(response);
} else if (Status.SUCCESS_PARTIAL_CONTENT .equals(response.getStatus())) {
text = processSuccessfulChunkRequest(response);
} else {
System.err.println("FAILED "+response.getStatus());
}
}
return text;
}
private String processSuccessfulChunkRequest(Response response) {
String text = null;
try {
text = response.getEntity().getText();
} catch (IOException e) {
throw new RuntimeException("Cannot download chunk", e);
}
return text;
}
内容来源于网络,如有侵权,请联系作者删除!