Example usage for java.io FileWriter flush

List of usage examples for java.io FileWriter flush

Introduction

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

Prototype

public void flush() throws IOException 

Source Link

Document

Flushes the stream.

Usage

From source file:com.shazam.fork.summary.JsonSummarySerializer.java

@Override
public void print(Summary summary) {
    FileWriter writer = null;
    try {/* ww  w  .ja va 2s  .c om*/
        File summaryFile = fileManager.createSummaryFile();
        writer = new FileWriter(summaryFile);
        gson.toJson(summary, writer);
        writer.flush();
    } catch (IOException e) {
        logger.error("Could not serialize the summary.", e);
    } finally {
        closeQuietly(writer);
    }
}

From source file:com.spider.ssh.SshConfigFile.java

/**
 * Saves Host objects to disk at the original location.
 * @throws IOException//w w  w . j  a  v a2 s  .co m
 */
public void save() throws IOException {
    FileWriter writer = new FileWriter(source);

    save(writer);

    writer.flush();
    writer.close();
}

From source file:de.hstsoft.sdeep.NoteManager.java

@SuppressWarnings("unchecked")
private void saveNotes() {
    JSONObject envelope = new JSONObject();
    envelope.put("version", VERSION);

    JSONArray jsonArray = new JSONArray();
    for (Note n : notes) {
        jsonArray.add(n.toJson());/*  w  w w.j  a va  2s .c o m*/
    }

    envelope.put("notes", jsonArray);

    try {
        File file = new File(directory + FILENAME);
        FileWriter fileWriter = new FileWriter(file);
        fileWriter.append(envelope.toJSONString());
        fileWriter.flush();
        fileWriter.close();
    } catch (IOException e) {
        e.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  w ww  .  ja v  a2s  . 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:com.yahoo.storm.yarn.TestConfig.java

@SuppressWarnings("rawtypes")
synchronized File createConfigFile(Map storm_conf) throws IOException {
    storm_conf_file = new File("./conf/storm.yaml");
    storm_conf_file.getParentFile().mkdirs();
    Yaml yaml = new Yaml();
    FileWriter writer = new FileWriter(storm_conf_file);
    Util.rmNulls(storm_conf);/*  w w w .java2 s  .c o m*/
    yaml.dump(storm_conf, writer);
    writer.flush();
    writer.close();
    return storm_conf_file;
}

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();//  w ww .j  a  v  a 2  s .c  o 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: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 {// www .j  a  v a2 s  .com
        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:com.collaide.fileuploader.requests.repository.RepositoryRequest.java

/**
 * download a file or a folder from the server to the disk a folder is
 * downloaded as a zip and the unzipped<br/>
 *
 * @param url the URL of the repo item to download
 * @param folderToSave the folderin which to save the downloaded item
 * @return The path of the saved file or folder
 * @throws IOException//  ww  w  . ja  v  a  2s.c  om
 */
public String download(String url, String folderToSave) throws IOException {
    ClientResponse response = Client.create().resource(url + "?" + CurrentUser.getAuthParams())
            .accept(MediaType.APPLICATION_JSON).get(ClientResponse.class);
    if (response.getStatus() != 200) {
        return null;
    }
    File downloadedFile = response.getEntity(File.class);

    File fileToSave = new File(folderToSave, getFileName(response));
    downloadedFile.renameTo(fileToSave);
    FileWriter fr = new FileWriter(downloadedFile);
    fr.flush();
    String itemName = fileToSave.getAbsolutePath();
    if (isAZip(response)) {
        unzip(fileToSave, new File(folderToSave));
        fileToSave.delete();
        itemName = FilenameUtils.removeExtension(itemName);
    }
    downloadedFile.getAbsolutePath();
    return itemName;
}

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
 *//* w ww  .j a  va2 s .  com*/
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: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   www  . j  a  va 2 s.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;
}