本文整理汇总了Java中org.simpleframework.http.Response.getOutputStream方法的典型用法代码示例。如果您正苦于以下问题:Java Response.getOutputStream方法的具体用法?Java Response.getOutputStream怎么用?Java Response.getOutputStream使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.simpleframework.http.Response
的用法示例。
在下文中一共展示了Response.getOutputStream方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: handle
import org.simpleframework.http.Response; //导入方法依赖的package包/类
/**
* Handle the incoming request on the tracker service.
*
* <p>
* This makes sure the request is made to the tracker's announce URL, and
* delegates handling of the request to the <em>process()</em> method after
* preparing the response object.
* </p>
*
* @param request The incoming HTTP request.
* @param response The response object.
*/
public void handle(Request request, Response response) {
// Reject non-announce requests
if (!Tracker.ANNOUNCE_URL.equals(request.getPath().toString())) {
response.setCode(404);
response.setText("Not Found");
return;
}
OutputStream body = null;
try {
body = response.getOutputStream();
this.process(request, response, body);
body.flush();
} catch (IOException ioe) {
logger.warn("Error while writing response: {}!", ioe.getMessage());
} finally {
IOUtils.closeQuietly(body);
}
}
示例2: streamResponse
import org.simpleframework.http.Response; //导入方法依赖的package包/类
private void streamResponse(Response resp, ResponseParams rp) throws IOException {
OutputStream body = null;
try {
if (rp.staticFile) {
String fileName = rp.message;
body = resp.getOutputStream();
byte[] buffer = new byte[32 * 1024];
InputStream input = configReader.getStaticFile(fileName);
int bytesRead;
while ((bytesRead = input.read(buffer, 0, buffer.length)) > 0) {
body.write(buffer, 0, bytesRead);
}
} else {
body = resp.getPrintStream();
if (body != null) {
((PrintStream) body).print(rp.message);
}
}
} finally {
if (body != null) {
try {
body.close();
} catch (IOException e) {
LOGGER.log(Level.SEVERE, "Exception on MockServer close", e);
}
}
}
}
示例3: serveMotionJpegAsync
import org.simpleframework.http.Response; //导入方法依赖的package包/类
void serveMotionJpegAsync(final Response response) throws IOException {
LOG.info("Serving MJPEG...");
response.setContentType("multipart/x-mixed-replace;boundary=ipcamera");
response.setStatus(Status.OK);
OutputStream outputStream = response.getOutputStream();
Executor mMjpegExecutor = Executors.newSingleThreadExecutor();
mMjpegExecutor.execute(() -> {
byte[] jpegData = null;
try {
// Immediately serve most recent frame.
synchronized (mBytesLock) {
serveMotionJpegFrame(mCurrentImageBytes, outputStream);
}
// Skip the first frame, since it's old. Then continue to read updated frames.
mmJpegQueue.take();
while ((jpegData = mmJpegQueue.take()) != null) {
serveMotionJpegFrame(jpegData, outputStream);
}
} catch (IOException | InterruptedException e) {
LOG.warn("Interrupted while serving MJPEG data. Exiting MJPEG loop.");
try {
response.close();
} catch (IOException ignore) {
}
}
});
}
示例4: sendContent
import org.simpleframework.http.Response; //导入方法依赖的package包/类
private OutputStream sendContent(Response resp, String contentType) throws IOException {
OutputStream out = resp.getOutputStream();
addStandardHeaders(resp, contentType);
byte[] buffer = new byte[1024];
int len;
while ((len = in.read(buffer)) != -1) {
out.write(buffer, 0, len);
}
out.flush();
return out;
}
示例5: handle
import org.simpleframework.http.Response; //导入方法依赖的package包/类
public void handle(Request request, Response response) {
try {
//PrintStream body = response.getPrintStream();
OutputStream body = response.getOutputStream();
long time = System.currentTimeMillis();
response.setValue("Server", "BlobStationServer/1.0 (Simple 4.0)");
response.setDate("Date", time);
response.setDate("Last-Modified", time);
String file = request.getAddress().getPath().getPath();
// TODO: Check that html/index.html exists
if(file == null || file == "/" || file.lastIndexOf('.') == -1 ||
getClass().getResource("/html"+file) == null) {
file = "/index.html";
}
String extension = file.substring(file.lastIndexOf('.')+1);
if(extension.equals("jpg") || extension.equals("jpeg"))
response.setValue("Content-Type", "image/jpeg");
else if (extension.equals("png") || extension.equals("ico"))
response.setValue("Content-Type", "image/png");
else if (extension.equals("gif"))
response.setValue("Content-Type", "image/gif");
else if (extension.equals("svg") || extension.equals("svgz"))
response.setValue("Content-Type", "image/svg+xml");
else if (extension.equals("js"))
response.setValue("Content-Type", "text/javascript");
else if (extension.equals("css"))
response.setValue("Content-Type", "text/css");
else
response.setValue("Content-Type", "text/html");
String path = getClass().getResource("/html"+file).getPath();
body.write(Files.readAllBytes(Paths.get(path)));
body.close();
} catch(Exception e) {
e.printStackTrace();
}
}