Example usage for java.io FileReader close

List of usage examples for java.io FileReader close

Introduction

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

Prototype

public void close() throws IOException 

Source Link

Usage

From source file:com.flipkart.polyguice.config.JsonConfiguration.java

public JsonConfiguration(File file) throws IOException {
    FileReader reader = new FileReader(file);
    load(reader);/*w  w  w  .jav  a  2 s  .c  o  m*/
    reader.close();
}

From source file:org.eclipselabs.spray.releng.tools.ant.CompositeSiteTaskTest.java

@Test
public void test_addRelease() throws Exception {
    File testFile = new File("src/test/resources/compositeArtifacts.xml");
    assertTrue(testFile.exists());/*from ww w .j av a2 s.  c  om*/
    File f = File.createTempFile("compositeArtifacts", ".xml");
    f.deleteOnExit();
    FileReader reader = new FileReader(testFile);
    FileWriter writer = new FileWriter(f);

    IOUtils.copy(reader, writer);
    reader.close();
    writer.close();

    Project project = new Project();
    task.setProject(project);

    task.setCompositeArtifactsXml(f);
    task.setVersionToAdd("0.5.0");
    task.execute();

    reader = new FileReader(f);
    String content = FileUtils.readFully(reader);
    reader.close();
    assertTrue(content.contains("0.5.0"));
}

From source file:com.googlecode.t7mp.CommonsSetupUtilTest.java

private void checkResultFile() throws IOException {
    FileReader reader = new FileReader(target);
    char[] buffer = new char[10];
    reader.read(buffer);//from w w  w. j ava 2s  .  c om
    reader.close();
    String result = new String(buffer);
    Assert.assertEquals(MESSAGE, result.trim());
}

From source file:jfix.db4o.engine.PersistenceEngineXStream.java

public Collection<Object> query() {
    try {//from w  w  w . j a  va 2s.com
        if (new File(filename).exists()) {
            XStream xstream = new XStream(new DomDriver());
            xstream.setMode(XStream.ID_REFERENCES);
            FileReader reader = new FileReader(filename);
            objects = (Set<Object>) xstream.fromXML(reader);
            reader.close();
        }
        return objects;
    } catch (Exception e) {
        throw new RuntimeException(e.getMessage(), e);
    }
}

From source file:com.clustercontrol.platform.PlatformPertial.java

public static void setupHostname() {
    String hostname = null;//  www  .  j  av  a2 s. c  o m
    // hinemos.cfg???hostname?
    String etcDir = System.getProperty("hinemos.manager.etc.dir");
    if (etcDir != null) {
        File config = new File(etcDir, "hinemos.cfg");
        FileReader fr = null;
        BufferedReader br = null;
        try {
            fr = new FileReader(config.getAbsolutePath());
            br = new BufferedReader(fr);

            String line;
            while ((line = br.readLine()) != null) {
                line = line.trim();
                if (line.trim().startsWith("MANAGER_HOST")) {
                    hostname = line.split("=")[1];
                    break;
                }
            }
        } catch (FileNotFoundException e) {
            log.warn("configuration file not found." + config.getAbsolutePath(), e);
        } catch (IOException e) {
            log.warn("configuration read error." + config.getAbsolutePath(), e);
        } finally {
            if (br != null) {
                try {
                    br.close();
                } catch (IOException e) {
                }
            }

            if (fr != null) {
                try {
                    fr.close();
                } catch (IOException e) {
                }
            }
        }
    }

    if (hostname == null || hostname.length() == 0) {
        Runtime runtime = Runtime.getRuntime();
        Process process = null;
        InputStreamReader is = null;
        BufferedReader br = null;

        try {
            process = runtime.exec("hostname");

            is = new InputStreamReader(process.getInputStream());
            br = new BufferedReader(is);
            process.waitFor();

            if (br != null) {
                hostname = br.readLine();
            }

        } catch (IOException | InterruptedException e) {
            log.warn("command execute error.", e);
        } finally {
            if (process != null) {
                process.destroy();
            }

            if (br != null) {
                try {
                    br.close();
                } catch (IOException e) {
                }
            }

            if (is != null) {
                try {
                    is.close();
                } catch (IOException e) {
                }
            }
        }
    }

    if (hostname == null) {
        hostname = "";
    }

    System.setProperty("hinemos.manager.hostname", hostname);
}

