Example usage for java.io Writer flush

List of usage examples for java.io Writer flush

Introduction

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

Prototype

public abstract void flush() throws IOException;

Source Link

Document

Flushes the stream.

Usage

From source file:net.lightbody.bmp.proxy.jetty.html.Element.java

/** Write Element to an OutputStream.
 * Calls print(Writer) and checks errors
 * Elements that override this method should also override
 * write(Writer) to avoid infinite recursion.
 * @param out OutputStream to write the element to.
 *//*  www . j  a  v a2 s .  co m*/
public void write(OutputStream out) throws IOException {
    Writer writer = new OutputStreamWriter(out);
    write(writer);
    writer.flush();
}

From source file:com.netxforge.oss2.config.ThresholdingConfigFactory.java

/**
 * Saves the current in-memory configuration to disk and reloads
 *
 * @throws org.exolab.castor.xml.MarshalException if any.
 * @throws java.io.IOException if any./*  ww w .  java  2s.  c  om*/
 * @throws org.exolab.castor.xml.ValidationException if any.
 */
public synchronized void saveCurrent() throws MarshalException, IOException, ValidationException {
    // Marshal to a string first, then write the string to the file. This
    // way the original config
    // isn't lost if the XML from the marshal is hosed.
    StringWriter stringWriter = new StringWriter();
    Marshaller.marshal(m_config, stringWriter);

    String xmlString = stringWriter.toString();
    if (xmlString != null) {
        File cfgFile = ConfigFileConstants.getFile(ConfigFileConstants.THRESHOLDING_CONF_FILE_NAME);

        Writer fileWriter = new OutputStreamWriter(new FileOutputStream(cfgFile), "UTF-8");
        fileWriter.write(xmlString);
        fileWriter.flush();
        fileWriter.close();
    }

    update();

}

From source file:net.lightbody.bmp.proxy.jetty.servlet.AdminServlet.java

public void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    if (request.getQueryString() != null && request.getQueryString().length() > 0) {
        String target = doAction(request);
        response.sendRedirect(request.getContextPath() + request.getServletPath()
                + (request.getPathInfo() != null ? request.getPathInfo() : "")
                + (target != null ? ("#" + target) : ""));
        return;/*  w  w  w  .  ja  va2 s  . co  m*/
    }

    Page page = new Page();
    page.title(getServletInfo());
    page.addHeader("");
    page.attribute("text", "#000000");
    page.attribute(Page.BGCOLOR, "#FFFFFF");
    page.attribute("link", "#606CC0");
    page.attribute("vlink", "#606CC0");
    page.attribute("alink", "#606CC0");

    page.add(new Block(Block.Bold).add(new Font(3, true).add(getServletInfo())));
    page.add(Break.rule);
    Form form = new Form(request.getContextPath() + request.getServletPath() + "?A=exit");
    form.method("GET");
    form.add(new Input(Input.Submit, "A", "Exit All Servers"));
    page.add(form);
    page.add(Break.rule);
    page.add(new Heading(3, "Components:"));

    List sList = new List(List.Ordered);
    page.add(sList);

    String id1;
    int i1 = 0;
    Iterator s = _servers.iterator();
    while (s.hasNext()) {
        id1 = "" + i1++;
        HttpServer server = (HttpServer) s.next();
        Composite sItem = sList.newItem();
        sItem.add("<B>HttpServer&nbsp;");
        sItem.add(lifeCycle(request, id1, server));
        sItem.add("</B>");
        sItem.add(Break.line);
        sItem.add("<B>Listeners:</B>");
        List lList = new List(List.Unordered);
        sItem.add(lList);

        HttpListener[] listeners = server.getListeners();
        for (int i2 = 0; i2 < listeners.length; i2++) {
            HttpListener listener = listeners[i2];
            String id2 = id1 + ":" + listener;
            lList.add(lifeCycle(request, id2, listener));
        }

        Map hostMap = server.getHostMap();

        sItem.add("<B>Contexts:</B>");
        List hcList = new List(List.Unordered);
        sItem.add(hcList);
        Iterator i2 = hostMap.entrySet().iterator();
        while (i2.hasNext()) {
            Map.Entry hEntry = (Map.Entry) (i2.next());
            String host = (String) hEntry.getKey();

            PathMap contexts = (PathMap) hEntry.getValue();
            Iterator i3 = contexts.entrySet().iterator();
            while (i3.hasNext()) {
                Map.Entry cEntry = (Map.Entry) (i3.next());
                String contextPath = (String) cEntry.getKey();
                java.util.List contextList = (java.util.List) cEntry.getValue();

                Composite hcItem = hcList.newItem();
                if (host != null)
                    hcItem.add("Host=" + host + ":");
                hcItem.add("ContextPath=" + contextPath);

                String id3 = id1 + ":" + host + ":"
                        + (contextPath.length() > 2 ? contextPath.substring(0, contextPath.length() - 2)
                                : contextPath);

                List cList = new List(List.Ordered);
                hcItem.add(cList);
                for (int i4 = 0; i4 < contextList.size(); i4++) {
                    String id4 = id3 + ":" + i4;
                    Composite cItem = cList.newItem();
                    HttpContext hc = (HttpContext) contextList.get(i4);
                    cItem.add(lifeCycle(request, id4, hc));
                    cItem.add("<BR>ResourceBase=" + hc.getResourceBase());
                    cItem.add("<BR>ClassPath=" + hc.getClassPath());

                    List hList = new List(List.Ordered);
                    cItem.add(hList);
                    int handlers = hc.getHandlers().length;
                    for (int i5 = 0; i5 < handlers; i5++) {
                        String id5 = id4 + ":" + i5;
                        HttpHandler handler = hc.getHandlers()[i5];
                        Composite hItem = hList.newItem();
                        hItem.add(lifeCycle(request, id5, handler, handler.getName()));
                        if (handler instanceof ServletHandler) {
                            hItem.add("<BR>" + ((ServletHandler) handler).getServletMap());
                        }
                    }
                }
            }
        }
        sItem.add("<P>");
    }

    response.setContentType("text/html");
    response.setHeader("Pragma", "no-cache");
    response.setHeader("Cache-Control", "no-cache,no-store");
    Writer writer = response.getWriter();
    page.write(writer);
    writer.flush();
}

