Example usage for java.io BufferedWriter toString

List of usage examples for java.io BufferedWriter toString

Introduction

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

Prototype

public String toString() 

Source Link

Document

Returns a string representation of the object.

Usage

From source file:com.evidon.areweprivateyet.Crawler.java

private void recordLog(String name) throws IOException {
    BufferedWriter out = new BufferedWriter(new FileWriter(path + "crawl-" + name + ".log"));
    out.write(out.toString());
    out.close();/*  w ww .  j a  va 2  s.c o  m*/
}

From source file:cn.org.once.cstack.service.impl.ScriptingServiceImpl.java

public void execute(String scriptContent, String login, String password) throws ServiceException {
    logger.info(scriptContent);/*from   w w  w. j  a v  a 2s.com*/

    File tmpFile = null;
    FileWriter fileWriter = null;
    BufferedWriter writer = null;
    ProcessBuilder processBuilder = null;
    try {
        tmpFile = File.createTempFile(login, ".cmdFile");
        fileWriter = new FileWriter(tmpFile);
        writer = new BufferedWriter(fileWriter);
        String commandConnect = CONNECT_CMD.replace("#USER", login).replace("#PASSWORD", password)
                .replace("#HOST", host);
        logger.debug(commandConnect);
        writer.append(commandConnect);
        writer.newLine();
        writer.append(scriptContent);
        writer.newLine();
        writer.append(DISCONNECT_CMD);
        writer.flush();
        logger.debug(writer.toString());

        File fileCLI = new File(pathCLI);
        if (!fileCLI.exists()) {
            System.out.println("Error ! ");
            StringBuilder msgError = new StringBuilder(512);
            msgError.append(
                    "\nPlease run manually (1) : mkdir -p " + pathCLI.substring(0, pathCLI.lastIndexOf("/")));
            msgError.append(
                    "\nPlease run manually (2) : wget https://github.com/Treeptik/cloudunit/releases/download/1.0/CloudUnitCLI.jar -O "
                            + pathCLI);
            throw new ServiceException(msgError.toString());
        }

        processBuilder = new ProcessBuilder("java", "-jar", pathCLI, "--cmdfile", tmpFile.getAbsolutePath());
        processBuilder.redirectErrorStream(true);
        Process process = processBuilder.start();

        BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
        String line = "";
        try {
            while ((line = reader.readLine()) != null) {
                logger.info(line);
                if (line.contains("not found"))
                    throw new ServiceException("Syntax error : " + line);
                if (line.contains("Invalid or corrupt jarfile"))
                    throw new ServiceException("Invalid or corrupt jarfile");
            }
        } finally {
            reader.close();
        }

    } catch (IOException e) {
        StringBuilder msgError = new StringBuilder(512);
        msgError.append("login=").append(login);
        msgError.append(", password=").append(password);
        msgError.append(", scriptContent=").append(scriptContent);
        logger.error(msgError.toString(), e);
    } finally {
        try {
            fileWriter.close();
        } catch (Exception ignore) {
        }
        try {
            writer.close();
        } catch (Exception ignore) {
        }
    }
}

From source file:org.talend.core.model.utils.ContextOrderProperties.java

public void orderStore(Writer writer, String comments, boolean escUnicode) throws IOException {
    BufferedWriter bufferedWriter = (writer instanceof BufferedWriter) ? (BufferedWriter) writer
            : new BufferedWriter(writer);
    if (comments != null) {
        writeComments(bufferedWriter, comments);
    }//ww w. ja v  a  2s .  com
    bufferedWriter.write("#" + new Date().toString());
    bufferedWriter.newLine();

    synchronized (this) {
        Iterator<String> iterator = this.commentMap.keySet().iterator();
        while (iterator.hasNext()) {
            String key = iterator.next();
            String value = this.getProperty(key);
            String comment = this.commentMap.get(key);
            key = saveConvert(key, true, escUnicode);
            value = saveConvert(value, false, escUnicode);
            if (comment != null && !comment.equals("")) {
                bufferedWriter.newLine();
                writeComments(bufferedWriter, comment);
            }
            bufferedWriter.write(key + "=" + value);
            bufferedWriter.newLine();
        }
    }
    bufferedWriter.toString();
    bufferedWriter.flush();
}