Logo Search packages:      
Sourcecode: jaminid version File versions  Download package

void com::prolixtech::jaminid::Response::sendFile ( File  cFile  )  throws Exception [inline]

sends a file to the client. Sets the MIME type accordingly

Parameters:
cFile the file to send
Exceptions:
IOException 

Definition at line 152 of file Response.java.

References com::prolixtech::jaminid::Request::getHeader(), publishHeader(), setHeaderLine(), and setStatus().

Referenced by com::prolixtech::jaminid_examples::SimpleServer::demultiplex(), and com::prolixtech::jaminid_examples::ajax::SimpleAjaxServer::demultiplex().

                                                      {
        String lastModifiedGMT = Connection.getGMTString(new Date(cFile
                .lastModified()));
        String modifiedCondition = (String) this.masterRequest.getHeader().get(
                Protocol.HQ_IFMODSINCE);

        if (lastModifiedGMT.equals(modifiedCondition)) {
            setStatus(Protocol.NOT_MODIFIED);
            setHeaderLine(ProtocolResponseHeader.Content_Length, "0");
        } else {

            String canonFile = cFile.getCanonicalPath();
            String fileExt = canonFile.substring(canonFile.lastIndexOf("."));
            String type = Protocol.getMIME(fileExt);
            setHeaderLine(ProtocolResponseHeader.Content_Type, type);

            setHeaderLine(ProtocolResponseHeader.Content_Length, "" + cFile.length());
            setHeaderLine(ProtocolResponseHeader.Last_Modified, lastModifiedGMT);

            publishHeader();

            java.io.BufferedInputStream bfin = new java.io.BufferedInputStream(
                    new java.io.FileInputStream(cFile));
            int in;
            byte[] bin = new byte[4096];
            while (true) {
                int bytesRead = bfin.read(bin);
                if (bytesRead < 0)
                    break;
                out.write(bin, 0, bytesRead);
            }

        }
    }


Generated by  Doxygen 1.6.0   Back to index