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