Example usage for java.io PrintWriter print

List of usage examples for java.io PrintWriter print

Introduction

In this page you can find the example usage for java.io PrintWriter print.

Prototype

public void print(Object obj) 

Source Link

Document

Prints an object.

Usage

From source file:gov.nih.nci.caarray.application.translation.geosoft.GeoSoftFileWriterUtil.java

private static void writeSources(PrintWriter out, Set<Source> sources) {
    out.print("!Sample_source_name=");
    String del = "";

    for (final Source source : sources) {
        out.print(del);/*from  w  w  w . j  a va  2s . c  o  m*/
        out.print(source.getName());
        del = "; ";
    }
    out.println();
}

From source file:com.google.gsa.valve.modules.utils.HTTPAuthZProcessor.java

/**
 * If the document is HTML, this method processes its content in order to 
 * rewrite the URLs it includes/*  w w  w . ja  va  2 s  .  co m*/
 * 
 * @param response HTTP response
 * @param method HTTP method
 * @param url document url
 * @param loginUrl login url
 * @param contenType content Type
 * 
 * @throws IOException
 * @throws ParserException
 */
public static void processHTML(HttpServletResponse response, HttpMethodBase method, String url, String loginUrl,
        String contentType) throws IOException, ParserException {
    logger.debug("Processing an HTML document");

    String stream = null;
    Parser parser = null;
    NodeVisitor visitor = null;

    // Retrieve HTML stream
    stream = readFully(new InputStreamReader(method.getResponseBodyAsStream()));

    // Protection
    if (stream != null) {
        logger.debug("Stream content size: " + stream.length());
        // Parse HTML stream to replace any links to include the path to the valve
        parser = Parser.createParser(stream, null);

        // Instantiate visitor
        visitor = new HTTPVisitor(url, loginUrl);
        // Parse nodes
        parser.visitAllNodesWith(visitor);

        // Get writer
        PrintWriter out = response.getWriter();

        // Push HTML content
        if (out != null) {
            out.flush();
            out.print(((HTTPVisitor) visitor).getModifiedHTML());
            out.close();
            logger.debug("Wrote: " + ((HTTPVisitor) visitor).getModifiedHTML().length());
        }

        response.setHeader("Content-Type", contentType);

        //  Garbagge collect
        stream = null;
        parser = null;
        visitor = null;
    }
}

From source file:gov.nih.nci.caarray.application.translation.geosoft.GeoSoftFileWriterUtil.java

private static void writeExperimentContact(ExperimentContact c, PrintWriter out) {
    final Person p = c.getPerson();
    out.print("!Series_contributor=");
    out.print(p.getFirstName());/*  w  ww  .ja va  2 s  .  co m*/
    out.print(',');
    if (StringUtils.isNotBlank(p.getMiddleInitials())) {
        out.print(p.getMiddleInitials());
        out.print(",");
    }
    out.println(p.getLastName());
}

From source file:gov.nih.nci.caarray.application.translation.geosoft.GeoSoftFileWriterUtil.java

private static void writeDescription(PrintWriter out, Hybridization h, Set<Sample> samples) {
    out.print("!Sample_description=");
    final String desc = h.getDescription();
    if (StringUtils.isNotBlank(desc)) {
        out.println(desc);/*from   w ww . ja va  2s  .c om*/
    } else {
        String comma = "";
        for (final Sample s : samples) {
            out.print(comma);
            out.print(s.getName());
            comma = ", ";
        }
        out.println();
    }
}

From source file:com.jaspersoft.jasperserver.rest.RESTUtils.java

/**
 * Set the status of the response to the errorCode and send the message to the client
 *
 * @param errorCode the errorCode (see HttpServletResponse for common HTTP status codes)
 * @param response the HttpServletResponse
 * @param body if null, an empty string is sent.
 *///w  w  w. j av a 2  s . c  o  m
public static void setStatusAndBody(int errorCode, HttpServletResponse response, String body) {
    response.setStatus(errorCode);
    // we can put an error in the output too (so avoid the webserver to display unwanted pages...)
    try {
        PrintWriter pw = response.getWriter();
        pw.print((body == null) ? "" : body);
    } catch (Exception ioEx) {
        // do nothing. If we have an I/O error, we just avoid to specify unuseful errors here.
        log.error("Error sending output a file", ioEx);
    }
}

