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:org.mashupmedia.service.MapperManagerImpl.java

@Override
public void writeStartRemoteMusicLibraryXml(long libraryId, LibraryType libraryType) throws Exception {
    File file = FileHelper.getLibraryXmlFile(libraryId);
    FileWriter writer = new FileWriter(file, false);
    writer.write("<?xml version=\"1.0\" ?>");

    writer.write("<library type=\"" + libraryType.name().toLowerCase() + "\">");
    writer.close();/*from  w ww.j a  v a  2s  .  c  o m*/
}

From source file:org.apache.qpid.disttest.charting.writer.ChartWriterTest.java

private void writeDummyContentToSummaryFileToEnsureItGetsOverwritten(File summaryFile) throws Exception {
    FileWriter writer = null;
    try {/*from   w ww  .j  av  a  2  s  .c o  m*/
        writer = new FileWriter(summaryFile);
        writer.write("dummy content");
        writer.close();
    } finally {
        if (writer != null) {
            writer.close();
        }
    }
}

From source file:com.respam.comniq.models.OMDBParser.java

public void movieInfoWriter() {
    String path = System.getProperty("user.home") + File.separator + "comniq" + File.separator + "output";
    File userOutDir = new File(path);
    if (userOutDir.exists()) {
        System.out.println(userOutDir + " already exists");
    } else if (userOutDir.mkdirs()) {
        System.out.println(userOutDir + " was created");
    } else {//from w w  w  .j  a va2 s.  c o m
        System.out.println(userOutDir + " was not created");
    }
    try {
        FileWriter omdbList = new FileWriter(userOutDir + File.separator + "MovieInfo.json");
        omdbList.write(movieInfo.toJSONString());
        omdbList.flush();
        omdbList.close();
        System.out.println("Movie Info Written");
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:fr.inria.oak.paxquery.algebra.operators.BaseLogicalOperator.java

public void draw(String folder, String givenFileName) {
    //System.out.println("BaseLogicalOperator:");
    //System.out.println("\tfolder: "+folder);
    //System.out.println("\tgivenFileName: "+givenFileName);

    StringBuffer sb = new StringBuffer();
    sb.append("digraph  g{\n edge [dir=\"back\"]\n");
    recursiveDotString(sb, 0, 100);//from   www  .j  av  a2s.  c om
    try {
        if (givenFileName == null) {
            givenFileName = "" + System.currentTimeMillis();
        }
        String pathName = "";
        int lastSlash = givenFileName.lastIndexOf(File.separator);
        if (lastSlash > 0) {
            pathName = givenFileName.substring(0, lastSlash);
            File dir = new File(pathName);
            dir.mkdirs();
        }

        String fileNameDot = new String(folder + File.separator + givenFileName + "-logplan.dot");
        String fileNamePNG = new String(folder + File.separator + givenFileName + "-logplan.png");

        //System.out.println("fileNameDot: "+fileNameDot);
        FileWriter file = new FileWriter(fileNameDot);
        file.write(new String(sb));
        file.write("}\n");
        file.close();
        Runtime r = Runtime.getRuntime();
        String com = new String("dot -Tpng " + fileNameDot + " -o " + fileNamePNG);
        Process p = r.exec(com);
        p.waitFor();
        //System.out.println("Logical plan drawn.");
        logger.debug("Logical plan drawn.");
    } catch (Exception e) {
        logger.error("Exception: ", e);
    }
}

From source file:com.me.SmartContracts.Utils.DocumentReader.java

public void getAllCapitalWords() {
    Set<String> allCapsWords = new HashSet<>();
    Pattern p = Pattern.compile("\\b[A-Z]{2,}\\b");
    Matcher m = p.matcher(docText);
    while (m.find()) {
        String word = m.group();/*from   w w w  .  ja  v  a2 s  . co m*/
        // System.out.println(word);
        allCapsWords.add(word);
    }

    for (String allcaps : allCapsWords) {
        // System.out.println(allcaps);
    }
    System.out.println("Caps word count" + allCapsWords.size());
    org.json.simple.JSONObject obj = new org.json.simple.JSONObject();
    int count = 0;
    for (String output : outputArray) {
        obj.put(String.valueOf(count), output.replaceAll("\\s+", " "));
        count++;
    }
    try {

        FileWriter file = new FileWriter("CapsWord.json");
        file.write(obj.toJSONString());
        file.flush();
        file.close();

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

From source file:co.mcme.animations.animations.commands.AnimationFactory.java

public static boolean saveAnimationData(Player p) {
    //Perform Animation integrity checks
    if (animationName.trim().isEmpty()) {
        p.sendMessage(ChatColor.RED//from  w w w .  ja  v  a  2s  .  c o  m
                + "Animation name has not been set. Use /anim name while in Animation setup mode to set up the animation name");
        return false;
    }

    if ((null == animationDescription) || (animationDescription.trim().isEmpty())) {
        p.sendMessage(ChatColor.RED
                + "The animation needs a description. Use /anim description while in Animation setup mode to set up the animation description");
        return false;
    }

    if (null == origin) {
        p.sendMessage(ChatColor.RED
                + "Origin has not been set. Use /anim origin while in Animation setup mode to set up the animation origin");
        return false;
    }

    if (null == type) {
        p.sendMessage(ChatColor.RED
                + "Animation type has not been set. Use /anim type while in Animation setup mode to set up the animation type");
        return false;
    }

    if (frames.isEmpty()) {
        p.sendMessage(ChatColor.RED + "The Animation doesn't contain any Frame!");
        return false;
    }

    if (clips.isEmpty()) {
        p.sendMessage(ChatColor.RED + "The Animation doesn't contain any Clipboard!");
        return false;
    }
    if (triggers.isEmpty()) {
        p.sendMessage(ChatColor.RED + "The Animation doesn't contain any Trigger!");
        return false;
    }
    //Save all the schematics
    File animationFolder = new File(MCMEAnimations.MCMEAnimationsInstance.getDataFolder() + File.separator
            + "schematics" + File.separator + "animations" + File.separator + animationName);
    if (animationFolder.exists()) {
        try {
            delete(animationFolder);
        } catch (IOException ex) {
            Logger.getLogger(AnimationFactory.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    animationFolder.mkdirs();

    for (MCMEClipboardStore cs : clips) {
        if (cs.getUses() > 0) {
            saveClipboardToFile(cs.getClip(), cs.getSchematicName(), animationFolder);
        }
    }

    //Save the configuration file
    JSONObject configuration = new JSONObject();
    configuration.put("name", animationName);
    configuration.put("world-index", p.getWorld().getName());
    JSONArray frameList = new JSONArray();
    JSONArray durationList = new JSONArray();
    for (int i = 0; i < frames.size(); i++) {
        frameList.add(frames.get(i).getSchematic().getSchematicName());
        durationList.add(frames.get(i).getDuration());
    }
    configuration.put("frames", frameList);
    configuration.put("durations", durationList);

    JSONArray originPoints = new JSONArray();
    originPoints.add((int) Math.floor(origin.getX()));
    originPoints.add((int) Math.floor(origin.getY()));
    originPoints.add((int) Math.floor(origin.getZ()));
    configuration.put("origin", originPoints);

    configuration.put("type", type.toString());

    JSONArray interactions = new JSONArray();
    for (AnimationTrigger at : triggers) {
        interactions.add(at.toJSON());
    }

    configuration.put("interactions", interactions);

    JSONArray animationActions = new JSONArray();
    for (AnimationAction a : actions) {
        animationActions.add(a.toJSON());
    }
    if (animationActions.size() > 0) {
        configuration.put("actions", animationActions);
    }

    configuration.put("creator", owner.getDisplayName());
    configuration.put("description", animationDescription);

    try {
        FileWriter fw = new FileWriter(new File(MCMEAnimations.MCMEAnimationsInstance.getDataFolder()
                + File.separator + "schematics" + File.separator + "animations" + File.separator + animationName
                + File.separator + "conf.json"));
        fw.write(configuration.toJSONString());
        fw.flush();
        fw.close();
    } catch (IOException ex) {
        p.sendMessage("Error saving Animation configuration file!");
        return false;
    }

    p.sendMessage(ChatColor.BLUE + "" + ChatColor.BOLD + "Animation " + animationName
            + " saved and ready to run! Use /anim reset to reload the configuration.");
    return true;
}

From source file:com.bc.fiduceo.post.PostProcessingTool_IOTest.java

@Test
public void testInitialisation() throws Exception {
    final Options options = PostProcessingTool.getOptions();
    final PosixParser parser = new PosixParser();
    final CommandLine commandLine = parser.parse(options, new String[] { "-j", processingConfigName, "-i",
            "/mmd_files", "-start", "2011-123", "-end", "2011-124", "-c", configDir.getPath() });

    final FileWriter fileWriter = new FileWriter(new File(configDir, "system-config.xml"));
    fileWriter.write("<system-config></system-config>");
    fileWriter.close();/*from   w w w. ja  v  a2s. co  m*/

    final PostProcessingContext context = PostProcessingTool.initializeContext(commandLine);

    final String separator = FileSystems.getDefault().getSeparator();
    assertEquals(separator + "mmd_files", context.getMmdInputDirectory().toString());
    assertEquals("03-May-2011 00:00:00", ProductData.UTC.createDateFormat().format(context.getStartDate()));
    assertEquals("04-May-2011 23:59:59", ProductData.UTC.createDateFormat().format(context.getEndDate()));

    final SystemConfig sysConfig = context.getSystemConfig();
    assertNotNull(sysConfig);
    assertNull(sysConfig.getArchiveConfig());

    final PostProcessingConfig config = context.getProcessingConfig();
    assertNotNull(config);
    final List<Element> postProcessingElements = config.getPostProcessingElements();
    assertNotNull(postProcessingElements);
    assertEquals("java.util.Collections$UnmodifiableList", postProcessingElements.getClass().getTypeName());
    assertEquals(1, postProcessingElements.size());
    assertEquals(TAG_NAME_SPHERICAL_DISTANCE, postProcessingElements.get(0).getName());
}

From source file:com.telefonica.euro_iaas.sdc.puppetwrapper.services.impl.FileAccessServiceImpl.java

public Node generateManifestFile(String nodeName) throws IOException {

    logger.info("creating Manifest file for node: " + nodeName);

    Node node = catalogManager.getNode(nodeName);

    String fileContent = catalogManager.generateManifestStr(nodeName);
    String path = defaultManifestsPath + node.getGroupName();

    try {/*from  w w w.  java2 s .c  o m*/

        File f = new File(path);
        f.mkdirs();
        f.createNewFile();
    } catch (IOException ex) {
        logger.debug("Error creating manifest paths and pp file", ex);
        throw new IOException("Error creating manifest paths and pp file");
    }

    try {
        FileWriter fw = new FileWriter(path + "/" + node.getId() + ".pp", false);
        fw.write(fileContent);
        fw.close();
    } catch (IOException ex) {
        logger.debug("Error creating manifest paths and pp file", ex);
        throw new IOException("Error creating manifest paths and pp file");
    }

    logger.debug("Manifest file created");

    return node;

}

From source file:com.meltmedia.cadmium.core.history.HistoryManagerTest.java

@Before
public void setupForTest() throws Exception {
    File testDir = new File("./target/history-test");
    testDirectory = testDir.getAbsoluteFile().getAbsolutePath();

    if (!testDir.exists()) {
        testDir.mkdirs();/*from   www.  j a  va 2  s . com*/
    }

    historyFile = new File(testDir, HistoryManager.HISTORY_FILE_NAME);

    if (!historyFile.exists() || historyFile.canWrite()) {
        FileWriter writer = null;
        try {
            writer = new FileWriter(historyFile, false);
            writer.write(INIT_HISTORY_CONTENT);
            writer.flush();
        } catch (Exception e) {
        } finally {
            IOUtils.closeQuietly(writer);
        }
    }

    manager = new HistoryManager(testDirectory, Executors.newSingleThreadExecutor(), mock(EventQueue.class));
}

From source file:WebCategorizer.java

private JSONObject fetchCategories() {
    try {/*from  ww  w . jav a2s.c om*/
        JSONObject webCatList = new JSONObject();
        URL obj = new URL(categoriesUrl);
        HttpURLConnection con = (HttpURLConnection) obj.openConnection();
        con.setRequestMethod("GET");
        con.setRequestProperty("User-agent", "Web Categorizer");
        int responseCode = con.getResponseCode();
        if (responseCode == HttpURLConnection.HTTP_OK) {
            BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
            String inputLine;
            StringBuffer response = new StringBuffer();

            while ((inputLine = in.readLine()) != null) {
                response.append(inputLine);
            }
            in.close();

            JSONArray inputData = new JSONArray(response.toString());
            for (Object currObj : inputData) {
                JSONObject tempObj = (JSONObject) currObj;
                webCatList.put(String.format("%02X", tempObj.get("num")).toLowerCase(), tempObj.get("name"));
            }

            FileWriter file = new FileWriter(categoriesFile);
            file.write(webCatList.toString());
            file.flush();
            file.close();
        } else {
            System.out.println("Not working");
        }
        return webCatList;
    } catch (Exception ex) {
        return new JSONObject();
    }
}