From source file:eu.europa.ec.markt.dss.signature.StreamDocumentTest.java

@Test
public void save() throws Exception {
    document.save("streamDocumentSaveTest.txt");
    assertTrue(Files.exists(Paths.get("streamDocumentSaveTest.txt")));

    FileReader fileReader = new FileReader("streamDocumentSaveTest.txt");
    int read = fileReader.read();
    fileReader.close();

    assertEquals(65, read);// ww  w .jav a2s . c om
    Files.deleteIfExists(Paths.get("streamDocumentSaveTest.txt"));
}

From source file:net.sourceforge.jcctray.utils.ObjectPersister.java

public static JCCTraySettings loadJCCTraySettings(String fileName) throws IOException, SAXException {
    Digester digester = new Digester();

    FileReader fileReader = new FileReader(fileName);

    digester.addRule("cctraysettings", new ObjectCreateRule(JCCTraySettings.class));

    digester.addRule("cctraysettings/hosts/host", new ObjectCreateRule(Host.class));
    digester.addRule("cctraysettings/hosts/host", new SetPropertiesRule());
    digester.addRule("cctraysettings/hosts/host", new SetNextRule("addHost"));

    digester.addRule("cctraysettings/hosts/host/projects/project",
            new ObjectCreateRule(DashBoardProject.class));
    digester.addRule("cctraysettings/hosts/host/projects/project", new SetPropertiesRule());
    digester.addRule("cctraysettings/hosts/host/projects/project", new SetNextRule("addConfiguredProject"));

    digester.addRule("cctraysettings/settings/entry", new ObjectCreateRule(NameValuePair.class));
    digester.addRule("cctraysettings/settings/entry", new SetPropertiesRule());
    digester.addRule("cctraysettings/settings/entry", new SetNextRule("set"));
    JCCTraySettings result = (JCCTraySettings) digester.parse(fileReader);
    fileReader.close();
    return result;
}

From source file:SiteFrame.java

public void loadContent() {
    try {//from   w  w w . j a  v a 2s.  co  m
        FileReader fr = new FileReader(filename);
        ta.read(fr, null);
        fr.close();
    } catch (Exception e) {
        System.err.println("Could not load page: " + filename);
    }
}

From source file:de.xirp.managers.DeleteManager.java

/**
 * Deletes all files listed in the delete properties file and
 * deletes the properties file itself afterwards.
 *//*from ww w . java  2  s  .c  o  m*/
private void deleteFromPropsFile() {
    Properties props = new Properties();
    File f = new File(Constants.TO_DELETE_FILE);
    try {
        FileReader fr = new FileReader(f);
        props.load(fr);
        fr.close();
        for (Object obj : props.values()) {
            String path = (String) obj;
            try {
                FileUtils.forceDelete(new File(path));
            } catch (IOException e) {
                logClass.warn(I18n.getString("DeleteManager.notDeleted", path) //$NON-NLS-1$
                        + Constants.LINE_SEPARATOR);
            }
        }
        f.delete();
    } catch (FileNotFoundException e) {
        logClass.error("Error: " + e.getMessage() + Constants.LINE_SEPARATOR, e); //$NON-NLS-1$
    } catch (IOException e) {
        logClass.error("Error: " + e.getMessage() + Constants.LINE_SEPARATOR, e); //$NON-NLS-1$
    }
}

From source file:net.douglasthrift.bigscreenbot.Settings.java

public void load() throws FileNotFoundException, IOException {
    FileReader reader = null;

    try {//from w  w w  .  j  av a 2  s .  c om
        reader = new FileReader(SETTINGS);

        load(reader);
    } finally {
        if (reader != null)
            reader.close();
    }
}