Code example for OutputStreamWriter

Methods: flush, write

0
                 
                response.setStatusCode(HttpStatus.SC_FORBIDDEN); 
                EntityTemplate body = new EntityTemplate(new ContentProducer() { 
                     
                    public void writeTo(final OutputStream outstream) throws IOException {
                        OutputStreamWriter writer = new OutputStreamWriter(outstream, "UTF-8"); 
                        writer.write("<html><body><h1>");
                        writer.write("Access denied");
                        writer.write("</h1></body></html>");
                        writer.flush();
                    } 
                     
                }); 
                body.setContentType("text/html; charset=UTF-8"); 
                response.setEntity(body); 
                System.out.println("Cannot read file " + file.getPath()); 
                 
            } else { 
                 
                response.setStatusCode(HttpStatus.SC_OK); 
                FileEntity body = new FileEntity(file, "text/html");