Example usage for java.io BufferedWriter flush

List of usage examples for java.io BufferedWriter flush

Introduction

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

Prototype

public void flush() throws IOException 

Source Link

Document

Flushes the stream.

Usage

From source file:org.codehaus.groovy.grails.scaffolding.AbstractGrailsTemplateGenerator.java

public void generateController(GrailsControllerType controllerType, GrailsDomainClass domainClass,
        String destDir) throws IOException {
    Assert.hasText(destDir, "Argument [destdir] not specified");

    if (domainClass == null) {
        return;//from  w  w w  .jav  a 2 s .  c o  m
    }

    String fullName = domainClass.getFullName();
    String pkg = "";
    int pos = fullName.lastIndexOf('.');
    if (pos != -1) {
        // Package name with trailing '.'
        pkg = fullName.substring(0, pos + 1);
    }

    File destFile = new File(destDir, "grails-app/controllers/" + pkg.replace('.', '/')
            + domainClass.getShortName() + "Controller.groovy");
    if (canWrite(destFile)) {
        destFile.getParentFile().mkdirs();

        BufferedWriter writer = null;
        try {
            writer = new BufferedWriter(new FileWriter(destFile));
            generateController(controllerType, domainClass, writer);
            try {
                writer.flush();
            } catch (IOException ignored) {
            }
        } finally {
            IOGroovyMethods.closeQuietly(writer);
        }

        log.info("Controller generated at [" + destFile + "]");
    }
}

From source file:ch.vorburger.webdriver.reporting.TestCaseReportWriter.java

private void addPakageNameToJS(String packageName) throws IOException {
    BufferedWriter bw = null;
    try {/*w w w.  j a  v a 2 s. com*/
        bw = new BufferedWriter(new FileWriter(jsFile, true));
        bw.write("packageArray.push(\"" + packageName.toUpperCase() + "\");");
        bw.newLine();
        bw.flush();
    } catch (IOException ioe) {
        // DO Nothing
    } finally { // always close the file
        if (bw != null)
            try {
                bw.close();
            } catch (IOException ioe2) {
                // just ignore it
            }
    } // end try/catch/finally
}

From source file:it.geosolutions.figis.ws.test.CheckChangeUserTest.java

/**
 * Create or modified test file/*w  w w.j a  va  2  s .  com*/
 *
 * @param useracProptestFile
 * @param userRoleAdminPwd
 * @throws IOException
 */
public void modifyUseracTestFile(String useracProptestFile, String userRoleAdminPwd) throws IOException {

    FileWriter fstream = null;
    BufferedWriter out = null;
    try {
        // Create file
        java.net.URL url = this.getClass().getClassLoader().getResource(useracProptestFile);
        fstream = new FileWriter(url.toURI().toURL().getPath());
        out = new BufferedWriter(fstream);
        out.write(TO_TEST_PROPERTIES_FILE + "\n");
        out.write(TO_TEST_PERIOD + "\n");
        out.write(userRoleAdminPwd + "\n");
        out.write(TO_TEST_USERS_ROLE_USER + "\n");
        out.flush();
    } catch (Exception e) // Catch exception if any
    {
        LOGGER.error(e.getLocalizedMessage(), e);
    } finally {
        // Close the output stream
        if (fstream != null) {
            IOUtils.closeQuietly(fstream);
        }
        if (out != null) {
            IOUtils.closeQuietly(out);
        }
    }
}

From source file:dylemator.UserResultList.java

private void removeButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_removeButtonActionPerformed
    int row = this.codeTable.getSelectedRow();
    if (row == -1)
        return;/*from w w  w. ja  v  a2s . c  o m*/
    String[] values = exportData.get(row + 1);
    int dialogResult = JOptionPane.showConfirmDialog(null, "Usun wyniki uytkownika " + values[0] + "?",
            "Warning", JOptionPane.YES_NO_OPTION);
    if (dialogResult == JOptionPane.YES_OPTION) {
        exportData.remove(row + 1);
        DefaultTableModel m = (DefaultTableModel) codeTable.getModel();
        m.setRowCount(0);
        for (int i = 1; i < exportData.size(); i++) {
            m.addRow(new String[] { exportData.get(i)[0] });
        }
        DefaultTableModel n = (DefaultTableModel) infoTable.getModel();
        DefaultTableModel o = (DefaultTableModel) resultsTable.getModel();
        n.setRowCount(0);
        o.setRowCount(0);
        try {
            OutputStreamWriter output = new FileWriter(this.selectedFilename);
            BufferedWriter bufferWriter = new BufferedWriter(output);
            for (String[] v : exportData) {
                String s = StringUtils.join(v, ";");
                bufferWriter.write(s + "\n");
            }
            bufferWriter.flush();
            bufferWriter.close();
        } catch (IOException ex) {
            Logger.getLogger(UserResultList.class.getName()).log(Level.SEVERE, null, ex);
        }

    }

}

From source file:madkitgroupextension.export.Export.java

public void createManifestFile(File f) throws IOException {
    FileWriter fw = new FileWriter(f);
    BufferedWriter b = new BufferedWriter(fw);
    b.write(getManifest());// www  .j a v  a2 s.  co m
    b.flush();
    b.close();
    fw.close();
}

From source file:com.thoughtmetric.tl.TLLib.java

