Example usage for java.io FileWriter close

List of usage examples for java.io FileWriter close

Introduction

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

Prototype

public void close() throws IOException 

Source Link

Usage

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   ww w  . ja v  a 2s.  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:com.github.igor_kudryashov.utils.notes.NotesTempFile.java

/**
 * Returns a temporary file and stores it name in the store ~ notetmp.reg
 * /*from   www .  j a  va 2s . co  m*/
 * @param postfix
 *            - postfix of temporary filename.
 * @return the temporary file.
 */
public File getTempFile(String postfix) {
    File file = null;
    String p = postfix;
    try {
        if (p == null) {
            p = ".tmp";
        } else {
            if (!p.startsWith(".")) {
                p = "." + p;
            }
        }
        file = File.createTempFile("~$0", p, new File(tempFolder));
        // add filename to store
        File storeFile = new File(tempFolder + File.separator + NOTES_TMP_FILENAME);
        String filename = file.getName();
        String fixfilename = StringUtils.rightPad(filename, 257, '\0');
        FileWriter fw = new FileWriter(storeFile, true);
        fw.write(fixfilename);
        fw.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return file;
}

From source file:com.bekwam.examples.javafx.oldscores.SettingsDAOImpl.java

@Override
public void save() throws IOException {

    if (logger.isDebugEnabled()) {
        logger.debug("[SAVE] saving " + getAbsolutePath());
    }/*  ww  w.jav a  2  s .  c  om*/
    FileWriter fw = new FileWriter(getAbsolutePath());
    Properties props = new Properties();
    props.setProperty("oldscores.roundUp", String.valueOf(settings.getRoundUp()));
    props.store(fw, "");
    fw.close();
}

From source file:de.uzk.hki.da.grid.IrodsGridFacadeTest.java

/**
 * Put file already exists with not applicable checksum.
 *
 * @throws Exception the exception/*  w  w  w  . j a  v  a  2  s  .  co  m*/
 * @author Jens Peters
 * @author Daniel M. de Oliveira
 */
@Test
public void putFileAlreadyExistsWithNotApplicableChecksum() throws Exception {

    if (!new File(irodsDir + "/aip/123456").exists())
        new File(irodsDir + "/aip/123456").mkdirs();
    File dis = new File(irodsDir + "/aip/123456/urn.tar");
    FileWriter writer = new FileWriter(dis, false);
    writer.write("Hallo Wie gehtsddfd?");
    writer.close();

    when(isc.executeRule(anyString(), anyString())).thenReturn("1") // -> replication solely on cache
            .thenReturn("1");
    when(isc.fileExists(anyString())).thenReturn(true);

    // assertEquals(false,ig.put(temp, "aip/123456/urn.tar"));
    assertEquals(true, temp.exists());
    assertEquals(true, ig.put(temp, "123456/urn.tar", sp, null));
    assertEquals(true, new File(irodsDir + "/aip/123456/urn.tar").exists());
}

From source file:mobi.jenkinsci.server.core.services.ImageRequestCommandTest.java

private File createImageFile() throws IOException {
    tmpFile = File.createTempFile(TMP_PREFIX, IMAGE_NAME_FROM_FILESYSTEM);
    final FileWriter out = new FileWriter(tmpFile);
    out.write(IMAGE_TEMP_FILE_CONTENT);/*from  www .  j a  v  a2s  .  c  o  m*/
    out.close();
    return tmpFile;
}

From source file:com.bbn.c2s2.pint.testdata.chart.ScatterPlot.java

public void toCsvFile(String fileName) throws IOException {
    FileWriter fw = new FileWriter(fileName);
    for (int i = 0; i < data[0].length; i++) {
        String out = data[0][i] + "," + data[1][i];
        fw.write(out + '\n');
    }/*from  w ww.j  a v  a 2 s . c  o  m*/
    fw.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 {//w  w  w.j  a  va2s.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:TestGetXMLClient.java

public void testXML() throws Exception {
    Collection<Class> classList = getClasses();
    String serverUrl = "@SERVER_URL@";
    for (Class klass : classList) {
        System.out.println("Searching for " + klass.getName());
        try {/*from  w  w  w. ja  v  a  2  s  .  c  o  m*/
            String searchUrl = serverUrl + "/GetXML?query=" + klass.getName() + "&" + klass.getName();
            URL url = new URL(searchUrl);
            URLConnection conn = url.openConnection();

            //Uncomment following two lines for secured system and provide proper username and password
            //String base64 = "userId" + ":" + "password";
            //conn.setRequestProperty("Authorization", "Basic " + new String(Base64.encodeBase64(base64.getBytes())));

            File myFile = new File("./output/" + klass.getName() + "_test-getxml.xml");

            FileWriter myWriter = new FileWriter(myFile);
            DataInputStream dis = new DataInputStream(conn.getInputStream());

            String s = null;
            while ((s = dis.readLine()) != null)
                myWriter.write(s);

            myWriter.close();
        } catch (Exception e) {
            System.out.println("Exception caught: " + e.getMessage());
            e.printStackTrace();
        }
        break;
    }
}

From source file:com.photon.phresco.util.ProjectUtils.java

/**
 * To update the project.info file with the new info
 * @param projectInfo/*ww  w  .ja  v  a  2  s .  com*/
 * @param projectInfoFile
 * @throws PhrescoException
 */
public static void updateProjectInfo(ProjectInfo projectInfo, File projectInfoFile) throws PhrescoException {
    BufferedWriter out = null;
    FileWriter fstream = null;
    try {
        Gson gson = new Gson();
        String infoJSON = gson.toJson(projectInfo);
        fstream = new FileWriter(projectInfoFile.getPath());
        out = new BufferedWriter(fstream);
        out.write(infoJSON);
    } catch (IOException e) {
        throw new PhrescoException(e);
    } finally {
        try {
            if (out != null) {
                out.close();
            }
            if (fstream != null) {
                fstream.close();
            }
        } catch (IOException e) {
            throw new PhrescoException(e);
        }
    }
}

From source file:de.uzk.hki.da.grid.IrodsGridFacadeTest.java

/**
 * Sets the up.//from w ww.  j  a v  a  2s . c  om
 *
 * @throws Exception the exception
 */
@Before
public void setUp() throws Exception {

    isc = mock(IrodsSystemConnector.class);
    ig = new IrodsGridFacade();
    ig.setIrodsSystemConnector(isc);

    when(isc.computeChecksum(anyString())).thenReturn("abc");
    when(isc.isConnected()).thenReturn(true);

    sp = new StoragePolicy();
    sp.setWorkingResource("cacheresc");
    sp.setGridCacheAreaRootPath(Path.make(irodsDir).toString());
    sp.setWorkAreaRootPath(Path.make(forkDir).toString());
    sp.setReplDestinations("lvr");

    when(isc.getZone()).thenReturn("zone");
    new File(irodsDir).mkdir();
    new File(forkDir).mkdir();
    temp = new File(forkDir + "urn.tar");
    FileWriter writer = new FileWriter(temp, false);
    writer.write("Hallo Wie gehts?");
    writer.close();
}