| | |
| | | |
| | | import com.sun.net.httpserver.HttpExchange; |
| | | import com.sun.net.httpserver.HttpHandler; |
| | | import de.uhilger.avdirektor.App; |
| | | import java.io.File; |
| | | import java.io.FileInputStream; |
| | | import java.io.IOException; |
| | |
| | | |
| | | private static final Logger logger = Logger.getLogger(FileHandler.class.getName()); |
| | | |
| | | private String basePath; |
| | | private final String basePath; |
| | | |
| | | public FileHandler(String basePath) { |
| | | this.basePath = basePath; |
| | |
| | | fName += "index.html"; |
| | | } |
| | | OutputStream os = t.getResponseBody(); |
| | | File outFile = new File(basePath, fName); |
| | | if(outFile.exists()) { |
| | | t.sendResponseHeaders(200, outFile.length()); |
| | | InputStream in = new FileInputStream(outFile); |
| | | File file = new File(basePath, fName); |
| | | if(file.exists()) { |
| | | t.sendResponseHeaders(200, file.length()); |
| | | InputStream in = new FileInputStream(file); |
| | | int b = in.read(); |
| | | while(b > -1) { |
| | | os.write(b); |