本文整理汇总了Java中org.restlet.representation.Representation.setSize方法的典型用法代码示例。如果您正苦于以下问题:Java Representation.setSize方法的具体用法?Java Representation.setSize怎么用?Java Representation.setSize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.restlet.representation.Representation
的用法示例。
在下文中一共展示了Representation.setSize方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: update
import org.restlet.representation.Representation; //导入方法依赖的package包/类
/**
* Parse the Content-Range header value and update the given representation.
*
* @param value
* Content-range header.
* @param representation
* Representation to update.
*/
public static void update(String value, Representation representation) {
String prefix = "bytes ";
if (value != null && value.startsWith(prefix)) {
value = value.substring(prefix.length());
int index = value.indexOf("-");
int index1 = value.indexOf("/");
if (index != -1) {
long startIndex = (index == 0) ? Range.INDEX_LAST : Long
.parseLong(value.substring(0, index));
long endIndex = Long.parseLong(value.substring(index + 1,
index1));
representation.setRange(new Range(startIndex, endIndex
- startIndex + 1));
}
String strLength = value.substring(index1 + 1, value.length());
if (!("*".equals(strLength))) {
representation.setSize(Long.parseLong(strLength));
}
}
}
示例2: getResponseEntity
import org.restlet.representation.Representation; //导入方法依赖的package包/类
/**
* Returns the response entity if available. Note that no metadata is
* associated by default, you have to manually set them from your headers.
*
* @param response
* the Response to get the entity from
* @return The response entity if available.
*/
public Representation getResponseEntity(Response response) {
Representation result = null;
// boolean available = false;
long size = Representation.UNKNOWN_SIZE;
// Compute the content length
Series<Header> responseHeaders = getResponseHeaders();
String transferEncoding = responseHeaders.getFirstValue(
HeaderConstants.HEADER_TRANSFER_ENCODING, true);
if ((transferEncoding != null)
&& !Encoding.IDENTITY.getName().equalsIgnoreCase(
transferEncoding)) {
size = Representation.UNKNOWN_SIZE;
} else {
size = getContentLength();
}
if (!getMethod().equals(Method.HEAD.getName())
&& !response.getStatus().isInformational()
&& !response.getStatus()
.equals(Status.REDIRECTION_NOT_MODIFIED)
&& !response.getStatus().equals(Status.SUCCESS_NO_CONTENT)
&& !response.getStatus().equals(Status.SUCCESS_RESET_CONTENT)) {
// Make sure that an InputRepresentation will not be instantiated
// while the stream is closed.
InputStream stream = getUnClosedResponseEntityStream(getResponseEntityStream(size));
if (stream != null) {
result = getRepresentation(stream);
}
}
if (result != null) {
result.setSize(size);
// Informs that the size has not been specified in the header.
if (size == Representation.UNKNOWN_SIZE) {
getLogger()
.debug("The length of the message body is unknown. The entity must be handled carefully and consumed entirely in order to surely release the connection.");
}
}
result = HeaderUtils.extractEntityHeaders(responseHeaders, result);
return result;
}