From source file:com.sunchenbin.store.feilong.servlet.http.ResponseUtil.java

/**
 * .//from  w  ww. jav  a 2s.  c o m
 *
 * @param response
 *            HttpServletResponse
 * @param content
 *            
 * @param contentType
 *            the content type
 * @param characterEncoding
 *            the character encoding
 * @see javax.servlet.ServletResponse#getWriter()
 * @see java.io.PrintWriter#print(Object)
 * @see java.io.PrintWriter#flush()
 * @since 1.0.9
 */
public static void write(HttpServletResponse response, Object content, String contentType,
        String characterEncoding) {
    try {
        //? ? getWriter?
        if (Validator.isNotNullOrEmpty(contentType)) {
            response.setContentType(contentType);
        }
        if (Validator.isNotNullOrEmpty(characterEncoding)) {
            response.setCharacterEncoding(characterEncoding);
        }

        PrintWriter printWriter = response.getWriter();
        printWriter.print(content);
        printWriter.flush();

        //http://www.iteye.com/problems/56543
        //tomcatjetty?? printWriter.close();
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
}

From source file:de.jgoldhammer.alfresco.jscript.jmx.JmxDumpUtil.java

/**
 * Outputs a single row in a two-column table. The first column is padded
 * with spaces so that the second column is aligned.
 * /* ww w .  ja v  a 2  s  .  c o  m*/
 * @param out
 *            PrintWriter to write the output to
 * @param maxKeyLength
 *            maximum number of characters in the first column
 * @param key
 *            the first column value
 * @param value
 *            the second column value
 * @param nestLevel
 *            the nesting level
 * @throws IOException
 *             Signals that an I/O exception has occurred.
 */
private static void outputRow(PrintWriter out, int maxKeyLength, String key, Object value, int nestLevel)
        throws IOException {
    indent(out, nestLevel);
    out.print(key);
    for (int i = key.length() - 1; i < maxKeyLength; i++) {
        out.print(' ');
    }
    outputValue(out, value, nestLevel);
}

From source file:org.apache.asterix.api.http.server.ResultUtil.java

public static void printError(PrintWriter pw, Throwable e, boolean comma) {
    Throwable rootCause = getRootCause(e);
    if (rootCause == null) {
        rootCause = e;//  w ww  .j av  a  2 s  .  c o m
    }
    final boolean addStack = false;
    pw.print("\t\"");
    pw.print(AbstractQueryApiServlet.ResultFields.ERRORS.str());
    pw.print("\": [{ \n");
    printField(pw, QueryServiceServlet.ErrorField.CODE.str(), "1");
    final String msg = rootCause.getMessage();
    printField(pw, QueryServiceServlet.ErrorField.MSG.str(),
            JSONUtil.escape(msg != null ? msg : rootCause.getClass().getSimpleName()), addStack);
    pw.print(comma ? "\t}],\n" : "\t}]\n");
}

From source file:at.wada811.dayscounter.CrashExceptionHandler.java

public static void makeReportFile(Context context, Throwable throwable) {
    PrintWriter writer = null;
    FileOutputStream outputStream;
    try {//from   w w w .ja va2s  .  com
        outputStream = context.openFileOutput(FILE_NAME, Context.MODE_PRIVATE);
        writer = new PrintWriter(outputStream);
        String report = CrashExceptionHandler.makeReport(context, throwable);
        writer.print(report);
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } finally {
        if (writer != null) {
            writer.close();
        }
    }
}

From source file:gov.nih.nci.caarray.application.translation.geosoft.GeoSoftFileWriterUtil.java

private static void writeData(Hybridization h, PrintWriter out) {
    for (final RawArrayData rad : h.getRawDataCollection()) {
        out.print("!Sample_supplementary_file=");
        out.println(rad.getDataFile().getName());
    }/*www.j  a va 2 s .com*/
    for (final DerivedArrayData dad : h.getDerivedDataCollection()) {
        if (GeoSoftExporterBean.AFFYMETRIX_CHP_TYPE_NAME.equals(dad.getDataFile().getFileType().getName())) {
            out.print("!Sample_table=");
            out.println(dad.getDataFile().getName());
        } else {
            out.print("!Sample_supplementary_file=");
            out.println(dad.getDataFile().getName());
        }
    }
}