From source file:com.sun.faban.harness.webclient.Uploader.java

/**
 * Updates the run description.// w ww .  j ava2s .  c  o m
 * @param req
 * @param resp
 * @throws java.io.IOException
 */
public void updateRunDesc(HttpServletRequest req, HttpServletResponse resp) throws IOException {
    String runId = req.getParameter("runId");
    RunResult result = RunResult.getInstance(new RunId(runId));
    result.description = req.getParameter("desc");
    ResultAction.editXML(result);
    Writer w = resp.getWriter();
    w.write("Tags updating completed");
    w.flush();
    w.close();
}

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

@Override
public void pushReconstitutedEmail(Writer output) throws IOException {
    try {/*from   w  ww .ja  v a2 s  .  co  m*/
        output.write(getOriginalHeaders());
        output.write(getLineEnding());
        IOUtils.copy(getEncodedContentData().getEncodedContent(), output);
        output.write(getLineEnding());
    } catch (ContentException e) {
        throw new IOException(e);
    } finally {
        output.flush();
    }
}

From source file:com.odiago.maven.plugins.soy.CompileMojo.java

/** {@inheritDoc} */
@Override/*from   w  w  w  .  ja  va 2 s.c om*/
public void execute() throws MojoExecutionException {
    getLog().info("Compiling soy templates...");

    SoyFileSet soyFileSet = getInputFileSet();
    SoyJsSrcOptions jsSrcOptions = new SoyJsSrcOptions();
    jsSrcOptions.setShouldProvideRequireSoyNamespaces(mShouldProvideRequireSoyNamespaces);
    jsSrcOptions.setShouldGenerateJsdoc(mShouldGenerateJsdoc);
    List<String> compiledSrcs = soyFileSet.compileToJsSrc(jsSrcOptions, null);

    FileSetManager fileSetManager = new FileSetManager(getLog());
    String[] inputFilenames = fileSetManager.getIncludedFiles(mInputFiles);
    assert inputFilenames.length == compiledSrcs.size();
    if (mOutputDirectory.mkdirs()) {
        getLog().info("Created output directory: " + mOutputDirectory);
    }
    for (int i = 0; i < inputFilenames.length; i++) {
        File outputFile = new File(mOutputDirectory, inputFilenames[i] + ".js");
        getLog().info("Writing compiled soy: " + outputFile);
        Writer writer = null;
        try {
            if (outputFile.createNewFile()) {
                getLog().info("Created new file: " + outputFile);
            }
            writer = new FileWriter(outputFile);
            writer.write(compiledSrcs.get(i));
            writer.flush();
        } catch (IOException e) {
            IOUtils.closeQuietly(writer);
        }
    }
}

