Example usage for java.io BufferedWriter write

List of usage examples for java.io BufferedWriter write

Introduction

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

Prototype

public void write(int c) throws IOException 

Source Link

Document

Writes a single character.

Usage

From source file:dao.EntryDaoTest.java

@BeforeClass
public static void setUpClass() {
    String fSeparator = File.separator;
    try {//from  w  w w . java 2s.co  m
        File folder = new File(
                System.getProperty("user.dir") + fSeparator + "MyDiaryBook" + fSeparator + "Users" + fSeparator
                        + "Panagiwtis Georgiadis" + fSeparator + "Entries" + fSeparator + "Texnologia2");
        folder.mkdirs();

        File textFolder = new File(folder.toString() + fSeparator + "Texts");
        textFolder.mkdirs();
        File textFile = new File(textFolder.toString() + fSeparator + "test.txt");
        BufferedWriter bw;
        FileWriter fw;
        fw = new FileWriter(textFile, true);
        bw = new BufferedWriter(fw);
        bw.write("test0123456789");
        if (bw != null)
            bw.close();
        fw.close();
        File imageFolder = new File(folder.toString() + fSeparator + "Images");
        imageFolder.mkdirs();
        String imageSourcePath = System.getProperty("user.dir") + fSeparator + "src" + fSeparator + "test"
                + fSeparator + "java" + fSeparator + "resources" + fSeparator + "testImg.jpg";
        File imageSourceFile = new File(imageSourcePath);
        FileUtils.copyFileToDirectory(imageSourceFile, imageFolder);

        String videoSourcePath = System.getProperty("user.dir") + fSeparator + "src" + fSeparator + "test"
                + fSeparator + "java" + fSeparator + "resources" + fSeparator + "testVideo.mp4";
        File videoSourceFile = new File(videoSourcePath);
        File videoFolder = new File(folder.toString() + fSeparator + "Videos");
        videoFolder.mkdirs();
        FileUtils.copyFileToDirectory(videoSourceFile, videoFolder);
    } catch (IOException ex) {
        Logger.getLogger(EntryDaoTest.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:com.adito.activedirectory.ActiveDirectoryPropertyManager.java

private static void writeFile(File file, String contents) throws IOException {
    BufferedWriter output = null;
    try {/*from  w w w .j  av a  2  s. c o  m*/
        output = new BufferedWriter(new FileWriter(file));
        output.write(contents);
    } finally {
        close(output);
    }
}

From source file:localization.split.java

public static boolean checkLPU(String filepath, String passoloPath) {
    File logfile = new File(filepath.substring(0, filepath.lastIndexOf("\\") + 1) + "error.log");
    try {//from ww w. ja  va2  s  . c  om
        String cmd = "cmd.exe /c " + passoloPath + " /openproject:" + filepath;
        Runtime rt = Runtime.getRuntime();
        Process proc = rt.exec(cmd);
        InputStreamReader isr = new InputStreamReader(proc.getInputStream());
        BufferedReader br = new BufferedReader(isr);
        String line = null;
        while ((line = br.readLine()) != null) {
            if (line.contains("Opening in read-only mode")) {
                if (!logfile.exists()) {
                    logfile.createNewFile();
                }
                String content = filepath
                        + " is not able to process because it is a type of Passolo 2011. Please process it with Passolo 2011."
                        + "\n";
                FileWriter fw = new FileWriter(logfile.getAbsoluteFile());
                BufferedWriter bw = new BufferedWriter(fw);
                bw.write(content);
                bw.close();
                return false;
            }
        }
        int exitVal = proc.waitFor();
        if (exitVal == 10) {
            if (!logfile.exists()) {
                logfile.createNewFile();
            }
            String content = filepath
                    + " is not able to process because it is a type of Passolo 2011. Please process it with Passolo 2015."
                    + "\n";
            FileWriter fw = new FileWriter(logfile.getAbsoluteFile());
            BufferedWriter bw = new BufferedWriter(fw);
            bw.write(content);
            bw.close();
            return false;
        }

    } catch (Exception e) {
        try {
            String content = e.getMessage();
            FileWriter fw = new FileWriter(logfile.getAbsoluteFile());
            BufferedWriter bw = new BufferedWriter(fw);
            bw.write(content);
            bw.close();
        } catch (Exception e1) {

        }

        return false;
    }
    return true;
}

From source file:es.sotileza.plugin.utils.Utilidades.java

public static void paintMaestroManager(String file, List<String> tr1, List<String> tr2, List<String> tr3,
        ArquetipoVO arq) throws IOException {
    FileWriter output = new FileWriter(file);
    BufferedWriter writer = new BufferedWriter(output);

    writer.write("package " + arq.getPakete() + ".business.manager;\n\r");

    writer.write("import " + arq.getPakete() + ".business.vo.*;");
    writer.write("import " + arq.getPakete() + ".business.dao.*;");
    writer.write("import java.util.List;");
    writer.write("import org.apache.commons.logging.Log;");
    writer.write("import org.apache.commons.logging.LogFactory;");
    writer.write("\n\r");

    writer.write("/**\n * Clase Manager - Maestros\n */");
    writer.write("public class MaestrosManager {\n\r");

    writer.write("\tprivate static Log log = LogFactory.getFactory().getInstance(MaestrosManager.class);");

    for (String i : tr1)
        writer.write(i + "\n");
    for (String i : tr2)
        writer.write(i + "\n");
    for (String i : tr3)
        writer.write(i + "\n");
    writer.write("}");
    System.out.println("Generado el fichero: " + file);
    writer.flush();/*from ww  w  . j  a  v a2  s  .  co  m*/
}

From source file:com.jbirdvegas.mgerrit.helpers.GerritTeamsHelper.java

private static void writeTeamToCache(String teamName, String teamUrl) {
    File teamPath = new File(mExternalCacheDir.getAbsolutePath() + '/' + teamName);
    if (teamPath.exists()) {
        teamPath.delete();/*from   w  w  w.  j  a va  2  s.c o  m*/
    }
    BufferedWriter writer = null;
    try {
        writer = new BufferedWriter(new FileWriter(teamPath));
        try {
            writer.write(new JSONObject().put(KEY_TEAM_NAME, teamName).put(KEY_TEAM_URL, teamUrl)
                    .put(KEY_TIMESTAMP, System.currentTimeMillis()).toString());
        } catch (JSONException e) {
            Log.e(TAG, "Failed to encode gerrit info to json", e);
        }
    } catch (IOException e) {
        Log.e(TAG, "Failed to write file to the cache", e);
    } finally {
        if (writer != null) {
            try {
                writer.close();
            } catch (IOException e) {
                // let it go
            }
        }
    }
}

From source file:es.sotileza.plugin.utils.Utilidades.java

public static void paintMaestroDelegate(String file, List<String> tr1, ArquetipoVO arq) throws IOException {
    FileWriter output = new FileWriter(file);
    BufferedWriter writer = new BufferedWriter(output);

    writer.write("package " + arq.getPakete() + ".web.delegate;\n\r");

    writer.write("import " + arq.getPakete() + ".business.vo.*;");
    writer.write("import " + arq.getPakete() + ".business.manager.*;");
    writer.write("import java.util.List;");
    writer.write("import org.apache.commons.logging.Log;");
    writer.write("import org.apache.commons.logging.LogFactory;");
    writer.write("\n\r");

    writer.write("/**\n * Clase Delegate - Maestros\n */");
    writer.write("public class MaestrosDelegate {\n\r");

    writer.write("\tprivate static Log log = LogFactory.getFactory().getInstance(MaestrosDelegate.class);");
    writer.write("\n\tprivate MaestrosManager maestrosManager;\n");
    writer.write("\n\tpublic MaestrosManager getMaestrosManager(){");
    writer.write("\n\t\treturn this.maestrosManager;");
    writer.write("\n\t}");
    writer.write("\n\tpublic void setMaestrosManager( MaestrosManager maestrosManager ){");
    writer.write("\n\t\tthis.maestrosManager = maestrosManager;");
    writer.write("\n\t}\n\r");

    for (String i : tr1)
        writer.write(i + "\n");
    writer.write("}");
    System.out.println("Generado el fichero: " + file);
    writer.flush();//from   ww w.ja va  2 s . c o  m
}

From source file:es.chatclient.styles.CssGenerator.java

private static File createCssFile(File f, String generatedText) {

    BufferedWriter writer = null;
    File outputFile = null;//from   www .ja v  a  2s . c o m

    try {

        outputFile = new File(DIR_GENERATED_CSS + f.getName());
        writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(outputFile), "utf-8"));
        writer.write(generatedText);

    } catch (IOException ex) {
        System.err.println("Error generando css file:" + f.getName());

    } finally {

        if (writer != null) {
            try {
                writer.close();
            } catch (IOException ex) {
                Logger.getLogger(CssGenerator.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }

    return outputFile;
}

From source file:com.zimbra.cs.session.WaitSetValidator.java

private static void printError(String text) {
    PrintStream ps = System.err;
    try {//  www .j  a va 2 s  .  co  m
        BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(ps, "UTF-8"));
        writer.write(text + "\n");
        writer.flush();
    } catch (UnsupportedEncodingException e) {
        ps.println(text);
    } catch (IOException e) {
        ps.println(text);
    }
}

From source file:es.sotileza.plugin.utils.Utilidades.java

public static void paintMaestroDWR(String file, List<String> tr1, ArquetipoVO arq, List<TablaVO> tablas)
        throws IOException {
    FileWriter output = new FileWriter(file);
    BufferedWriter writer = new BufferedWriter(output);

    writer.write("package " + arq.getPakete() + ".web.dwr;\n\r");

    writer.write("\nimport org.apache.commons.logging.Log;");
    writer.write("\nimport org.apache.commons.logging.LogFactory;");
    writer.write("\nimport org.springframework.context.ApplicationContext;");
    writer.write("\nimport org.springframework.context.support.ClassPathXmlApplicationContext;");
    writer.write("\nimport " + arq.getPakete() + ".business.vo.*;");
    writer.write("\nimport " + arq.getPakete() + ".web.delegate.*;");
    writer.write("\n\r");

    writer.write("\npublic class MaestrosController {\n\r");
    writer.write("\n\tprivate static Log log = LogFactory.getFactory().getInstance(MaestrosController.class);");
    writer.write(/*from w ww  .  java 2  s.  c o  m*/
            "\n\tprivate static ApplicationContext contextApplication = new ClassPathXmlApplicationContext(");
    writer.write("\n\t\t\tnew String[] { \"beans/business/dao-beans.xml\",");
    writer.write("\n\t\t\t\"beans/business/datasource-beans.xml\",");
    writer.write("\n\t\t\t\"beans/business/transaction-beans.xml\",");
    writer.write("\n\t\t\t\"beans/business/manager-beans.xml\",");
    writer.write("\n\t\t\t\"beans/web/delegate-beans.xml\"});\n\r");

    for (TablaVO tab : tablas) {
        if (tab.getNivel().equals("maestro")) {
            writer.write("\n\tprivate " + tab.getDelegateClase() + " " + tab.getDelegateVariable() + " = " + "("
                    + tab.getDelegateClase() + ")contextApplication.getBean(\"" + tab.getDelegateVariable()
                    + "\");\n");
        }
    }
    for (String i : tr1)
        writer.write(i + "\n");
    writer.write("\n}");
    System.out.println("Generado el fichero: " + file);
    writer.flush();
}

From source file:com.csipsimple.utils.SipProfileJson.java

/**
 * Save current sip configuration//from www . j  a  v  a 2  s .c o m
 * @param ctxt
 * @return
 */
public static boolean saveSipConfiguration(Context ctxt) {
    File dir = PreferencesWrapper.getConfigFolder();
    if (dir != null) {
        Date d = new Date();
        File file = new File(dir.getAbsoluteFile() + File.separator + "backup_"
                + DateFormat.format("MM-dd-yy_kkmmss", d) + ".json");
        Log.d(THIS_FILE, "Out dir " + file.getAbsolutePath());

        JSONObject configChain = new JSONObject();
        try {
            configChain.put(KEY_ACCOUNTS, serializeSipProfiles(ctxt));
        } catch (JSONException e) {
            Log.e(THIS_FILE, "Impossible to add profiles", e);
        }
        try {
            configChain.put(KEY_SETTINGS, serializeSipSettings(ctxt));
        } catch (JSONException e) {
            Log.e(THIS_FILE, "Impossible to add profiles", e);
        }

        try {
            // Create file
            FileWriter fstream = new FileWriter(file.getAbsoluteFile());
            BufferedWriter out = new BufferedWriter(fstream);
            out.write(configChain.toString(2));
            // Close the output stream
            out.close();
            return true;
        } catch (Exception e) {
            // Catch exception if any
            Log.e(THIS_FILE, "Impossible to save config to disk", e);
            return false;
        }
    }
    return false;
}