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


Java Representation.release方法代碼示例

本文整理匯總了Java中org.restlet.representation.Representation.release方法的典型用法代碼示例。如果您正苦於以下問題:Java Representation.release方法的具體用法?Java Representation.release怎麽用?Java Representation.release使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.restlet.representation.Representation的用法示例。


在下文中一共展示了Representation.release方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: sendRequest

import org.restlet.representation.Representation; //導入方法依賴的package包/類
/**
 * Sends the request to the client. Commits the request line, headers and
 * optional entity and send them over the network.
 * 
 * @param request
 *            The high-level request.
 * @return the status of the communication
 */
public Status sendRequest(Request request) {
    Status result = null;
    Representation entity = request.isEntityAvailable() ? request
            .getEntity() : null;

    // Get the connector service to callback
    org.restlet.service.ConnectorService connectorService = ConnectorHelper
            .getConnectorService();
    if (connectorService != null) {
        connectorService.beforeSend(entity);
    }

    try {
        if (entity != null) {

            // In order to workaround bug #6472250
            // (http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6472250),
            // it is very important to reuse that exact same "requestStream"
            // reference when manipulating the request stream, otherwise
            // "insufficient data sent" exceptions will occur in
            // "fixedLengthMode"
            OutputStream requestStream = getRequestEntityStream();

            if (requestStream != null) {
                entity.write(requestStream);
                requestStream.flush();
                requestStream.close();
            }
        }

        // Now we can access the status code, this MUST happen after closing
        // any open request stream.
        result = new Status(getStatusCode(), getReasonPhrase());
    } catch (IOException ioe) {
        getHelper()
                .getLogger()
                .debug("An error occurred during the communication with the remote HTTP server.",
                        ioe);
        result = new Status(Status.CONNECTOR_ERROR_COMMUNICATION, ioe);
    } finally {
        if (entity != null) {
            entity.release();
        }

        // Call-back after writing
        if (connectorService != null) {
            connectorService.afterSend(entity);
        }
    }

    return result;
}
 
開發者ID:restlet,項目名稱:restlet-framework,代碼行數:61,代碼來源:ClientCall.java

示例2: sendResponse

import org.restlet.representation.Representation; //導入方法依賴的package包/類
/**
 * Sends the response back to the client. Commits the status, headers and
 * optional entity and send them over the network. The default
 * implementation only writes the response entity on the response stream or
 * channel. Subclasses will probably also copy the response headers and
 * status.
 * 
 * @param response
 *            The high-level response.
 * @throws IOException
 *             if the Response could not be written to the network.
 */
public void sendResponse(Response response) throws IOException {
    if (response != null) {
        // Get the connector service to callback
        Representation responseEntity = response.getEntity();
        ConnectorService connectorService = ConnectorHelper
                .getConnectorService();

        if (connectorService != null) {
            connectorService.beforeSend(responseEntity);
        }

        OutputStream responseEntityStream = null;
        try {
            writeResponseHead(response);

            if (responseEntity != null) {

                responseEntityStream = getResponseEntityStream();
                writeResponseBody(responseEntity, responseEntityStream);

            }
        } finally {
            if (responseEntityStream != null) {
                try {
                    responseEntityStream.flush();
                    responseEntityStream.close();
                } catch (IOException ioe) {
                    // The stream was probably already closed by the
                    // connector. Probably OK, low message priority.
                    getLogger().debug("Exception while flushing and closing the entity stream.", ioe);
                }
            }
            if (responseEntity != null) {
                responseEntity.release();
            }

            if (connectorService != null) {
                connectorService.afterSend(responseEntity);
            }
        }
    }
}
 
開發者ID:restlet,項目名稱:restlet-framework,代碼行數:55,代碼來源:ServerCall.java


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