From source file:filesscanner.MainWindow.java

private void saveToJSONBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_saveToJSONBtnActionPerformed

    JSONObject object = new JSONObject();

    for (int i = 0; i < modelFiles.getSize(); i++) {

        object.put("filename" + i, modelFiles.get(i).toString());

    }/* www  .  j a  v  a2 s.  c o m*/

    File file = new File("C:");
    JFileChooser chooser = ShowChooser(file);
    chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
    chooser.setDialogType(JFileChooser.SAVE_DIALOG);
    int res = chooser.showDialog(this, "  ? ??!!!");
    if (res == JFileChooser.APPROVE_OPTION) {

        try {
            Writer writer = new FileWriter(chooser.getSelectedFile());
            object.writeJSONString(writer);
            JOptionPane.showMessageDialog(rootPane, "SAVED SUCCESFULLY!!!");
            writer.flush();
            writer.close();
        } catch (IOException ex) {
            Logger.getLogger(MainWindow.class.getName()).log(Level.SEVERE, null, ex);
            JOptionPane.showMessageDialog(rootPane, "Something bad!!!");
        }

    }

}

From source file:azkaban.webapp.servlet.LoginAbstractAzkabanServlet.java

protected void writeResponse(HttpServletResponse resp, String response) throws IOException {
    Writer writer = resp.getWriter();
    writer.append(response);// ww w.j  a  va 2 s.c o  m
    writer.flush();
}

From source file:net.lightbody.bmp.proxy.jetty.html.Element.java

/** Write Element to an OutputStream.
 * Calls print(Writer) and checks errors
 * Elements that override this method should also override
 * write(Writer) to avoid infinite recursion.
 * @param out OutputStream to write the element to.
 *//*from   w ww  .j  a  v  a 2s .com*/
public void write(OutputStream out, String encoding) throws IOException {
    Writer writer = new OutputStreamWriter(out, encoding);
    write(writer);
    writer.flush();
}

From source file:no.uis.service.studinfo.commons.StudinfoValidator.java

protected List<String> validate(String studieinfoXml, StudinfoType infoType, int year, FsSemester semester,
        String language) throws Exception {

    // save xml/*from  w  ww.ja  v a  2  s . c o m*/
    File outFile = new File("target/out", infoType.toString() + year + semester + language + ".xml");
    if (outFile.exists()) {
        outFile.delete();
    } else {
        outFile.getParentFile().mkdirs();
    }
    File outBackup = new File("target/out", infoType.toString() + year + semester + language + "_orig.xml");
    Writer backupWriter = new OutputStreamWriter(new FileOutputStream(outBackup), IOUtils.UTF8_CHARSET);
    backupWriter.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
    IOUtils.copy(new StringReader(studieinfoXml), backupWriter, IOBUFFER_SIZE);
    backupWriter.flush();
    backupWriter.close();

    TransformerFactory trFactory = TransformerFactory.newInstance();
    Source schemaSource = new StreamSource(getClass().getResourceAsStream("/fspreprocess.xsl"));
    Transformer stylesheet = trFactory.newTransformer(schemaSource);

    Source input = new StreamSource(new StringReader(studieinfoXml));

    Result result = new StreamResult(outFile);
    stylesheet.transform(input, result);

    SAXParserFactory factory = SAXParserFactory.newInstance();
    factory.setValidating(false);
    factory.setNamespaceAware(true);

    SchemaFactory schemaFactory = SchemaFactory.newInstance("http://www.w3.org/2001/XMLSchema");
    Schema schema = schemaFactory
            .newSchema(new Source[] { new StreamSource(new File("src/main/xsd/studinfo.xsd")) });

    factory.setSchema(schema);

    SAXParser parser = factory.newSAXParser();

    XMLReader reader = parser.getXMLReader();
    ValidationErrorHandler errorHandler = new ValidationErrorHandler(infoType, year, semester, language);
    reader.setErrorHandler(errorHandler);
    reader.setContentHandler(errorHandler);
    try {
        reader.parse(
                new InputSource(new InputStreamReader(new FileInputStream(outFile), IOUtils.UTF8_CHARSET)));
    } catch (SAXException ex) {
        // do nothing. The error is handled in the error handler
    }
    return errorHandler.getMessages();
}