當前位置: 首頁>>代碼示例>>Java>>正文


Java Representation.setSize方法代碼示例

本文整理匯總了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));
        }
    }
}
 
開發者ID:restlet,項目名稱:restlet-framework,代碼行數:33,代碼來源:RangeReader.java

示例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;
}
 
開發者ID:restlet,項目名稱:restlet-framework,代碼行數:54,代碼來源:ClientCall.java


注:本文中的org.restlet.representation.Representation.setSize方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。