Example usage for java.io BufferedWriter BufferedWriter

List of usage examples for java.io BufferedWriter BufferedWriter

Introduction

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

Prototype

public BufferedWriter(Writer out) 

Source Link

Document

Creates a buffered character-output stream that uses a default-sized output buffer.

Usage

From source file:com.pureinfo.srm.weight.action.ProbWeightConfigRadixAction.java

/**
 * @see com.pureinfo.ark.interaction.ActionBase#executeAction()
 *//*  w ww  .  j  av a2  s .  c  o  m*/
public ActionForward executeAction() throws PureException {
    String adjustType = request.getRequiredParameter("configType", "config type");
    String sFileName = getPropertiesFileName(adjustType);
    if (sFileName == null) {
        return mapping.findForward("success");
    }

    sFileName = ClassResourceUtil.mapFullPath(sFileName, true);

    PrintWriter pw = null;
    try {
        pw = new PrintWriter(
                new BufferedWriter(new OutputStreamWriter(new FileOutputStream(sFileName), "iso-8859-1")));
        Enumeration e = request.getParameterNames();
        while (e.hasMoreElements()) {
            String element = (String) e.nextElement();
            if (element.startsWith("weight.value.")) {
                pw.println(element + "=" + request.getParameter(element).trim());
                PureSystem.setProperty(element, request.getParameter(element).trim());
            }
        }
    } catch (FileNotFoundException ex) {
        throw new PureException(PureException.UNKNOWN, "", ex);
    } catch (UnsupportedEncodingException ex) {
        throw new PureException(PureException.UNKNOWN, "", ex);
    } finally {
        if (pw != null)
            pw.close();
    }
    request.setAttribute("forward", "../weight/weight-config-radix.jsp");
    return mapping.findForward("success");
}

From source file:com.ibm.g11n.pipeline.example.CSVFilter.java

@Override
public void write(OutputStream outStream, LanguageBundle languageBundle, FilterOptions options)
        throws IOException, ResourceFilterException {
    BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(outStream, StandardCharsets.UTF_8));
    CSVPrinter printer = CSVFormat.RFC4180.withHeader("key", "value").print(writer);
    for (ResourceString resString : languageBundle.getSortedResourceStrings()) {
        printer.printRecord(resString.getKey(), resString.getValue());
    }/* w w w .j a  va2s  . c  om*/
    printer.flush();
}

From source file:hu.bme.mit.trainbenchmark.generator.rdf.RdfSerializer.java

@Override
public void initModel() throws IOException {
    // source file
    final String modelFlavor = gc.getModelFlavor();
    final String extension = gc.getExtension();

    final String postfix = modelFlavor + "." + extension;

    final String srcFilePath = gc.getConfigBase().getWorkspaceDir() + RDF_METAMODEL_DIR + "railway" + postfix;

    final File srcFile = new File(srcFilePath);

    // destination file
    final String destFilePath = gc.getConfigBase().getModelPathWithoutExtension() + postfix;
    final File destFile = new File(destFilePath);

    // this overwrites the destination file if it exists
    FileUtils.copyFile(srcFile, destFile);

    file = new BufferedWriter(new FileWriter(destFile, true));
}

From source file:net.genesishub.gFeatures.Feature.gWarsSuiteOld.CrackshotConfiguration.java

public void MakeFile(String filename) throws IOException {
    Reader paramReader = new InputStreamReader(
            getClass().getResourceAsStream("/tk/genesishub/gFeatures/gWarsSuite/WeaponConfig/" + filename));
    StringWriter writer = new StringWriter();
    IOUtils.copy(paramReader, writer);/*from   w ww  . j a  va2  s  .  co  m*/
    String theString = writer.toString();
    File f = new File("plugins/CrackShot/weapons/" + filename + ".yml");
    f.createNewFile();
    BufferedWriter bw = new BufferedWriter(new FileWriter(f));
    bw.write(theString);
    bw.close();
}

From source file:com.egt.core.db.ddl.Writer.java

