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:de.ailis.jasdoc.tree.TreeParser.java

/**
 * Parses the specified JavaScript file or directory. If file is a directory
 * then all JavaScript files and all sub folders are parsed recursively.
 *
 * @param file/*from  w ww.ja v  a  2s  .  co  m*/
 *            The JavaScript file (or directory) to parse.
 * @throws IOException
 *             When JavaScript file could not be read.
 */
public void parseFile(final File file) throws IOException {
    if (file.isDirectory()) {
        final File[] subs = file.listFiles();
        if (subs == null)
            return;
        for (final File sub : subs) {
            if (sub.getName().toLowerCase().endsWith(".js") || sub.isDirectory())
                parseFile(sub);
        }
        return;
    }
    LOG.debug("Parsing " + file + "...");
    final FileReader reader = new FileReader(file);
    try {
        final AstRoot rootNode = new Parser(this.compilerEnv).parse(reader, file.getAbsolutePath(), 1);

        parseRootNode(rootNode);
    } finally {
        reader.close();
    }
}

From source file:com.krikelin.spotifysource.AppInstaller.java

protected void copyFile(String src, String dest) throws IOException {
    File inputFile = new File(src);
    File outputFile = new File(dest);

    FileReader in = new FileReader(inputFile);
    FileWriter out = new FileWriter(outputFile);
    int c;//from w w w  .  j ava 2 s. c om

    while ((c = in.read()) != -1)
        out.write(c);

    in.close();
    out.close();
}

From source file:com.qwazr.webapps.transaction.ControllerManager.java

private void handleJavascript(WebappTransaction transaction, File controllerFile)
        throws IOException, ScriptException, PrivilegedActionException {
    WebappHttpResponse response = transaction.getResponse();
    response.setHeader("Cache-Control", "max-age=0, no-cache, no-store");
    Bindings bindings = scriptEngine.createBindings();
    IOUtils.CloseableList closeables = new IOUtils.CloseableList();
    bindings.put("console", new ScriptConsole());
    bindings.put("request", transaction.getRequest());
    bindings.put("response", transaction.getResponse());
    bindings.put("session", transaction.getRequest().getSession());
    bindings.putAll(transaction.getRequest().getAttributes());
    FileReader fileReader = new FileReader(controllerFile);
    try {/*ww  w  . j a v a 2 s . c  om*/
        ScriptUtils.evalScript(scriptEngine, RestrictedAccessControlContext.INSTANCE, fileReader, bindings);
    } finally {
        fileReader.close();
    }
}

From source file:com.runwaysdk.business.generation.maven.MavenClasspathBuilder.java

public static MavenProject loadProject(File pomFile) throws IOException, XmlPullParserException {
    MavenProject ret = null;//from  ww  w.  j a v  a2 s.c o  m
    MavenXpp3Reader mavenReader = new MavenXpp3Reader();

    if (pomFile != null && pomFile.exists()) {
        FileReader reader = null;

        try {
            reader = new FileReader(pomFile);
            Model model = mavenReader.read(reader);
            model.setPomFile(pomFile);

            List<Repository> repositories = model.getRepositories();
            Properties properties = model.getProperties();
            properties.setProperty("basedir", pomFile.getParent());

            Parent parent = model.getParent();
            if (parent != null) {
                File parentPom = new File(pomFile.getParent(), parent.getRelativePath());
                MavenProject parentProj = loadProject(parentPom);

                if (parentProj == null) {
                    throw new CoreException("Unable to load parent project at " + parentPom.getAbsolutePath());
                }

                repositories.addAll(parentProj.getRepositories());
                model.setRepositories(repositories);

                properties.putAll(parentProj.getProperties());
            }

            ret = new MavenProject(model);
        } finally {
            reader.close();
        }
    }

    return ret;
}

From source file:fr.synchrotron.soleil.ica.ci.lib.mongodb.pomexporter.service.POMExportServiceTest.java

