本文整理汇总了Java中org.restlet.representation.Representation.write方法的典型用法代码示例。如果您正苦于以下问题:Java Representation.write方法的具体用法?Java Representation.write怎么用?Java Representation.write使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.restlet.representation.Representation
的用法示例。
在下文中一共展示了Representation.write方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getText
import org.restlet.representation.Representation; //导入方法依赖的package包/类
/**
* Converts the representation to a string value. Be careful when using this
* method as the conversion of large content to a string fully stored in
* memory can result in OutOfMemoryErrors being thrown.
*
* @param representation
* The representation to convert.
* @return The representation as a string value.
*/
public static String getText(Representation representation)
throws IOException {
String result = null;
if (representation.isAvailable()) {
if (representation.getSize() == 0) {
result = "";
} else {
java.io.StringWriter sw = new java.io.StringWriter();
representation.write(sw);
sw.flush();
result = sw.toString();
}
}
return result;
}
示例2: 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;
}
示例3: getStream
import org.restlet.representation.Representation; //导入方法依赖的package包/类
/**
* Returns an input stream based on the given representation's content and
* its write(OutputStream) method. Internally, it uses a writer thread and a
* pipe stream.
*
* @param representation
* the representation to get the {@link java.io.OutputStream} from.
* @return A stream with the representation's content.
*/
public static InputStream getStream(final Representation representation) {
InputStream result = null;
if (representation == null) {
return null;
}
final PipeStream pipe = new PipeStream();
final java.io.OutputStream os = pipe.getOutputStream();
// Creates a thread that will handle the task of continuously
// writing the representation into the input side of the pipe
Runnable task = new org.restlet.engine.util.ContextualRunnable() {
public void run() {
try {
representation.write(os);
os.flush();
} catch (IOException ioe) {
Context.getCurrentLogger().warn("Error while writing to the piped input stream.",
ioe);
} finally {
try {
os.close();
} catch (IOException ioe2) {
Context.getCurrentLogger().warn("Error while closing the pipe.", ioe2);
}
}
}
};
org.restlet.Context context = org.restlet.Context.getCurrent();
if (context != null && context.getExecutorService() != null) {
context.getExecutorService().execute(task);
} else {
Engine.createThreadWithLocalVariables(task, "Restlet-IoUtils")
.start();
}
result = pipe.getInputStream();
return result;
}
示例4: writeResponseBody
import org.restlet.representation.Representation; //导入方法依赖的package包/类
/**
* Effectively writes the response body. The entity to write is guaranteed
* to be non null. Attempts to write the entity on the response channel or
* response stream by default.
*
* @param entity
* The representation to write as entity of the body.
* @param responseEntityStream
* The response entity stream or null if a channel is used.
* @throws IOException
*/
protected void writeResponseBody(Representation entity,
OutputStream responseEntityStream) throws IOException {
// Send the entity to the client
if (responseEntityStream != null) {
entity.write(responseEntityStream);
responseEntityStream.flush();
}
}