private static void execute(String vm, Map clases) {
    //      Utils.println("*** combinar(" + vm + ", clases=" + clases.size() + ") ***");
    if (clases == null || clases.size() == 0) {
        return;//from  ww  w . j a  v  a 2 s.  c  o  m
    }
    try {
        Template template = Velocity.getTemplate(vm);
        VelocityContext context = new VelocityContext();
        context.put("clases", clases);
        StringWriter sw = new StringWriter();
        template.merge(context, sw);
        String filename = vm.replace(".vm", ".sql");
        FileWriter fileWriter = new FileWriter(filename);
        BufferedWriter bufferedWriter = new BufferedWriter(fileWriter);
        bufferedWriter.write(sw.toString());
        bufferedWriter.close();
    } catch (ResourceNotFoundException ex) {
        ex.printStackTrace();
    } catch (ParseErrorException ex) {
        ex.printStackTrace();
    } catch (MethodInvocationException ex) {
        ex.printStackTrace();
    } catch (IOException ex) {
        ex.printStackTrace();
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}

From source file:com.orange.atk.results.logger.documentGenerator.GraphGenerator.java

/**
 * Generate a graph in png from the provided plot list. The X axis of the
 * graph is in minutes.//from  w w  w .j av a 2s .co m
 * 
 * @param plotList
 *            plotlist to save. Xvalues must be stored in milliseconds.
 * @param associatedName
 *            kind of the list
 * @param folderWhereResultsAreSaved
 *            folder where graph while be saved
 * @param yLabel
 *            name of the y label
 * @param pictureFile
 *            name of the file where the picture would be saved (path should
 *            be absolute)
 * @param yDivisor divisor of the measurements
 */
public static void generateGraph(PlotList plotList, String associatedName, String folderWhereResultsAreSaved,
        String yLabel, String pictureFile, float yDivisor) {
    Logger.getLogger("generateGraph").debug(folderWhereResultsAreSaved + associatedName + ".cmd");
    // Store measurements in a file
    try {
        dumpInFile(plotList, folderWhereResultsAreSaved + associatedName + ".csv");

        // Create gnuplot scripts used to generate graphs
        if (plotList.isEmpty()) {
            Logger.getLogger(GraphGenerator.class).warn(associatedName + " plot list is empty");
            return;
        }

        // create a .cmd which will be given to the gnuplot program
        File commandFile = new File(folderWhereResultsAreSaved + associatedName + ".cmd");
        BufferedWriter bufferedWriter = new BufferedWriter(
                new OutputStreamWriter(new FileOutputStream(commandFile)));
        // Picture will be saved in png
        bufferedWriter.write("set terminal png" + Platform.LINE_SEP);
        // Name of the picture
        bufferedWriter.write(
                "set output '" + folderWhereResultsAreSaved + associatedName + ".png'" + Platform.LINE_SEP);
        // format of the number on the y-axis
        bufferedWriter.write("set format y \"%.3s\"" + Platform.LINE_SEP);
        // Names of the axis
        bufferedWriter.write("set xlabel \"Time\"" + Platform.LINE_SEP);
        bufferedWriter.write("set ylabel \"" + yLabel + "\"" + Platform.LINE_SEP);
        // Set the range on y axis
        bufferedWriter.write("set yrange [" + (plotList.getMin() / yDivisor) * 0.9998 + ":"
                + (plotList.getMax() / yDivisor) * 1.0002 + "]" + Platform.LINE_SEP);
        bufferedWriter.write("set xtics autofreq" + Platform.LINE_SEP);
        bufferedWriter.write("set ytics autofreq" + Platform.LINE_SEP);
        bufferedWriter.write("plot '" + folderWhereResultsAreSaved + associatedName + ".csv' with lines"
                + Platform.LINE_SEP);
        bufferedWriter.flush();
        bufferedWriter.close();

        // call gnuplot for generating graphs
        Runtime runtime = Runtime.getRuntime();
        String gnuplotName = null;
        if (Platform.OS_NAME.toLowerCase().contains("windows")) {
            gnuplotName = "wgnuplot";
        } else {
            gnuplotName = "gnuplot";
        }
        String[] cmdsCpu1 = { gnuplotName, folderWhereResultsAreSaved + associatedName + ".cmd" };
        if (!plotList.isEmpty()) {
            // Call gnuplot
            int returnValue = runtime.exec(cmdsCpu1).waitFor();
            if (returnValue != 0) {
                Logger.getLogger(GraphGenerator.class).warn(
                        "Problem while creating graph. Does " + gnuplotName + " program belongs to PATH?");
            }
        }
    } catch (IOException e) {
        e.printStackTrace();
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
}

From source file:com.cisco.ca.cstg.pdi.services.license.LicenseCryptoServiceImpl.java

public void encryptToFile() throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException,
        IllegalBlockSizeException, BadPaddingException, IOException {
    BufferedWriter out = null;//  www. j a v  a 2s. com
    try {
        byte[] raw = getPassword().getBytes(Charset.forName(Constants.UTF8));
        SecretKeySpec skeySpec = new SecretKeySpec(raw, ALGORITHM_BLOWFISH);
        Cipher cipher = null;
        cipher = Cipher.getInstance(ALGORITHM_BLOWFISH);
        cipher.init(1, skeySpec);
        byte[] output = cipher.doFinal(getMetaData().getBytes());
        BigInteger n = new BigInteger(output);

        String b64hidden = Base64.encodeBase64String(n.toString(16).getBytes());
        setAssessmentKey(b64hidden);

        out = new BufferedWriter(new FileWriter(this.getAssessmentKeyFileName()));
        out.write(b64hidden);
    } finally {
        if (out != null) {
            out.close();
        }
    }
}

From source file:com.enioka.jqm.tools.MultiplexPrintStream.java

MultiplexPrintStream(OutputStream out, String rootLogDir, boolean alsoWriteToCommonLog) {
    super(out);/*from ww w .j a v  a 2s  . c  o  m*/
    this.useCommonLogFile = alsoWriteToCommonLog;
    this.original = new BufferedWriter(new OutputStreamWriter(out));
    this.rootLogDir = rootLogDir;

    File d = new File(this.rootLogDir);
    if (!d.isDirectory() && !d.mkdir()) {
        throw new JqmInitError("could not create log dir " + this.rootLogDir);
    }
}

From source file:fm.last.moji.tracker.impl.AbstractTrackerFactory.java

public Tracker newTracker(InetSocketAddress newAddress) throws TrackerException {
    log.debug("new {}()", TrackerImpl.class.getSimpleName());
    Tracker tracker = null;//  w w w.  j  av a2s.  com
    BufferedReader reader = null;
    Writer writer = null;
    Socket socket = null;
    try {
        socket = new Socket(netConfig.getProxy());
        socket.setSoTimeout(netConfig.getTrackerReadTimeout());
        log.debug("Connecting to: {}:", newAddress, socket.getPort());
        socket.connect(newAddress, netConfig.getTrackerConnectTimeout());
        reader = new BufferedReader(new InputStreamReader(socket.getInputStream()));
        writer = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream()));
        RequestHandler requestHandler = new RequestHandler(writer, reader);
        tracker = new TrackerImpl(socket, requestHandler);
    } catch (IOException e) {
        IOUtils.closeQuietly(reader);
        IOUtils.closeQuietly(writer);
        IOUtils.closeQuietly(socket);
        throw new TrackerException(e);
    }
    return tracker;
}