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:net.lmxm.ute.beans.configuration.ApplicationPreferences.java

/**
 * Creates the empty preferences file./*from  ww  w  .  j  a v  a 2  s  .c  o m*/
 *
 * @param preferencesFile the preferences file
 */
private void createEmptyPreferencesFile(final File preferencesFile) {
    final String prefix = "createEmptyPreferencesFile() :";

    LOGGER.debug("{} entered, preferencesFile={}", prefix, preferencesFile);

    try {
        if (preferencesFile.createNewFile()) {
            LOGGER.debug("{} preferences file created successfully", prefix);
        } else {
            LOGGER.error("{} unable to create preferences file", prefix);
            throw new ConfigurationException(ExceptionResourceType.PREFERENCES_FILE_ALREADY_EXISTS);
        }

        final FileWriter fileWriter = new FileWriter(preferencesFile);
        fileWriter.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?><preferences/>");
        fileWriter.close();
    } catch (final IOException e) {
        LOGGER.error("{} unable to create empty preferences file", prefix);
        throw new ConfigurationException(ExceptionResourceType.ERROR_CREATING_PREFERENCES_FILE, e);
    }

    LOGGER.debug("{} leaving", prefix);
}

From source file:com.googlecode.fascinator.portal.process.RecordProcessor.java

/**
 * 'post' - processing method.//  w ww .  j ava 2 s . co  m
 * 
 * he 'inputKey' entry in the dataMap contains ids queued for resending.
 * This is merged with the 'includeList' and persisted on the config file.
 * The 'lastRun' is updated and persisted as well.
 * 
 * @param id
 * @param inputKey
 * @param configFilePath
 * @param dataMap
 * @return
 * @throws Exception
 */
private boolean postProcess(String id, String inputKey, String configFilePath, HashMap<String, Object> dataMap)
        throws Exception {
    File configFile = new File(configFilePath);
    SimpleDateFormat dtFormat = new SimpleDateFormat("yyy-MM-dd'T'HH:mm:ss'Z'");
    JsonSimple config = new JsonSimple(configFile);
    config.getJsonObject().put("lastrun", dtFormat.format(new Date()));
    Collection<String> oids = (Collection<String>) dataMap.get(inputKey);
    JSONArray includedArr = config.getArray("includeList");
    if (oids != null && oids.size() > 0) {
        // some oids failed, writing it to inclusion list so it can be sent
        // next time...
        if (includedArr == null) {
            includedArr = config.writeArray("includeList");
        }
        includedArr.clear();
        for (String oid : oids) {
            includedArr.add(oid);
        }
    } else {
        // no oids failed, all good, clearing the list...
        if (includedArr != null && includedArr.size() > 0) {
            includedArr.clear();
        }
    }
    FileWriter writer = new FileWriter(configFile);
    writer.write(config.toString(true));
    writer.close();
    return true;
}

From source file:org.sift.batch.tag.service.TagCloudMarshallerService.java

/**
 * Helper method to write the tag cloud to the file system using the Marshaller
 * @param filePath the absolute path to the data file
 * @param tagCloudModel the TagCloudModel whose data is to be written to the specified file
 * @throws RuntimeException in case of errors in writing the data file
 *///from w  w  w  .  jav a  2s  .c  om
private void marshallTagCloud(String filePath, TagCloudModel tagCloudModel) throws RuntimeException {
    File file = new File(filePath);
    if (file.exists()) {
        file.delete();
    }
    try {
        file.createNewFile();
        String data = this.marshaller.marshal(tagCloudModel);
        FileWriter writer = new FileWriter(file);
        writer.write(data);
        writer.flush();
        writer.close();
    } catch (IOException e) {
        throw new RuntimeException(
                "Error writing tag cloud image for : " + tagCloudModel.getSubject() + " to file : " + filePath,
                e);
    }
}

From source file:com.juick.android.Utils.java

public static void setupWebView(final WebView wv, String content) {
    try {/*  w  ww  . ja  va 2s  .  c o  m*/
        if (skipWeb)
            return;
        SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(wv.getContext());
        File file = new File(wv.getContext().getCacheDir(), "temp.html");
        String PREFIX = "#prefs.checked.";
        while (true) {
            int ix = content.indexOf(PREFIX);
            if (ix == -1)
                break;
            int ix2 = content.indexOf("#", ix + 1);
            if (ix2 == -1)
                break;
            String key = content.substring(ix + PREFIX.length(), ix2);
            boolean def = false;
            if (key.endsWith("!")) {
                def = true;
                key = key.substring(0, key.length() - 1);
            }
            boolean checked = sp.getBoolean(key, def);
            content = content.substring(0, ix) + (checked ? "checked" : "") + content.substring(ix2 + 1);
        }
        FileWriter fileWriter = new FileWriter(file);
        fileWriter.write(content);
        fileWriter.close();
        wv.getSettings().setJavaScriptEnabled(true);
        //            wv.getSettings().setBlockNetworkImage(false);
        //            wv.getSettings().setBlockNetworkLoads(false);
        wv.getSettings().setLoadsImagesAutomatically(true);
        Uri uri = Uri.fromFile(file);
        wv.addJavascriptInterface(new Object() {
            public void onFormData(String str) {
                wv.setTag(str);
            }
        }, "EXT");
        wv.loadUrl(uri.toString());
    } catch (IOException e) {
        //
    }

}