@Test
@SuppressWarnings("unchecked")
public void testExport() throws IOException, URISyntaxException, SAXException {

    //TEST DATA/*from  w  w w  .  ja v a 2s  .  c  o  m*/
    StringWriter writer = new StringWriter();
    String org = "fr.synchrotron.soleil.ica.ci.lib";
    String name = "maven-versionresolver";
    String version = "1.0.0";
    String status = "RELEASE";
    File inputPomFile = new File(this.getClass().getResource("pom-1.xml").toURI());
    PomReaderService pomReaderService = new PomReaderService();
    FileReader inputPomFileReader = new FileReader(inputPomFile);
    Model inputPomFileModel = pomReaderService.getModel(inputPomFileReader);
    inputPomFileReader.close();

    pomImportService.importPomFile(inputPomFile);
    pomExportService.exportPomFile(writer, new ArtifactDocumentKey(org, name, version, status));

    final String outputPomContent = writer.toString();
    //  System.out.println(outputPomContent);
    assertNotNull(outputPomContent);
    final StringReader outputPomContentStringReader = new StringReader(outputPomContent);
    Model outputPomFileModel = pomReaderService.getModel(outputPomContentStringReader);
    outputPomContentStringReader.close();
    assertEquals(inputPomFileModel.getDescription(), outputPomFileModel.getDescription());
    //                      getModelVersion vraiment utile?
    //assertEquals(inputPomFileModel.getModelVersion(), outputPomFileModel.getModelVersion());
    assertEquals(inputPomFileModel.getGroupId(), outputPomFileModel.getGroupId());
    assertEquals(inputPomFileModel.getArtifactId(), outputPomFileModel.getArtifactId());
    assertEquals(inputPomFileModel.getVersion() + "." + status, outputPomFileModel.getVersion());
    assertEquals(inputPomFileModel.getPackaging(), outputPomFileModel.getPackaging());
    assertEquals(inputPomFileModel.getInceptionYear(), outputPomFileModel.getInceptionYear());
    assertTrue(EqualsBuilder.reflectionEquals(inputPomFileModel.getOrganization(),
            outputPomFileModel.getOrganization()));
    //TODO           assertEquals(inputPomFileModel.getParent(), outputPomFileModel.getParent());
    //TODO project classifier  ?
    List<License> licenses = inputPomFileModel.getLicenses();
    List<License> licensesOut = outputPomFileModel.getLicenses();
    assertEquals(licenses.size(), licensesOut.size());
    for (int i = 0; i < licenses.size(); i++) {
        License licenseIn = licenses.get(i);
        License licenseOut = licensesOut.get(i);
        assertTrue(EqualsBuilder.reflectionEquals(licenseIn, licenseOut));
        //            assertEquals(licenseIn.getName(), licenseOut.getName());
        //            assertEquals(licenseIn.getUrl(), licenseOut.getUrl());
        //            assertEquals(licenseIn.getComments(), licenseOut.getComments());
        //            assertEquals(licenseIn.getDistribution(), licenseOut.getDistribution());

    }

    // SCM - "scm:git:" removed by pomimporter
    assertEquals(inputPomFileModel.getScm().getConnection(),
            "scm:git:" + outputPomFileModel.getScm().getConnection());
    // dependencies
    List<Dependency> inputDependencies = inputPomFileModel.getDependencies();
    List<Dependency> outputDependencies = outputPomFileModel.getDependencies();
    assertEquals(inputDependencies.size(), outputDependencies.size());
    for (int i = 0; i < inputDependencies.size(); i++) {
        Dependency inputDependency = inputDependencies.get(i);
        Dependency outputDependency = outputDependencies.get(i);
        //      System.out.println("in: "+ToStringBuilder.reflectionToString(inputDependency));
        //    System.out.println("out: "+ToStringBuilder.reflectionToString(outputDependency));
        // exclude test version in not imported in mongodb
        assertTrue(EqualsBuilder.reflectionEquals(inputDependency, outputDependency,
                new String[] { "version", "exclusions" }));

        //     assertEquals(inputDependency.getGroupId(), outputDependency.getGroupId());
        //   assertEquals(inputDependency.getArtifactId(), outputDependency.getArtifactId());
        //  assertEquals(inputDependency.getScope(), outputDependency.getScope());
        //TODO? assertEquals(inputDependency.getSystemPath(), outputDependency.getSystemPath());
        //TODO? assertEquals(inputDependency.getType(), outputDependency.getType());
        //TODO? assertEquals(inputDependency.getClassifier(), outputDependency.getClassifier());
        // System.out.println(inputDependency.getExclusions());
        assertTrue(EqualsBuilder.reflectionEquals(inputDependency.getExclusions(),
                outputDependency.getExclusions()));
    }
    // developers info
    assertTrue(EqualsBuilder.reflectionEquals(inputPomFileModel.getDevelopers(),
            outputPomFileModel.getDevelopers()));
    //TODO contributors
    //   assertEquals(inputPomFileModel.getContributors(), outputPomFileModel.getContributors());

    assertEquals(inputPomFileModel.getModules(), outputPomFileModel.getModules());
    //TODO build?
    //TODO properties

    //TODO dependency management? transitive  exclusion can be done in dep man

}

