Example usage for java.io PrintWriter flush

List of usage examples for java.io PrintWriter flush

Introduction

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

Prototype

public void flush() 

Source Link

Document

Flushes the stream.

Usage

From source file:cc.kune.core.server.rack.filters.rest.CORSServiceFilter.java

@Override
protected void customDoFilter(final HttpServletRequest request, final HttpServletResponse response,
        final FilterChain chain) throws IOException, ServletException {
    final boolean cors = (Boolean) request.getAttribute("cors.isCorsRequest");

    // This part is similar to RESTServiceFilter
    final String methodName = RackHelper.getMethodName(request, pattern);
    final ParametersAdapter parameters = new ParametersAdapter(request);
    LOG.debug((cors ? "" : "NO ") + "CORS METHOD: '" + methodName + "' on: " + serviceClass.getSimpleName());

    response.setCharacterEncoding("utf-8");

    // See: http://software.dzhuvinov.com/cors-filter-tips.html
    response.setContentType("text/plain");

    final RESTResult result = transactionalFilter.doService(serviceClass, methodName, parameters,
            getInstance(serviceClass));//from w w w .  jav  a 2s.  c o m
    if (result != null) {
        final Exception exception = result.getException();
        if (exception != null) {
            if (exception instanceof InvocationTargetException && ((InvocationTargetException) exception)
                    .getTargetException() instanceof ContentNotFoundException) {
                printMessage(response, HttpServletResponse.SC_NOT_FOUND, result.getException().getMessage());
            } else {
                printMessage(response, HttpServletResponse.SC_BAD_REQUEST, result.getException().getMessage());
            }
        } else {
            final String output = result.getOutput();
            if (output != null) {
                final PrintWriter writer = response.getWriter();
                writer.print(output);
                writer.flush();
            } else {
                // Is not for us!!!
            }
        }
    }
}

From source file:com.ponysdk.core.export.xml.XMLExporter.java

public void exportXMLString(final String fileName, final String content) throws Exception {
    // Set MIME type to binary data to prevent opening of PDF in browser window
    UIContext.get().stackStreamRequest((req, response) -> {
        response.reset();/*from ww  w  . j av  a2 s  .c o m*/
        response.setContentType("application/xml");
        response.setHeader("Content-Disposition", "attachment; filename=" + fileName);
        PrintWriter printer;
        try {
            printer = response.getWriter();
            printer.print(content);
            printer.flush();
            printer.close();
        } catch (final IOException e) {
            log.error("Error when exporting", e);
        }
    });
}

From source file:de.ailis.oneinstance.OneInstanceClient.java

/**
 * @see java.lang.Runnable#run()//w  ww.  j av  a 2  s .  c om
 */
@Override
public void run() {
    try {
        try {
            // Send the application ID.
            PrintWriter out = new PrintWriter(new OutputStreamWriter(this.socket.getOutputStream(), "UTF-8"));
            out.println(this.appId);
            out.flush();

            // Read the data from the client
            InputStream in = this.socket.getInputStream();
            ObjectInputStream objIn = new ObjectInputStream(in);
            File workingDir = (File) objIn.readObject();
            String[] args = (String[]) objIn.readObject();

            // Call event handler
            boolean result = OneInstance.getInstance().fireNewInstance(workingDir, args);

            // Send the result
            out.println(result ? "start" : "exit");
            out.flush();

            // Wait for client disconnect.
            in.read();
        } finally {
            this.socket.close();
        }
    } catch (IOException e) {
        LOG.error(e.toString(), e);
    } catch (ClassNotFoundException e) {
        LOG.error(e.toString(), e);
    }
}

From source file:jp.eisbahn.oauth2.server.spi.servlet.TokenServlet.java

/**
 * Issue the token against the request based on OAuth 2.0.
 * //from   w w  w  .  j  a  v a2  s  .com
 * @param req The request object.
 * @param resp The response object.
 * @exception IOException When the error regarding I/O occurred.
 * @exception ServletException When other error occurred.
 */
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    HttpServletRequestAdapter request = new HttpServletRequestAdapter(req);
    Response response = token.handleRequest(request);
    resp.setStatus(response.getCode());
    resp.setContentType("application/json; charset=UTF-8");
    PrintWriter writer = resp.getWriter();
    IOUtils.write(response.getBody(), writer);
    writer.flush();
}

From source file:com.linuxbox.enkive.message.AbstractMessage.java

@Override
public void pushReconstitutedEmail(Writer output) throws IOException {
    PrintWriter writer = new PrintWriter(output);
    writer.print(getReconstitutedEmail());
    writer.flush();
}

From source file:cz.cas.lib.proarc.common.config.CatalogConfiguration.java

@Override
public String toString() {
    StringWriter dump = new StringWriter();
    PrintWriter printWriter = new PrintWriter(dump);
    ConfigurationUtils.dump(properties, printWriter);
    printWriter.flush();
    return "CatalogConfiguration{id=" + id + ", prefix=" + prefix + ", properties:" + dump + '}';
}

From source file:at.tuwien.ifs.somtoolbox.data.InputDataWriter.java

/** Writes the class information to a file in SOMLib format. */
public static void writeAsSOMLib(SOMLibClassInformation classInfo, String fileName)
        throws IOException, SOMLibFileFormatException {
    PrintWriter writer = FileUtils.openFileForWriting("SOMLib class info", fileName);
    writer.println("$TYPE class_information");
    writer.println("$NUM_CLASSES " + classInfo.numClasses());
    writer.write("$CLASS_NAMES ");
    for (int i = 0; i < classInfo.numClasses(); i++) {
        writer.write(classInfo.getClassName(i));
        if (i + 1 < classInfo.numClasses()) {
            writer.write(" ");
        }//from ww w  .ja v a2s . c om
    }
    writer.println();
    writer.println("$XDIM 2");
    writer.println("$YDIM " + classInfo.numData);
    for (String element : classInfo.getDataNames()) {
        writer.println(element + " " + classInfo.getClassName(element));
    }

    writer.flush();
    writer.close();
}

From source file:com.honnix.yaacs.admin.lifecycle.Lifecycle.java

private void createRunFile() {
    File file = new File(ACPropertiesConstant.RUN_FILE_PATH);

    if (file.exists()) {
        file.delete();//from  w w w . j av a2  s .c o  m

        StringBuilder sb = new StringBuilder("Strange! yaacs.run file exists.")
                .append(" Anyway, we will start YaACs.");

        LOG.warn(sb.toString());
    }
    try {
        PrintWriter pw = new PrintWriter(file);

        pw.println("Delete this file to stop YaACs.");
        pw.flush();
    } catch (FileNotFoundException e) {
        LOG.fatal("Error starting YaACs.", e);

        System.exit(1);
    }
}

From source file:info.bitoo.Daemon.java

public void downloadCompleted(BiToo biToo) {
    logger.debug("download completed event");
    PrintWriter output = (PrintWriter) biToos.remove(biToo);
    if (output != null) {
        output.println("OK");
        output.flush();
        output.close();// w ww. ja  v  a2 s. co  m
    } else {
        logger.warn("No output for BiToo worker: [" + biToo.toString() + "]");
    }
    biToo.destroy();
}

From source file:info.bitoo.Daemon.java

public void downloadFailed(BiToo biToo) {
    logger.debug("download failed event");
    PrintWriter output = (PrintWriter) biToos.remove(biToo);
    if (output != null) {
        output.println("KO");
        output.flush();
        output.close();//from   w w  w .  j av  a2s .  c om
    } else {
        logger.warn("No output for BiToo worker: [" + biToo.toString() + "]");
    }
    biToo.destroy();
}