Code example for OutputStreamWriter

Methods: flush, write

0
 
                response.setStatusCode(HttpStatus.SC_NOT_FOUND); 
                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("File "); 
                        writer.write(file.getPath()); 
                        writer.write(" not found"); 
                        writer.write("</h1></body></html>"); 
                        writer.flush(); 
                    } 
                     
                }); 
                body.setContentType("text/html; charset=UTF-8"); 
                response.setEntity(body); 
                System.out.println("File " + file.getPath() + " not found"); 
                 
            } else if (!file.canRead() || file.isDirectory()) {