Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- char[] updatedArr = new char[pars.getHttpRequestParser().getFileName().length()-1];
- pars.getHttpRequestParser().getFileName().getChars(1, pars.getHttpRequestParser().getFileName().length(), updatedArr, 0);
- File startingDirectory = new File(String.valueOf(updatedArr));
- if (startingDirectory.isDirectory()) {
- PrintWriter out = new PrintWriter(new BufferedOutputStream(pars.getOutputStream()));
- BufferedOutputStream dataOut = new BufferedOutputStream(pars.getOutputStream());
- FileListing listing = new FileListing();
- List<File> files = listing.getFileListing(startingDirectory);
- File file1 = new File(WEB_ROOT, METHOD_NOT_SUPPORTED);
- int fileLength = (int) file1.length();
- String contentMimeType = "text/html";
- long timeStamp = file1.lastModified();
- out.println("HTTP/1.1 200 OK");
- out.println("Server: Java HTTP Server from : 1.0");
- out.println("Last-Modified: " + timeStamp);
- out.println("Date: " + new Date());
- out.println("Content-type: " + contentMimeType);
- out.println("Content-length: " + fileLength);
- out.println(); // blank line between headers and content, very important !
- out.flush();
- dataOut.write("<html><body>".getBytes());
- for (File file : files) {
- Path rootPath = Paths.get(new File(String.valueOf(WEB_ROOT)).toURI()); // this can be static
- Path filePath = Paths.get(file.toURI());
- String pathString = rootPath.relativize(filePath).toString();
- String mesaj="<a href=\"/" + pathString + "\">" + file.getName() + "</a><br>";
- dataOut.write(mesaj.getBytes());
- dataOut.write("<a href=\"/".getBytes());
- dataOut.write(pathString.getBytes());
- dataOut.write("\">".getBytes());
- dataOut.write(file.getName().getBytes());
- dataOut.write("</a><br>".getBytes());
- }
- dataOut.write("</body></html>".getBytes());
- dataOut.flush();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement