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:com.joliciel.frenchTreebank.export.FrenchTreebankXmlWriter.java

public void write(File outDir) throws TemplateException, IOException {
    List<TreebankFile> treebankFiles = treebankService.findTreebankFiles();
    for (TreebankFile treebankFile : treebankFiles) {
        String ftbFileName = treebankFile.getFileName();
        String fileName = ftbFileName.substring(ftbFileName.lastIndexOf('/') + 1);
        File xmlFile = new File(outDir, fileName);
        xmlFile.delete();/* ww  w.jav a 2  s  .c o m*/
        xmlFile.createNewFile();

        Writer xmlFileWriter = new BufferedWriter(
                new OutputStreamWriter(new FileOutputStream(xmlFile, false), "UTF8"));
        this.write(xmlFileWriter, treebankFile);
        xmlFileWriter.flush();
        xmlFileWriter.close();
    }
}

From source file:gumga.framework.application.template.GumgaFreemarkerTemplateEngineTest.java

@Test
public void testParseToFile() throws Exception {
    Map<String, Object> values = new HashMap<>();
    String name = "Lara Croft";
    values.put("name", name);
    values.put("age", new Integer(35));
    File file = new File(OUTPUT_FOLDER + "/testResult.txt");
    FileOutputStream fos = new FileOutputStream(file);
    Writer writer = new OutputStreamWriter(fos);
    try {/*from www .j  a  v a 2  s. c  o m*/
        gumgaFreemarkerTemplateEngineService.parse(values, "testTemplate.ftl", writer);
    } finally {
        fos.close();
        writer.flush();
        writer.close();
    }
    assertTrue(file.exists());
}

From source file:juserdefaults.JUserDefaults.java

/**
  * Makes changes persistent by writing them to a file.
  *//*from www . j  a  va2 s  .  c  om*/
public void synchronize() {
    try {
        if (this.storageObject != null) {
            File f = new File(storageFileName);
            FileWriter fstream = new FileWriter(f);
            BufferedWriter fout = new BufferedWriter(fstream);
            Writer writer = this.storageObject.write(fout);
            writer.flush();
            fout.close();
        }
    } catch (IOException e) {
        System.err.print(e.getMessage());
    }
}

From source file:io.lightlink.excel.StreamingExcelTransformer.java

private void processSheet(byte[] bytes, OutputStream out, ExcelStreamVisitor visitor)
        throws ParserConfigurationException, SAXException, IOException {

    SAXParserFactory factory = SAXParserFactory.newInstance();
    SAXParser saxParser = factory.newSAXParser();
    Writer printWriter = new OutputStreamWriter(out, "UTF-8");

    saxParser.parse(new ByteArrayInputStream(bytes),
            new SheetTemplateHandler(printWriter, sharedStrings, visitor));

    printWriter.flush();

}

From source file:com.tinspx.util.json.JSONParserTest.java

static void writeIndentingOut(Object value) throws IOException {
    Writer w = new OutputStreamWriter(System.out);
    IndentingWriter.create().writeTo(w, value);
    w.flush();
    w.close();/*from  ww w . j  a  v a2 s. c om*/
    System.out.println();
}

From source file:net.cit.tetrad.resource.LoginResource.java

@RequestMapping(value = "/registLicensekey.do")
public void registLicensekey(HttpServletRequest request, HttpServletResponse response) {
    String licensekey = request.getParameter("licensekey");
    int resultCode = ColumnConstent.REGIST_FAIL_INVALID;
    try {/*w  w w .j a  v  a  2 s.  c om*/
        String useros = System.getProperty("os.name");
        String userencoding = System.getProperty("file.encoding");
        String userlanguage = System.getProperty("user.language");

        JSONObject jsonObj = new JSONObject();
        jsonObj.put("version", PropertiesNames.RELEASEVERSIONINFO);
        jsonObj.put("useros", useros);
        jsonObj.put("userencoding", userencoding);
        jsonObj.put("userlanguage", userlanguage);
        jsonObj.put("licensekey", licensekey);

        try {
            if (DistrCommunication.isCommercial("mongobird", jsonObj)) {
                resultCode = licenseManager.registLicensekey(licensekey);
                if (resultCode == ColumnConstent.REGIST_SUCCESS) {
                    Config.LICENSETYPE = licenseManager.getLicenseType(licensekey);
                    Config.LICENSEKEY = licenseManager.convertLicensekey(licensekey);
                }
            }
        } catch (DistrCommunicationException.CannotConnectServer e) {
            resultCode = ColumnConstent.REGIST_FAIL_CANNOTCONNECT;
        }
        response.setCharacterEncoding("UTF-8");
        response.setContentType("application/json");
        response.setHeader("Cache-Control", "no-cache");
        Writer writer = response.getWriter();
        writer.write(Integer.toString(resultCode));
        writer.flush();
    } catch (IOException e) {
        e.printStackTrace();
        log.error(e, e);
    }
}

From source file:au.org.ala.biocache.dao.TaxonDAOImpl.java

void outputNestedLayerStart(String layerName, Writer out) throws Exception {
    out.write("<Layer><Name>" + layerName + "</Name><Title>" + layerName + "</Title>\n\t");
    out.flush();
}

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

/** {@inheritDoc} */
protected void saveXml(String data) throws IOException {
    if (data != null) {
        Writer fileWriter = new OutputStreamWriter(new FileOutputStream(m_groupsConfFile), "UTF-8");
        fileWriter.write(data);/*from  w w w.  ja v a 2s  . c  o  m*/
        fileWriter.flush();
        fileWriter.close();
    }
}

From source file:cz.lbenda.dataman.db.ExportTableData.java

/** Write rows to CSV file
 * @param sqlQueryRows rows/* w  w  w. j  a  v a2 s  . c  o m*/
 * @param writer writer where are data write */
public static void writeSqlQueryRowsToTXT(SQLQueryRows sqlQueryRows, Writer writer) throws IOException {
    String joined = sqlQueryRows.getMetaData().getColumns().stream()
            .map(cd -> fixedString(cd.getName(), cd.getSize())).collect(Collectors.joining(""));
    writer.append(joined).append(Constants.CSV_NEW_LINE_SEPARATOR);
    for (RowDesc row : sqlQueryRows.getRows()) {
        joined = sqlQueryRows.getMetaData().getColumns().stream()
                .map(cd -> fixedString(row.getColumnValueStr(cd), cd.getSize()))
                .collect(Collectors.joining(""));
        writer.append(joined).append(Constants.CSV_NEW_LINE_SEPARATOR);
        writer.flush();
    }
}

From source file:com.amazon.sqs.javamessaging.AmazonSQSExtendedClient.java

private static long getStringSizeInBytes(String str) {
    CountingOutputStream counterOutputStream = new CountingOutputStream();
    try {/* w  ww  .j a va2 s  .c o m*/
        Writer writer = new OutputStreamWriter(counterOutputStream, "UTF-8");
        writer.write(str);
        writer.flush();
        writer.close();
    } catch (IOException e) {
        String errorMessage = "Failed to calculate the size of message payload.";
        LOG.error(errorMessage, e);
        throw new AmazonClientException(errorMessage, e);
    }
    return counterOutputStream.getTotalSize();
}