Package org.apache.http.entity

Examples of org.apache.http.entity.EntityTemplate


                Writer writer = new OutputStreamWriter(outstream, "UTF-8");
                writer.write(content);
                writer.flush();
            }
        };
        HttpEntity entity = new EntityTemplate(cp);
        post.setEntity(entity);
    }
View Full Code Here


            public void writeTo(OutputStream out) throws IOException {
                RDFDataMgr.write(out, graph, syntax) ;
            }
        } ;

        EntityTemplate entity = new EntityTemplate(producer) ;
        String ct = syntax.getLang().getContentType().getContentType() ;
        entity.setContentType(ct) ;
        return entity ;
    }
View Full Code Here

            public void writeTo(OutputStream out) throws IOException {
                RDFDataMgr.write(out, graph, sendLang) ;
            }
        } ;
       
        EntityTemplate entity = new EntityTemplate(producer) ;
        String ct = sendLang.getLang().getContentType().getContentType() ;
        entity.setContentType(ct) ;
        return entity ;
    }       
View Full Code Here

                statusCode == HttpStatus.SC_RESET_CONTENT ||
                statusCode == HttpStatus.SC_NOT_MODIFIED) {
            return;
        }

        EntityTemplate body = createEntity();
        body.setContentType(contentType);
        response.setEntity(body);
    }
View Full Code Here

        body.setContentType(contentType);
        response.setEntity(body);
    }

    private EntityTemplate createEntity() {
        return new EntityTemplate(new ContentProducer() {
            public void writeTo(OutputStream outputStream) throws IOException {
                OutputStreamWriter writer = new OutputStreamWriter(outputStream, "UTF-8");
                writer.write(payload);
                writer.flush();
            }
View Full Code Here

      ContentProducer producer = new ContentProducer() {
        public void writeTo(OutputStream out) throws IOException {
          out.write(o.toByteArray());
        }
      };
      HttpEntity entity = new EntityTemplate(producer);
      response.setEntity(entity);
      this.out = new ServletOutputStream() {
        @Override
        public void write(int b) throws IOException {
          o.write((int)b);
View Full Code Here

                        } catch (Exception e) {
                            throw new IOException(e);
                        }
                    }
                };
                entity = new EntityTemplate(cp);
            } else {
                // Single string argument
                entity = new StringEntity((String)args[0], "UTF-8");
            }
View Full Code Here

        } else if (method.equals("GET")) {
            final File file = new File(this.docRoot, URLDecoder.decode(
                    target, "UTF-8"));
            if (!file.exists()) {
                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);
                log.error("找不到文件" + file.getPath(), true);
            } else if (!file.canRead() || file.isDirectory()) {
                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);
                log.error("无法读取文件" + file.getPath(), true);
            } else {
                response.setStatusCode(HttpStatus.SC_OK);
                FileEntity body = new FileEntity(file, "text/html");
View Full Code Here

           
            final File file = new File(this.docRoot, URLDecoder.decode(target));
            if (!file.exists()) {

                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()) {
               
                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 {
               
View Full Code Here

            String target = request.getRequestLine().getUri();
            final File file = new File(this.docRoot, URLDecoder.decode(target, "UTF-8"));
            if (!file.exists()) {

                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()) {
               
                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 {
               
View Full Code Here

TOP

Related Classes of org.apache.http.entity.EntityTemplate

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.