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:org.gradle.api.publish.maven.internal.publisher.ValidatingMavenPublisher.java

private Model readModelFromPom(File pomFile) throws IOException, XmlPullParserException {
    FileReader reader = new FileReader(pomFile);
    try {// w w  w  .j a  v  a2 s.co m
        return new MavenXpp3Reader().read(reader);
    } finally {
        reader.close();
    }
}

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

@Override
public void load() throws IOException {

    File f = new File(getAbsolutePath());
    if (f.exists()) {

        if (logger.isDebugEnabled()) {
            logger.debug("[LOAD] " + f.getName() + " exists; loading");
        }//from  w w  w. j  av  a  2 s .  c  o  m
        FileReader fr = new FileReader(f);
        Properties props = new Properties();
        props.load(fr);
        settings.setRoundUp(BooleanUtils.toBoolean(props.getProperty("oldscores.roundUp")));
        fr.close();
    } else {
        if (logger.isDebugEnabled()) {
            logger.debug("[LOAD " + f.getName() + " does not exist");
        }
    }

}

From source file:com.springsource.hq.plugin.tcserver.plugin.serverconfig.FileUtilityTest.java

@Test
public void testRevertLatestBackupFiles() throws IOException, InterruptedException, FileUtilityException {
    LOGGER.debug("REVERT TEST STARTING");
    Date latestDate = new Date();
    fileUtility.copyBackupFile(TEMP_DIR, "config", "tempfile2.tmp", latestDate);
    File alterFile = new File(TEMP_DIR + "/config/tempfile2.tmp");
    LOGGER.debug("ALTER FILE - " + alterFile.getAbsolutePath() + " - Exists: " + alterFile.isFile());
    FileWriter writer = new FileWriter(alterFile);
    writer.append("THIS IS A NEWER FILE");
    writer.close();/*from w ww.  ja va2  s .c o  m*/
    FileReader reader = new FileReader(alterFile);
    BufferedReader br = new BufferedReader(reader);
    String fileText = br.readLine();
    reader.close();
    assertEquals("This text should be the same.", "THIS IS A NEWER FILE", fileText);
    Set<String> latestDirs = fileUtility.getLatestBackupDirectories(TEMP_DIR);
    String highestDirectory = ((TreeSet<String>) latestDirs).last();
    fileUtility.revertToBackupFiles(TEMP_DIR, highestDirectory);
    alterFile = new File(TEMP_DIR + "/config/tempfile2.tmp");
    LOGGER.debug("ALTER FILE After - " + alterFile.getAbsolutePath() + " - Exists: " + alterFile.isFile());
    reader = new FileReader(alterFile);
    br = new BufferedReader(reader);
    fileText = br.readLine();
    reader.close();
    assertEquals("The text in the file should be the same.", FILE2_TEXT, fileText);
}

From source file:org.ecoinformatics.emltest.SaxValidateTest.java

/**
 * Test if XML documents are valid with respect to their schemas.
 *///from ww w  . j a  va 2  s .c  o  m
public void testSchemaValid() {
    SAXValidate test = new SAXValidate(true);
    assertTrue(test != null);

    File testDir = new File(TEST_DIR);
    Vector fileList = getXmlFiles(testDir);

    for (int i = 0; i < fileList.size(); i++) {
        File testFile = (File) fileList.elementAt(i);
        try {
            System.err.println("Validating file: " + testFile.getName());
            FileReader reader = new FileReader(testFile);
            String namespace = EMLParserServlet.findNamespace(reader);
            reader.close();
            test.runTest(new FileReader(testFile), namespace);
        } catch (Exception e) {
            if (e instanceof SAXParseException) {
                SAXParseException spe = (SAXParseException) e;
                System.err.println("Error on line: " + spe.getLineNumber());
            }
            e.printStackTrace(System.err);
            fail("Document NOT valid!\n\n" + e.getClass().getName() + "(" + e.getMessage() + ")");
        }
    }
}

