forked from piotrpolak/android-http-server
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStreaming.java
More file actions
35 lines (29 loc) · 1.1 KB
/
Copy pathStreaming.java
File metadata and controls
35 lines (29 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
/**************************************************
* Android Web Server
* Based on JavaLittleWebServer (2008)
* <p/>
* Copyright (c) Piotr Polak 2008-2016
**************************************************/
package example;
import java.io.IOException;
import java.nio.charset.Charset;
import ro.polak.http.exception.ServletException;
import ro.polak.http.servlet.HttpServletRequest;
import ro.polak.http.servlet.HttpServletResponse;
import ro.polak.http.servlet.HttpServlet;
/**
* Writing to output stream.
*/
public class Streaming extends HttpServlet {
private static final Charset CHARSET = Charset.forName("UTF-8");
@Override
public void service(HttpServletRequest request, HttpServletResponse response) throws ServletException {
try {
byte[] message = "<p>Writing to output stream directly, without chunking.</p>".getBytes(CHARSET);
response.setContentLength(message.length);
response.getOutputStream().write(message);
} catch (IOException e) {
throw new ServletException("Unable to write to output stream", e);
}
}
}