From source file:org.semantictools.web.upload.AppspotUploadClient.java

private void loadCheckSumProperties(File baseDir) throws IOException {
    checksumProperties = new Properties();

    File file = new File(baseDir, CHECKSUM_PROPERTIES);
    if (file.exists()) {
        FileReader reader = new FileReader(file);
        try {//from w  w w. java2 s  .c o m
            checksumProperties.load(reader);
        } finally {
            reader.close();
        }
    }

}

From source file:org.apache.sysml.utils.GenerateClassesForMLContext.java

/**
 * Obtain the content of a file as a string.
 * //from w  ww.  j av  a 2s.c  o m
 * @param filePath
 *            the path to a file
 * @return the file content as a string
 */
public static String fileToString(String filePath) {
    try {
        File f = new File(filePath);
        FileReader fr = new FileReader(f);
        StringBuilder sb = new StringBuilder();
        int n;
        char[] charArray = new char[1024];
        while ((n = fr.read(charArray)) > 0) {
            sb.append(charArray, 0, n);
        }
        fr.close();
        return sb.toString();
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return null;
}

From source file:com.netflix.lipstick.Main.java

private static void configureLog4J(Properties properties, PigContext pigContext) {
    // TODO Add a file appender for the logs
    // TODO Need to create a property in the properties file for it.
    // sgroschupf, 25Feb2008: this method will be obsolete with PIG-115.

    String log4jconf = properties.getProperty(LOG4J_CONF);
    String trueString = "true";
    boolean brief = trueString.equalsIgnoreCase(properties.getProperty(BRIEF));
    Level logLevel = Level.INFO;

    String logLevelString = properties.getProperty(DEBUG);
    if (logLevelString != null) {
        logLevel = Level.toLevel(logLevelString, Level.INFO);
    }/*from w ww.  j a  va  2  s.  c  o m*/

    Properties props = new Properties();
    FileReader propertyReader = null;
    if (log4jconf != null) {
        try {
            propertyReader = new FileReader(log4jconf);
            props.load(propertyReader);
        } catch (IOException e) {
            System.err.println("Warn: Cannot open log4j properties file, use default");
        } finally {
            if (propertyReader != null)
                try {
                    propertyReader.close();
                } catch (Exception e) {
                }
        }
    }
    if (props.size() == 0) {
        props.setProperty("log4j.logger.org.apache.pig", logLevel.toString());
        if ((logLevelString = System.getProperty("pig.logfile.level")) == null) {
            props.setProperty("log4j.rootLogger", "INFO, PIGCONSOLE");
        } else {
            logLevel = Level.toLevel(logLevelString, Level.INFO);
            props.setProperty("log4j.logger.org.apache.pig", logLevel.toString());
            props.setProperty("log4j.rootLogger", "INFO, PIGCONSOLE, F");
            props.setProperty("log4j.appender.F", "org.apache.log4j.RollingFileAppender");
            props.setProperty("log4j.appender.F.File", properties.getProperty("pig.logfile"));
            props.setProperty("log4j.appender.F.layout", "org.apache.log4j.PatternLayout");
            props.setProperty("log4j.appender.F.layout.ConversionPattern",
                    brief ? "%m%n" : "%d [%t] %-5p %c - %m%n");
        }

        props.setProperty("log4j.appender.PIGCONSOLE", "org.apache.log4j.ConsoleAppender");
        props.setProperty("log4j.appender.PIGCONSOLE.target", "System.err");
        props.setProperty("log4j.appender.PIGCONSOLE.layout", "org.apache.log4j.PatternLayout");
        props.setProperty("log4j.appender.PIGCONSOLE.layout.ConversionPattern",
                brief ? "%m%n" : "%d [%t] %-5p %c - %m%n");
    }

    PropertyConfigurator.configure(props);
    logLevel = Logger.getLogger("org.apache.pig").getLevel();
    if (logLevel == null) {
        logLevel = Logger.getLogger("org.apache.pig").getEffectiveLevel();
    }
    Properties backendProps = pigContext.getLog4jProperties();
    backendProps.setProperty("log4j.logger.org.apache.pig", logLevel.toString());
    pigContext.setLog4jProperties(backendProps);
    pigContext.setDefaultLogLevel(logLevel);
}

From source file:de.viaboxx.nlstools.tasks.CopyBundlesTask.java

public void execute() {
    if (masterFile == null)
        throw new BuildException("masterFile required");
    if (dest == null)
        dest = new File(getProject().getBaseDir(), "bundles");
    try {/*  w  ww .j  a v  a  2s  .  c o  m*/
        Map<String, File> mappings = readControlFileMapping(masterFile);
        if (!zip) {
            dest.mkdirs();
            for (Map.Entry<String, File> entry : mappings.entrySet()) {
                File source = entry.getValue();

                File target = new File(dest, entry.getKey());
                FileUtils.getFileUtils().copyFile(source, target);
            }
        } else {
            if (dest.getParentFile() != null) {
                dest.getParentFile().mkdirs();
            }
            List<MBFile> files = new ArrayList();
            for (Map.Entry<String, File> entry : mappings.entrySet()) {
                File source = entry.getValue();
                MBFile file = new MBFile();
                FileReader reader = new FileReader(source);
                file.setContent(IOUtils.toString(reader));
                file.setLastModified(source.lastModified());
                file.setName(entry.getKey());
                reader.close();
                files.add(file);
            }
            FileOutputStream fout = new FileOutputStream(dest);
            MBBundlesZipper.zip(files, fout);
            fout.close();
        }
    } catch (Exception ex) {
        throw new BuildException(ex);
    }
}

From source file:org.apache.cxf.xjc.javadoc.JavadocPluginTest.java

private CompilationUnit parseSourceFile(String fileName) throws IOException, FileNotFoundException {
    FileReader inputFile = new FileReader(new File(OUTPUT_DIR + "/" + PACKAGE_DIR, fileName));
    char[] classChars = IOUtils.toCharArray(inputFile);
    inputFile.close();
    ASTParser parser = ASTParser.newParser(AST.JLS3);
    @SuppressWarnings("rawtypes")
    Map options = JavaCore.getOptions();
    JavaCore.setComplianceOptions(JavaCore.VERSION_1_5, options);
    parser.setCompilerOptions(options);// w  ww  .jav a 2  s. c  o m
    parser.setSource(classChars);
    CompilationUnit compilationUnit = (CompilationUnit) parser.createAST(null);

    return compilationUnit;
}