mirror of
https://github.com/itplr-kosit/validator.git
synced 2026-05-25 16:55:39 +00:00
introduce docsify; refactor the daemon
This commit is contained in:
parent
7dc62012a6
commit
91e4d79953
12 changed files with 1038 additions and 26 deletions
|
|
@ -11,15 +11,21 @@ import com.sun.net.httpserver.HttpHandler;
|
|||
*
|
||||
* @author Andreas Penski
|
||||
*/
|
||||
public abstract class BaseHandler implements HttpHandler {
|
||||
abstract class BaseHandler implements HttpHandler {
|
||||
|
||||
protected static final String APPLICATION_XML = "application/xml";
|
||||
|
||||
protected static final int OK = 200;
|
||||
|
||||
protected static void write(final HttpExchange exchange, final byte[] content, final String contentType) throws IOException {
|
||||
final OutputStream os = exchange.getResponseBody();
|
||||
write(exchange, contentType, os -> os.write(content));
|
||||
}
|
||||
|
||||
protected static void write(final HttpExchange exchange, final String contentType, Write write) throws IOException {
|
||||
exchange.getResponseHeaders().add("Content-Type", contentType);
|
||||
exchange.sendResponseHeaders(200, content.length);
|
||||
os.write(content);
|
||||
exchange.sendResponseHeaders(OK, 0);
|
||||
final OutputStream os = exchange.getResponseBody();
|
||||
write.write(os);
|
||||
os.close();
|
||||
}
|
||||
|
||||
|
|
@ -31,4 +37,9 @@ public abstract class BaseHandler implements HttpHandler {
|
|||
os.close();
|
||||
}
|
||||
|
||||
@FunctionalInterface
|
||||
protected interface Write {
|
||||
|
||||
public void write(OutputStream out) throws IOException;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue