private void readFile() {
        if(parameters.getPath() != null) {
            boolean isDirectory = false;
            String dir = DOCUMENT_ROOT + parameters.getPath();
            File file = new File(dir);
            try {
                if (!file.getCanonicalPath().contains(DOCUMENT_ROOT)) {
                    parameters.setCode(403);
                    writeToSocket();
                } else {
                    if (file.isDirectory()) {
                        dir += "index.html";
                        file = new File(dir);
                        isDirectory = true;
                        parameters.setSuffix(".html");
                    }
                    if (!file.exists()) {
                        throw new FileNotFoundException("File not found");
                    } else
                        parameters.setLength(file.length());

                    switch (parameters.getMethod()) {
                        case "GET":
                            AsynchronousFileChannel fileChannel = AsynchronousFileChannel.open(file.toPath(), StandardOpenOption.READ);
                            ByteBuffer buffer = ByteBuffer.allocate((int) file.length());
                            fileChannel.read(buffer, 0, null, new FileReadHandler<Integer, Void>(this, buffer, fileChannel));
                            break;
                        default:
                            writeToSocket();
                    }
                }

            } catch (FileNotFoundException e) {
                e.printStackTrace();
                if (isDirectory)
                    parameters.setCode(403);
                else
                    parameters.setCode(404);
                writeToSocket();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }