Search in sources :

Example 36 with PrintWriter

use of java.io.PrintWriter in project eweb4j-framework by laiweiwei.

the class BDecoder method print.

private static void print(File f, File output) {
    try {
        BDecoder decoder = new BDecoder();
        decoder.setRecoveryMode(false);
        PrintWriter pw = new PrintWriter(new FileWriter(output));
        decoder.print(pw, decoder.decodeStream(new BufferedInputStream(new FileInputStream(f))));
        pw.flush();
    } catch (Throwable e) {
    }
}
Also used : BufferedInputStream(java.io.BufferedInputStream) FileWriter(java.io.FileWriter) FileInputStream(java.io.FileInputStream) PrintWriter(java.io.PrintWriter)

Example 37 with PrintWriter

use of java.io.PrintWriter in project eweb4j-framework by laiweiwei.

the class CommonUtil method getExceptionString.

public static String getExceptionString(Throwable e) {
    if (e == null)
        return "";
    StringWriter strWriter = new StringWriter();
    PrintWriter writer = new PrintWriter(strWriter, true);
    e.printStackTrace(writer);
    StringBuffer sb = strWriter.getBuffer();
    String s = "cause by: \n\t" + sb.toString();
    return s.replace("Caused by:", "<font color='red'>Caused by:");
}
Also used : StringWriter(java.io.StringWriter) PrintWriter(java.io.PrintWriter)

Example 38 with PrintWriter

use of java.io.PrintWriter in project Lazy by l123456789jy.

the class ClassUtils method dumpException.

public static String dumpException(Throwable e) {
    StringWriter sw = new StringWriter(160);
    sw.write(e.getClass().getName());
    sw.write(":\n");
    e.printStackTrace(new PrintWriter(sw));
    return sw.toString();
}
Also used : StringWriter(java.io.StringWriter) PrintWriter(java.io.PrintWriter)

Example 39 with PrintWriter

use of java.io.PrintWriter in project eweb4j-framework by laiweiwei.

the class ActionExecution method injectActionCxt2Pojo.

private void injectActionCxt2Pojo(ReflectUtil ru) throws Exception {
    HttpServletRequest req = this.context.getRequest();
    HttpServletResponse res = this.context.getResponse();
    PrintWriter out = this.context.getWriter();
    HttpSession session = this.context.getSession();
    ActionProp actionProp = this.context.getActionProp();
    QueryParams queryParams = this.context.getQueryParams();
    for (String n : ru.getFieldsName()) {
        Method m = ru.getSetter(n);
        if (m == null)
            continue;
        Class<?> clazz = m.getParameterTypes()[0];
        if (Context.class.isAssignableFrom(clazz)) {
            m.invoke(ru.getObject(), this.context);
        } else if (HttpServletRequest.class.isAssignableFrom(clazz)) {
            m.invoke(ru.getObject(), req);
        } else if (HttpServletResponse.class.isAssignableFrom(clazz)) {
            m.invoke(ru.getObject(), res);
        } else if (PrintWriter.class.isAssignableFrom(clazz)) {
            m.invoke(ru.getObject(), out);
        } else if (ServletOutputStream.class.isAssignableFrom(clazz)) {
            m.invoke(ru.getObject(), this.context.getOut());
        } else if (HttpSession.class.isAssignableFrom(clazz)) {
            m.invoke(ru.getObject(), session);
        } else if (ActionProp.class.isAssignableFrom(clazz)) {
            if (actionProp == null)
                actionProp = new ActionProp(clazz.getName());
            this.context.setActionProp(actionProp);
            m.invoke(ru.getObject(), actionProp);
        } else if (QueryParams.class.isAssignableFrom(clazz)) {
            m.invoke(ru.getObject(), queryParams);
        } else if (Validation.class.isAssignableFrom(clazz)) {
            m.invoke(ru.getObject(), this.context.getValidation());
        } else {
            /* 如果找不到注入的类型,则尝试从IOC容器获取 */
            Object obj = IOC.getBean(n);
            if (obj != null)
                m.invoke(ru.getObject(), obj);
        }
    }
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) HttpSession(javax.servlet.http.HttpSession) HttpServletResponse(javax.servlet.http.HttpServletResponse) Method(java.lang.reflect.Method) PrintWriter(java.io.PrintWriter)

Example 40 with PrintWriter

use of java.io.PrintWriter in project commons by twitter.

the class AbortHandler method doPost.

@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException {
    LOG.info(String.format("Received abort HTTP signal from %s (%s)", req.getRemoteAddr(), req.getRemoteHost()));
    resp.setContentType("text/plain");
    PrintWriter writer = resp.getWriter();
    try {
        writer.println("Aborting process NOW!");
        writer.close();
        abortListener.run();
    } catch (Exception e) {
        LOG.log(Level.WARNING, "Abort failed.", e);
    }
}
Also used : IOException(java.io.IOException) PrintWriter(java.io.PrintWriter)

Aggregations

PrintWriter (java.io.PrintWriter)4039 StringWriter (java.io.StringWriter)1201 IOException (java.io.IOException)788 File (java.io.File)643 Test (org.junit.Test)512 FileWriter (java.io.FileWriter)318 FileOutputStream (java.io.FileOutputStream)313 OutputStreamWriter (java.io.OutputStreamWriter)278 BufferedReader (java.io.BufferedReader)202 ArrayList (java.util.ArrayList)196 ByteArrayOutputStream (java.io.ByteArrayOutputStream)162 HttpServletResponse (javax.servlet.http.HttpServletResponse)145 InputStreamReader (java.io.InputStreamReader)140 Date (java.util.Date)131 HashMap (java.util.HashMap)130 ServletException (javax.servlet.ServletException)126 BufferedWriter (java.io.BufferedWriter)125 HttpServletRequest (javax.servlet.http.HttpServletRequest)125 FastPrintWriter (com.android.internal.util.FastPrintWriter)124 Map (java.util.Map)118