Jak wysłać dane pliku PDF jako odpowiedź za pomocą serwletu?

Moim wymaganiem jest odpowiadanie na dane PDF do klienta mobilnego (iPhone) za pomocą serwletu HTTP.

Zrobiłem w następujący sposób, ale nie otrzymuję oczekiwanych danych wyjściowych od klienta.

    PrintWriter out = response.getWriter();

    String aInputFileName = "/Users/hcl/Desktop/Easwar/sample.pdf";
        log("Reading in binary file named : " + aInputFileName);
        File file = new File(aInputFileName);
        log("File size: " + file.length());
        byte[] result = new byte[(int)file.length()];
        System.out.println("Length : "+  result.length);
        try {
          InputStream input = null;
          try {
            int totalBytesRead = 0;
            input = new BufferedInputStream(new FileInputStream(file));
            while(totalBytesRead < result.length){
              int bytesRemaining = result.length - totalBytesRead;
              //input.read() returns -1, 0, or more :
              int bytesRead = input.read(result, totalBytesRead, bytesRemaining); 
              if (bytesRead > 0){
                totalBytesRead = totalBytesRead + bytesRead;
              }
            }
        response.setHeader("Content-Type", "application/pdf");

        out.println(result);

Czy metoda, którą śledzę, jest właściwa? Proszę o radę.

Dzięki.

questionAnswers(2)

yourAnswerToTheQuestion