Example usage for java.io FileWriter write

List of usage examples for java.io FileWriter write

Introduction

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

Prototype

public void write(int c) throws IOException 

Source Link

Document

Writes a single character.

Usage

From source file:com.mhs.hboxmaintenanceserver.utils.Utils.java

/**
 * Create properties file/*from w  w  w. j a  va 2  s  .c  om*/
 *
 * @param filename
 * @param props
 * @return
 */
private static File createPropFile(String filename, String[] props) {
    File file = new File(filename);
    if (!file.exists()) {
        FileWriter pw = null;
        try {
            pw = new FileWriter(file);
            for (String s : props) {
                pw.write(new String(s.getBytes(), "UTF-8"));
            }
            pw.close();
        } catch (IOException ex) {
            Logger.getLogger(Utils.class.getName()).log(Level.SEVERE, null, ex);
        } finally {
            try {
                if (pw != null) {
                    pw.close();
                }
            } catch (IOException ex) {
                Logger.getLogger(Utils.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }
    return file;
}

From source file:com.magnet.mmx.tsung.GenTestScript.java

public static void generateScripts(Settings settings) throws TemplateException {
    genSettings = settings;/*  w ww.  j  a v a  2 s.  c  o m*/
    File file = new File(settings.outputDir + "/userdb.csv");
    FileWriter fileWriter = null;
    try {
        fileWriter = new FileWriter(file);
        // hard-code to "test" for all passwords
        String password = "test";
        for (int i = 1; i <= settings.maxCount; i++) {
            String jid = settings.userName + i + "%" + settings.appId;
            int random = new Random().nextInt(settings.maxCount); // make sure it's at least 1
            if (random == 0)
                random++;
            String toJid = settings.userName + random + "%" + settings.appId;
            // jid;password;toJid
            StringBuilder rowBuilder = new StringBuilder();
            rowBuilder.append(jid).append(";").append(password).append(";").append(toJid).append("\n");
            fileWriter.write(rowBuilder.toString());
        }
        fileWriter.close();

        // generate the login load test file
        generateLoginScript(settings);

        // generate the dev registration files
        generateDevRegScript(settings);

        // generate the message send files
        generateSendMessageScript(settings);

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

From source file:Util.PacketGenerator.java

public static void GeneratePacket() {
    try {//from  www  .j av  a 2s  . c om
        File file = new File(
                "D:\\Mestrado\\Prototipo\\Trace\\Los Angeles\\equinix-sanjose.dirA.20120920-130000.UTC.anon.pcap.csv");
        File newFile = new File("D:\\Mestrado\\SketchMatrix\\trunk\\Tracer_100_Pacotes.csv");

        FileInputStream tracesFIS = new FileInputStream(file);
        DataInputStream tracesDIS = new DataInputStream(tracesFIS);
        BufferedReader tracesBR = new BufferedReader(new InputStreamReader(tracesDIS));

        FileWriter tracesFW = new FileWriter(newFile);

        String tracesStr = tracesBR.readLine();

        Random random = new Random();

        long numberOfPackets = 0;

        while (tracesStr != null && numberOfPackets < 100) {

            String[] packetTokens = tracesStr.split(",");

            long time = Long.parseLong(packetTokens[0]);
            long srcIP = Long.parseLong(packetTokens[1]);
            long dstIP = Long.parseLong(packetTokens[2]);
            int srcPort = Integer.parseInt(packetTokens[3]);
            int dstPort = Integer.parseInt(packetTokens[4]);
            int payload = random.nextInt(256);

            tracesFW.write(
                    time + "," + srcIP + "," + dstIP + "," + srcPort + "," + dstPort + "," + payload + "\n");

            tracesStr = tracesBR.readLine();
            numberOfPackets++;
            if ((numberOfPackets % 100000) == 0) {
                System.out.println(numberOfPackets / 1000 + "K Pacotes");
            }
        }
        tracesBR.close();
        tracesDIS.close();
        tracesFIS.close();
        tracesFW.close();
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}

From source file:com.photon.phresco.framework.commons.QualityUtil.java

public static void adaptTestConfig(String testDirPath, SettingsInfo serverSettings) throws PhrescoException {
    FileWriter out = null;
    try {/*from  ww w.j a  va 2s  . c o m*/
        File configFile = new File(testDirPath + configFileName);
        if (!configFile.exists()) {
            return;
        }
        out = new FileWriter(configFile);

        getSettingInfo(serverSettings);

        out.write(host + Constants.COMMA);
        out.write(port + Constants.COMMA);
        out.write(protocol + Constants.COMMA);
        out.write(serverContext);
        out.flush();
    } catch (IOException e) {
        throw new PhrescoException(e);
    } finally {
        try {
            if (out != null) {
                out.close();
            }
        } catch (IOException e) {
            throw new PhrescoException(e);
        }
    }
}

From source file:AuthenticateNT.java

public Object run() {
    try {//from   w  w w  .  j a v  a2  s  .  com
        File file = new File("D:/", "privilegedFile.txt");
        FileWriter fileWriter = new FileWriter(file);

        fileWriter.write("Welcome to JAAS!");
        fileWriter.close();
    } catch (IOException ioException) {
        ioException.printStackTrace();
    }

    return null;

}

From source file:gumga.framework.application.GumgaLoggerService.java

public void logToFile(String msg, int level) {
    try {/* w  w  w  .  j a  v a2s. c  o m*/
        String line = createLogLine(msg, level);
        File folder = new File(gumgaValues.getLogDir());
        folder.mkdirs();
        File log = new File(folder, "gumgalog.txt");
        FileWriter fw = new FileWriter(log, true);
        fw.write(line);
        fw.close();
    } catch (IOException ex) {
        log.error("Problema ao loggar no arquivo", ex);
    }
}

From source file:io.gumga.application.GumgaLoggerService.java

/**
 * Adiciona uma mensagem no gumgalog.txt
 * @param msg mensagem a ser adicionada no arquivo
 * @param level index da execption do StrackTrace
 */// w w w. j av a 2s. c  om
public void logToFile(String msg, int level) {
    try {
        String line = createLogLine(msg, level);
        File folder = new File(gumgaValues.getLogDir());
        folder.mkdirs();
        File log = new File(folder, "gumgalog.txt");
        FileWriter fw = new FileWriter(log, true);
        fw.write(line);
        fw.close();
    } catch (IOException ex) {
        log.error("Problema ao loggar no arquivo", ex);
    }
}

From source file:org.oncoblocks.centromere.mongodb.MongoImportTempFileWriter.java

/**
 * Writes a {@link Model} record to a temp file, formatted into JSON using {@link ImportUtils#convertEntityToJson(Object)}.
 * // ww w  . j  a  v  a2  s.co  m
 * @param record
 * @throws DataImportException
 */
public void writeRecord(T record) throws DataImportException {
    FileWriter writer = this.getWriter();
    try {
        writer.write(importUtils.convertEntityToJson(record));
        writer.write("\n");
    } catch (IOException e) {
        e.printStackTrace();
        throw new DataImportException(e.getMessage());
    }
}

From source file:org.xsocket.connection.SpringTest.java

@Test
public void testSimple() throws Exception {

    File file = QAUtil.createTempfile();
    FileWriter fw = new FileWriter(file);
    fw.write(SPRING_XML);
    fw.close();//w  w w  . j  a v  a  2s.  c om

    BeanFactory beanFactory = new XmlBeanFactory(new FileSystemResource(file));
    IServer server = (IServer) beanFactory.getBean("server");
    Assert.assertTrue(server.isOpen());
    assert (server.isOpen() == true);

    IBlockingConnection connection = new BlockingConnection("localhost", server.getLocalPort());
    connection.setAutoflush(true);
    String request = "3453543535";
    connection.write(request + EchoHandler.DELIMITER);

    String response = connection.readStringByDelimiter(EchoHandler.DELIMITER, Integer.MAX_VALUE);
    connection.close();

    Assert.assertTrue(request.equals(response));

    file.delete();
    server.close();
}

From source file:com.karki.spring.dao.impl.FacilitatorDaoImpl.java

@Override
public void exportData(String filename, String content)
        throws IOException, ClassNotFoundException, SQLException {
    FileWriter fileWriter = new FileWriter(new File(filename));
    fileWriter.write(content);
    fileWriter.close();/*from   www.  j av  a 2s.  c  o  m*/
}