/** * Create output stream. * * @param port the port * @param path the path * @param mimeType the mime type * @return the output stream * @throws IOException the io exception */ @javax.annotation.Nonnull public static FileNanoHTTPD create(final int port, @Nonnull final File path, final String mimeType) throws IOException { return new FileNanoHTTPD(path, port).init(); }
/** * Init stream nano httpd. * * @return the stream nano httpd * @throws IOException the io exception */ @javax.annotation.Nonnull public FileNanoHTTPD init() throws IOException { start(30000); return this; }
setArchiveHome(root.toURI()); primaryOut = new PrintStream(new FileOutputStream(new File(root, getName().toString()))); FileNanoHTTPD httpd = httpPort <= 0 ? null : new FileNanoHTTPD(root, httpPort); if (null != httpd) httpd.addGET("", "text/html", out -> { try { write(); if (null != httpd) httpd.addGET("pdf", "application/pdf", out -> { try { write(); if (null != httpd) httpd.addGET("shutdown", "text/plain", out -> { try (PrintStream printStream = new PrintStream(out)) { printStream.print("Closing..."); if (null != httpd) { try { httpd.init(); } catch (Throwable e) { log.warn("Error starting web server", e); if (null != httpd) new Thread(() -> { try { while (!this.httpd.isAlive()) Thread.sleep(100); if (isAutobrowse()) Desktop.getDesktop().browse(new URI(String.format("http://localhost:%d", httpPort))); } catch (InterruptedException | IOException | URISyntaxException e) { this.httpd.stop(); });
@Override @javax.annotation.Nonnull public StreamNanoHTTPD init() throws IOException { super.init(); if (!GraphicsEnvironment.isHeadless() && Desktop.isDesktopSupported() && Desktop.getDesktop().isSupported(Desktop.Action.BROWSE)) new Thread(() -> { try { Thread.sleep(100); if (null != gatewayUri && isAutobrowse()) Desktop.getDesktop().browse(gatewayUri); } catch (@javax.annotation.Nonnull final Exception e) { e.printStackTrace(); } }).start(); return this; }
@Override public Response serve(final IHTTPSession session) { String requestPath = session.getUri(); while (requestPath.startsWith("/")) { requestPath = requestPath.substring(1); } if (null != primaryFile && requestPath.equals(primaryFile.getName())) { try { @javax.annotation.Nonnull final Response response = NanoHTTPD.newChunkedResponse(Response.Status.OK, mimeType, new BufferedInputStream(dataReciever.newInputStream())); response.setGzipEncoding(false); return response; } catch (@javax.annotation.Nonnull final IOException e) { throw new RuntimeException(e); } } else { return super.serve(session); } }
setArchiveHome(root.toURI()); primaryOut = new PrintStream(new FileOutputStream(new File(root, getName().toString()))); FileNanoHTTPD httpd = httpPort <= 0 ? null : new FileNanoHTTPD(root, httpPort); if (null != httpd) httpd.addGET("", "text/html", out -> { try { write(); if (null != httpd) httpd.addGET("pdf", "application/pdf", out -> { try { write(); if (null != httpd) httpd.addGET("shutdown", "text/plain", out -> { try (PrintStream printStream = new PrintStream(out)) { printStream.print("Closing..."); if (null != httpd) { try { httpd.init(); } catch (Throwable e) { log.warn("Error starting web server", e); if (null != httpd) new Thread(() -> { try { while (!this.httpd.isAlive()) Thread.sleep(100); if (isAutobrowse()) Desktop.getDesktop().browse(new URI(String.format("http://localhost:%d", httpPort))); } catch (InterruptedException | IOException | URISyntaxException e) { this.httpd.stop(); });
@Override @javax.annotation.Nonnull public StreamNanoHTTPD init() throws IOException { super.init(); if (!GraphicsEnvironment.isHeadless() && Desktop.isDesktopSupported() && Desktop.getDesktop().isSupported(Desktop.Action.BROWSE)) new Thread(() -> { try { Thread.sleep(100); if (null != gatewayUri && isAutobrowse()) Desktop.getDesktop().browse(gatewayUri); } catch (@javax.annotation.Nonnull final Exception e) { e.printStackTrace(); } }).start(); return this; }
@Override public Response serve(final IHTTPSession session) { String requestPath = session.getUri(); while (requestPath.startsWith("/")) { requestPath = requestPath.substring(1); } if (null != primaryFile && requestPath.equals(primaryFile.getName())) { try { @javax.annotation.Nonnull final Response response = NanoHTTPD.newChunkedResponse(Response.Status.OK, mimeType, new BufferedInputStream(dataReciever.newInputStream())); response.setGzipEncoding(false); return response; } catch (@javax.annotation.Nonnull final IOException e) { throw new RuntimeException(e); } } else { return super.serve(session); } }
/** * Create output stream. * * @param port the port * @param path the path * @param mimeType the mime type * @return the output stream * @throws IOException the io exception */ @javax.annotation.Nonnull public static FileNanoHTTPD create(final int port, @Nonnull final File path, final String mimeType) throws IOException { return new FileNanoHTTPD(path, port).init(); }
/** * Init stream nano httpd. * * @return the stream nano httpd * @throws IOException the io exception */ @javax.annotation.Nonnull public FileNanoHTTPD init() throws IOException { start(30000); return this; }