/** Create a print writer that uses UTF-8 encoding */ static public PrintWriter asPrintWriterUTF8(OutputStream out) { return new PrintWriter(asUTF8(out)); }
/** Create an buffered reader that uses UTF-8 encoding */ static public BufferedReader asBufferedUTF8(InputStream in) { return new BufferedReader(asUTF8(in)) ; }
/** Create an buffered reader that uses UTF-8 encoding */ static public BufferedReader asBufferedUTF8(InputStream in) { return new BufferedReader(asUTF8(in)) ; }
/** Create an buffered reader that uses UTF-8 encoding */ static public BufferedReader asBufferedUTF8(InputStream in) { return new BufferedReader(asUTF8(in)) ; }
/** Create a print writer that uses UTF-8 encoding */ static public PrintWriter asPrintWriterUTF8(OutputStream out) { return new PrintWriter(asUTF8(out)); }
/** Create a print writer that uses UTF-8 encoding */ static public PrintWriter asPrintWriterUTF8(OutputStream out) { return new PrintWriter(asUTF8(out)); }
/** Read a whole stream as UTF-8 * * @param in InputStream to be read * @return String * @throws IOException */ public static String readWholeFileAsUTF8(InputStream in) throws IOException { // Don't buffer - we're going to read in large chunks anyway Reader r = asUTF8(in) ; return readWholeFileAsUTF8(r) ; }
/** Read a whole stream as UTF-8 * * @param in InputStream to be read * @return String * @throws IOException */ public static String readWholeFileAsUTF8(InputStream in) throws IOException { // Don't buffer - we're going to read in large chunks anyway try ( Reader r = asUTF8(in) ) { return readWholeFileAsUTF8(r) ; } }
/** Read a whole stream as UTF-8 * * @param in InputStream to be read * @return String * @throws IOException */ public static String readWholeFileAsUTF8(InputStream in) throws IOException { // Don't buffer - we're going to read in large chunks anyway try ( Reader r = asUTF8(in) ) { return readWholeFileAsUTF8(r) ; } }
/** Wrap in a general writer interface */ static public AWriter wrapUTF8(OutputStream out) { return wrap(asUTF8(out)) ; }
/** Wrap in a general writer interface */ static public AWriter wrapUTF8(OutputStream out) { return wrap(asUTF8(out)) ; }
/** Wrap in a general writer interface */ static public AWriter wrapUTF8(OutputStream out) { return wrap(asUTF8(out)); }
@Override public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException { String method = request.getMethod(); if ( !method.equals(HttpMethod.GET.asString()) && !method.equals(HttpMethod.POST.asString()) && !method.equals(HttpMethod.HEAD.asString()) ) return ; response.setContentType(MimeTypes.Type.TEXT_PLAIN_UTF_8.asString()) ; ServletOps.setNoCache(response) ; ByteArrayOutputStream bytes = new ByteArrayOutputStream(1024) ; try ( Writer writer = IO.asUTF8(bytes) ) { String reason = (response instanceof Response) ? ((Response)response).getReason() : null; handleErrorPage(request, writer, response.getStatus(), reason) ; writer.flush(); response.setContentLength(bytes.size()) ; response.getOutputStream().write(bytes.toByteArray()) ; } }
@Override public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException { String method = request.getMethod(); if ( !method.equals(HttpMethod.GET.asString()) && !method.equals(HttpMethod.POST.asString()) && !method.equals(HttpMethod.HEAD.asString()) ) return ; response.setContentType(MimeTypes.Type.TEXT_PLAIN_UTF_8.asString()) ; ServletOps.setNoCache(response) ; ByteArrayOutputStream bytes = new ByteArrayOutputStream(1024) ; try ( Writer writer = IO.asUTF8(bytes) ) { String reason = (response instanceof Response) ? ((Response)response).getReason() : null; handleErrorPage(request, writer, response.getStatus(), reason) ; writer.flush(); response.setContentLength(bytes.size()) ; response.getOutputStream().write(bytes.toByteArray()) ; } }
/** Make PeekReader where the input is UTF8 : BOM is removed */ public static PeekReader makeUTF8(InputStream in) { // This is the best route to make a PeekReader because it avoids // chances of wrong charset for a Reader say. PeekReader pr ; if ( true ) { Reader r = IO.asUTF8(in) ; // This adds reader-level buffering pr = make(r) ; } else { // This is a bit slower - reason unknown. InputStreamBuffered in2 = new InputStreamBuffered(in) ; CharStream r = new InStreamUTF8(in2) ; pr = new PeekReader(r) ; } // Skip BOM. int ch = pr.peekChar() ; if ( ch == Chars.BOM ) // Skip BOM pr.readChar() ; return pr ; }
/** Make PeekReader where the input is UTF8 : BOM is removed */ public static PeekReader makeUTF8(InputStream in) { // This is the best route to make a PeekReader because it avoids // chances of wrong charset for a Reader say. PeekReader pr ; if ( true ) { Reader r = IO.asUTF8(in) ; // This adds reader-level buffering pr = make(r) ; } else { // This is a bit slower - reason unknown. InputStreamBuffered in2 = new InputStreamBuffered(in) ; CharStream r = new InStreamUTF8(in2) ; pr = new PeekReader(r) ; } // Skip BOM. int ch = pr.peekChar() ; if ( ch == Chars.BOM ) // Skip BOM pr.readChar() ; return pr ; }
/** Make PeekReader where the input is UTF8 : BOM is removed */ public static PeekReader makeUTF8(InputStream in) { // This is the best route to make a PeekReader because it avoids // chances of wrong charset for a Reader say. PeekReader pr ; if ( true ) { Reader r = IO.asUTF8(in) ; // This adds reader-level buffering pr = make(r) ; } else { // This is a bit slower - reason unknown. InputStreamBuffered in2 = new InputStreamBuffered(in) ; CharStream r = new InStreamUTF8(in2) ; pr = new PeekReader(r) ; } // Skip BOM. int ch = pr.peekChar() ; if ( ch == Chars.BOM ) // Skip BOM pr.readChar() ; return pr ; }