From source file:de.fhg.iais.asc.viewspreview.ViewXmlScanner.java

private FileWriter createFile() throws IOException {
    final FileWriter result = new FileWriter(
            new File(this.target + File.separator + "views" + this.filecounter + ".html"), false);
    result.write("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" "
            + "\"http://www.w3.org/TR/html4/loose.dtd\">");
    result.write("<html><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">"
            + "<title>DDB-Views (Demo)</title></head><body>");
    return result;
}

From source file:org.zalando.stups.swagger.codegen.YamlToJson.java

public void convert() {
    logger.info("Generate .json file from .yaml");

    File outputDirectory = new File(outputDirectoryPath);
    if (!outputDirectory.exists()) {
        outputDirectory.mkdirs();/*from   w ww  .  j  av a2s . c  o m*/
        logger.info("OutputDirectory created");
    }

    File jsonFile = new File(outputDirectory, getYamlFilename() + ".json");
    FileWriter fileWriter = null;
    try {

        fileWriter = new FileWriter(jsonFile);
        fileWriter.write(getYamlFileContentAsJson());
        fileWriter.flush();
        logger.info("File written to " + jsonFile.getAbsolutePath());
    } catch (Exception e) {
        throw new RuntimeException(e.getMessage(), e);
    } finally {
        IOUtils.closeQuietly(fileWriter);
    }
}

From source file:presenter.MainPresenter.java

@Override
public void saveEmissionsequenceToFile(ActionEvent e) {
    JFileChooser fc = new JFileChooser();

    if (fc.showSaveDialog((Component) e.getSource()) == JFileChooser.APPROVE_OPTION) {
        File file = fc.getSelectedFile();
        try {//from w w w .ja v  a2  s  .  c o  m
            FileWriter fw = new FileWriter(file);
            fw.write(this.emissionsequenceModel.toString());
            fw.flush();
            fw.close();
            this.displayStatus("File was written successfully!");
        } catch (IOException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }
    }
}

From source file:presenter.MainPresenter.java

@Override
public void saveMovementsequenceToFile(ActionEvent e) {
    JFileChooser fc = new JFileChooser();

    if (fc.showSaveDialog((Component) e.getSource()) == JFileChooser.APPROVE_OPTION) {
        File file = fc.getSelectedFile();
        try {/*from  ww w .  j a  va2s  .c o  m*/
            FileWriter fw = new FileWriter(file);
            fw.write(this.movSeq.toString());
            fw.flush();
            fw.close();
            this.displayStatus("File was written successfully!");
        } catch (IOException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }
    }
}

From source file:it.unibas.spicygui.controllo.tree.ActionExportQuery.java

public void actionPerformed(ActionEvent e) {
    this.executeInjection();
    JFileChooser chooser = vista.getFileChooserSalvaFileGenerico();
    File file;//ww  w. j av a2s.co  m
    int returnVal = chooser.showDialog(WindowManager.getDefault().getMainWindow(),
            NbBundle.getMessage(Costanti.class, Costanti.EXPORT));
    if (returnVal == JFileChooser.APPROVE_OPTION) {
        FileWriter writer = null;
        try {
            file = chooser.getSelectedFile();
            writer = new FileWriter(file);
            writer.write(this.textArea.getText());
            writer.flush();
            StatusDisplayer.getDefault().setStatusText(NbBundle.getMessage(Costanti.class, Costanti.EXPORT_OK));
        } catch (IOException ex) {
            DialogDisplayer.getDefault().notify(new NotifyDescriptor.Message(
                    NbBundle.getMessage(Costanti.class, Costanti.EXPORT_ERROR) + " : " + ex.getMessage(),
                    DialogDescriptor.ERROR_MESSAGE));
            logger.error(ex);
        } finally {
            try {
                writer.close();
            } catch (IOException ex) {
            }
        }
    }
}

From source file:com.brienwheeler.svc.content.impl.ContentServiceTest.java

@Test(expected = ContentServiceConfigException.class)
public void testSetBaseDirectoryFailNotDir() throws IOException {
    try {/*  w  ww .  j  a v  a2 s.  c  o m*/
        FileWriter writer = new FileWriter(baseDirectory);
        writer.write("foo\n");
        writer.close();

        contentService.setBaseDirectory(baseDirectory);
        Assert.fail();
    } catch (ContentServiceConfigException e) {
        baseDirectory.delete();
        throw e;
    }
}