From source file:org.onebusaway.nyc.vehicle_tracking.impl.VehicleTrackingManagementServiceImpl.java

@PostConstruct
public void setup() {

    if (_configPath == null || !_configPath.exists())
        return;/* ww w . j av  a 2 s. com*/

    try {
        Properties p = new Properties();
        FileReader in = new FileReader(_configPath);
        p.load(in);
        in.close();

        if (p.containsKey("noProgressTimeout"))
            _vehicleStalledTimeThreshold = Integer.parseInt(p.getProperty("noProgressTimeout"));

        if (p.containsKey("offRouteDistance"))
            _vehicleOffRouteDistanceThreshold = Double.parseDouble("offRouteDistance");

    } catch (IOException ex) {
        _log.warn("error loading configuration properties from " + _configPath, ex);
    }
}

From source file:com.linkedin.pinot.tools.admin.command.StopProcessCommand.java

private boolean stopProcess(String fileName) throws IOException {
    File file = new File(fileName);
    FileReader reader = new FileReader(file);
    int pid = reader.read();

    Runtime.getRuntime().exec("kill " + pid);
    reader.close();

    file.delete();//  w  w w .  j a v  a2 s .c  o  m
    return true;
}

From source file:eu.bittrade.libs.steemj.util.BrainkeyDictionaryManager.java

/**
 * Create a a new BrainkeyDictionaryManager instance. This method will load
 * and split the {@link #DICTIONARY_FILE_NAME}.
 * //ww  w  .j  a va 2  s.c om
 * @throws IOException
 *             If there is a problem loading the file.
 */
private BrainkeyDictionaryManager() throws IOException {
    FileReader fileReader = new FileReader(
            getClass().getClassLoader().getResource(DICTIONARY_FILE_NAME).getFile());
    try {
        this.brainKeyDictionary = IOUtils.toString(fileReader).split(DICTIONARY_DELIMITER);
    } finally {
        fileReader.close();
    }
}

From source file:net.ymate.platform.configuration.support.PropertyConfigFileHandler.java

public PropertyConfigFileHandler(File file) throws IOException {
    __rootProps = new Properties();
    FileReader _reader = new FileReader(file);
    try {//from w  w w .  j  a  v a  2 s .c o m
        __rootProps.load(_reader);
    } finally {
        _reader.close();
    }
}

From source file:uk.co.flax.biosolr.ontology.config.loaders.YamlConfigurationLoader.java

@Override
public IndexerConfiguration loadConfiguration() throws IOException {
    FileReader reader = new FileReader(configFile);
    final JsonNode node = mapper.readTree(yamlFactory.createParser(reader));
    final IndexerConfiguration config = mapper.readValue(new TreeTraversingParser(node),
            IndexerConfiguration.class);

    // Close the file reader
    reader.close();

    return config;
}

From source file:org.collectionspace.chain.csp.persistence.file.StubJSONStore.java

public JSONObject retrieveJSON(String filePath, JSONObject restrictions)
        throws ExistException, UnderlyingStorageException, UnimplementedException {
    // XXX hack: support views properly
    String XXXCHOP = "/view";
    String XXXCHOP2 = "/refs";

    if (filePath.endsWith(XXXCHOP))
        filePath = filePath.substring(0, filePath.length() - XXXCHOP.length());
    if (filePath.endsWith(XXXCHOP2))
        return new JSONObject();
    if (idRequest(filePath))
        return id.retrieveJSON(filePath, restrictions);
    File jsonFile = fileFromPath(filePath);
    if (!jsonFile.exists()) {
        throw new ExistException("No such file: " + filePath);
    }/*w w  w  .  j  ava2 s  . co m*/
    try {
        FileReader r = new FileReader(jsonFile);
        String data = IOUtils.toString(r);
        r.close();
        JSONObject jsonObject = new JSONObject(data);
        return jsonObject;
    } catch (IOException ioe) {
        return new JSONObject(); // XXX
    } catch (JSONException je) {
        return new JSONObject(); // XXX
    }
}