public static Object[] parseEditText(HtmlCleaner cleaner, URL url, TLHandler handler, Context context)
        throws IOException {
    // Although probably not THE worst hack I've written, this function ranks near the top.
    // TODO: rework this routine get rid of code duplication.

    DefaultHttpClient httpclient = new DefaultHttpClient();
    httpclient.setCookieStore(cookieStore);

    HttpGet httpGet = new HttpGet(url.toExternalForm());
    HttpResponse response = httpclient.execute(httpGet);

    handler.sendEmptyMessage(PROGRESS_DOWNLOADING);
    InputStream is = response.getEntity().getContent();

    InputStreamReader isr = new InputStreamReader(is);
    BufferedReader br = new BufferedReader(isr);

    FileOutputStream fos = context.openFileOutput(TEMP_FILE_NAME, Context.MODE_PRIVATE);
    BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(fos));

    String line;//from   w ww .j  a  va  2 s .c  o m
    String formStart = "<form action=\"/forum/edit.php";
    while ((line = br.readLine()) != null) {
        if (line.startsWith(formStart)) {
            Log.d(TAG, line);
            bw.write(line);
            break;
        }
    }

    String start = "\t\t<textarea";
    String end = "\t\t<p>";
    StringBuffer sb = new StringBuffer();
    while ((line = br.readLine()) != null) {
        if (line.startsWith(start)) {
            bw.write("</form>");
            int i = line.lastIndexOf('>');
            sb.append(Html.fromHtml(line.substring(i + 1)).toString());
            sb.append("\n");
            break;
        } else {
            bw.write(line);
        }
    }

    while ((line = br.readLine()) != null) {
        if (line.startsWith(end)) {
            break;
        }
        sb.append(Html.fromHtml(line).toString());
        sb.append("\n");
    }

    bw.flush();
    bw.close();

    if (handler != null)
        handler.sendEmptyMessage(PROGRESS_PARSING);

    Object[] ret = new Object[2];

    ret[0] = sb.toString();
    ret[1] = cleaner.clean(context.openFileInput(TEMP_FILE_NAME));
    return ret;
}

From source file:com.pieframework.runtime.utils.azure.CsdefGenerator.java

public File generate(SubSystem c, Request r, Operation o, String csdefFilename) {

    File configFile = new File(csdefFilename);
    if (!configFile.getParentFile().exists()) {
        try {/* w  w  w  . ja v  a2  s .c o  m*/
            if (configFile.getParentFile().mkdirs()) {

            } else {
                Configuration.log().error("Failed creating directory for:" + configFile.getPath());
            }

        } catch (Exception e) {
            Configuration.log().error("Failed creating directory for:" + configFile.getPath(), e);
        }
    }

    try {
        BufferedWriter out = new BufferedWriter(
                new OutputStreamWriter(new FileOutputStream(configFile), "UTF8"));
        printHeader(out, r, c);
        printBody(out, o, c);
        printFooter(out);
        out.flush();
        out.close();

    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }

    return configFile;
}

From source file:json_csv.JSON2CSV.java

public void printCuisineLookupTable(Recipes recipes) {
    Recipes newRecipes = recipes;/*from  ww  w  . j  a  v  a 2  s .c  o  m*/
    List<String> printLookupTable = newRecipes.getCuisineMap();
    BufferedWriter ctw = null;

    try {

        StringBuffer oneLine = new StringBuffer();
        ctw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream("cuisine.csv"), "UTF-8"));

        //iterates through the map and print
        for (String cuisine : printLookupTable) {

            ctw.write(cuisine);
            ctw.newLine();
        }

        ctw.flush();
        ctw.close();
    } catch (UnsupportedEncodingException e) {
    } catch (FileNotFoundException e) {
    } catch (IOException e) {
    }
}

From source file:net.sourceforge.eclipsetrader.core.CurrencyConverter.java

private void save() {
    try {// ww w .  j a  v a 2s  .  co  m
        DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
        Document document = builder.getDOMImplementation().createDocument(null, "data", null); //$NON-NLS-1$

        Element root = document.getDocumentElement();

        for (Iterator iter = currencies.iterator(); iter.hasNext();) {
            Element node = document.createElement("currency"); //$NON-NLS-1$
            node.appendChild(document.createTextNode((String) iter.next()));
            root.appendChild(node);
        }

        for (Iterator iter = map.keySet().iterator(); iter.hasNext();) {
            String symbol = (String) iter.next();
            Element node = document.createElement("conversion"); //$NON-NLS-1$
            node.setAttribute("symbol", symbol); //$NON-NLS-1$
            node.setAttribute("ratio", String.valueOf(map.get(symbol))); //$NON-NLS-1$
            saveHistory(node, symbol);
            root.appendChild(node);
        }

        TransformerFactory factory = TransformerFactory.newInstance();
        try {
            factory.setAttribute("indent-number", new Integer(4)); //$NON-NLS-1$
        } catch (Exception e) {
        }
        Transformer transformer = factory.newTransformer();
        transformer.setOutputProperty(OutputKeys.METHOD, "xml"); //$NON-NLS-1$
        transformer.setOutputProperty(OutputKeys.ENCODING, "ISO-8859-1"); //$NON-NLS-1$
        transformer.setOutputProperty(OutputKeys.INDENT, "yes"); //$NON-NLS-1$
        transformer.setOutputProperty("{http\u003a//xml.apache.org/xslt}indent-amount", "4"); //$NON-NLS-1$ //$NON-NLS-2$
        DOMSource source = new DOMSource(document);

        File file = new File(Platform.getLocation().toFile(), "currencies.xml"); //$NON-NLS-1$

        BufferedWriter out = new BufferedWriter(new FileWriter(file));
        StreamResult result = new StreamResult(out);
        transformer.transform(source, result);
        out.flush();
        out.close();
    } catch (Exception e) {
        logger.error(e, e);
    }
}

From source file:madkitgroupextension.export.Export.java

public void createVersionFile(File f) throws IOException {
    FileWriter fw = new FileWriter(f);
    BufferedWriter b = new BufferedWriter(fw);
    b.write(MadKitGroupExtension.VERSION.getHTMLCode());
    b.flush();
    b.close();//ww w.j a  v  a 2 s. c  o  m
    fw.close();
}