當前位置: 首頁>>代碼示例>>Java>>正文


Java FileUtils.close方法代碼示例

本文整理匯總了Java中org.apache.tools.ant.util.FileUtils.close方法的典型用法代碼示例。如果您正苦於以下問題:Java FileUtils.close方法的具體用法?Java FileUtils.close怎麽用?Java FileUtils.close使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.apache.tools.ant.util.FileUtils的用法示例。


在下文中一共展示了FileUtils.close方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getInputStream

import org.apache.tools.ant.util.FileUtils; //導入方法依賴的package包/類
/**
 * Return an InputStream for reading the contents of this Resource.
 * @return an InputStream object.
 * @throws IOException if the tar file cannot be opened,
 *         or the entry cannot be read.
 */
@Override
public InputStream getInputStream() throws IOException {
    if (isReference()) {
        return getCheckedRef().getInputStream();
    }
    Resource archive = getArchive();
    final TarInputStream i = new TarInputStream(archive.getInputStream());
    TarEntry te;
    while ((te = i.getNextEntry()) != null) {
        if (te.getName().equals(getName())) {
            return i;
        }
    }

    FileUtils.close(i);
    throw new BuildException("no entry " + getName() + " in "
                             + getArchive());
}
 
開發者ID:apache,項目名稱:ant,代碼行數:25,代碼來源:TarResource.java

示例2: createFileSet

import org.apache.tools.ant.util.FileUtils; //導入方法依賴的package包/類
private IFileSet createFileSet() throws IOException {
    final BaseContainer rootcontainer = new BaseContainer();
    final IContainer container = Files.autozip(rootcontainer);
    // We just use the Properties.load() method as a parser. As we
    // will allow duplicate keys we have to hook into the put() method.
    final Properties parser = new Properties() {
        private static final long serialVersionUID = 1L;

        @Override
        public synchronized Object put(Object key, Object value) {
            String outputpath = replaceProperties((String) key);
            String sourcepath = replaceProperties((String) value);
            addFiles(container, outputpath, sourcepath);
            return null;
        }
    };
    final InputStream in = new FileInputStream(packagefile);
    try {
        parser.load(in);
    } finally {
        FileUtils.close(in);
    }
    return rootcontainer;
}
 
開發者ID:servicecatalog,項目名稱:oscm,代碼行數:25,代碼來源:ResourcePackageTask.java

示例3: writeFiles

import org.apache.tools.ant.util.FileUtils; //導入方法依賴的package包/類
private void writeFiles(IFileSet set) throws BuildException {
    final Set<String> filenames = new HashSet<String>();
    for (final IFile f : set.getFiles()) {
        if (filenames.add(f.getLocalPath())) {
            try {
                OutputStream out = null;
                try {
                    out = new FileOutputStream(new File(outputdir,
                            f.getLocalPath()));
                    f.writeTo(out);
                } finally {
                    if (out != null)
                        FileUtils.close(out);
                }
            } catch (IOException e) {
                throw new BuildException(e);
            }
        }
    }
}
 
開發者ID:servicecatalog,項目名稱:development,代碼行數:21,代碼來源:LicensesPackageTask.java

示例4: writeFiles

import org.apache.tools.ant.util.FileUtils; //導入方法依賴的package包/類
/**
 * Writes the given set of files into the output directory.
 * 
 * @param set
 * @param outputdir
 */
public static void writeFiles(final IFileSet set, final File outputdir)
        throws IOException {
    final Set<String> filenames = new HashSet<String>();
    for (final IFile f : set.getFiles()) {
        assertNoAbsolutePath(f);
        assertNoDuplicates(filenames, f);
        final File file = new File(outputdir, f.getLocalPath());
        OutputStream out = null;
        try {
            out = new FileOutputStream(file);
            f.writeTo(out);
        } finally {
            if (out != null)
                FileUtils.close(out);
        }
    }
}
 
開發者ID:servicecatalog,項目名稱:development,代碼行數:24,代碼來源:Files.java

示例5: testPrintStreamDoesNotGetClosed

import org.apache.tools.ant.util.FileUtils; //導入方法依賴的package包/類
/**
 * test for bugzilla 48932
 */
@Test
public void testPrintStreamDoesNotGetClosed() throws IOException {
    Message ms = new Message();
    Project p = new Project();
    ms.setProject(p);
    ms.addText("hi, this is an email");
    FileOutputStream fis = null;
    try {
        fis = new FileOutputStream(f);
        ms.print(new PrintStream(fis));
        fis.write(120);
    } finally {
        FileUtils.close(fis);
    }

}
 
開發者ID:apache,項目名稱:ant,代碼行數:20,代碼來源:MessageTest.java

示例6: getProperties

import org.apache.tools.ant.util.FileUtils; //導入方法依賴的package包/類
/**
 * Returns properties from a specified properties file.
 *
 * @param resource The resource to load properties from.
 */
private Properties getProperties(Resource resource) {
    InputStream in = null;
    Properties props = new Properties();
    try {
        in = resource.getInputStream();
        props.load(in);
    } catch (IOException ioe) {
        if (getProject() != null) {
            getProject().log("getProperties failed, " + ioe.getMessage(), Project.MSG_ERR);
        } else {
            ioe.printStackTrace(); //NOSONAR
        }
    } finally {
        FileUtils.close(in);
    }

    return props;
}
 
開發者ID:apache,項目名稱:ant,代碼行數:24,代碼來源:ReplaceTokens.java

示例7: writeJavaClass

import org.apache.tools.ant.util.FileUtils; //導入方法依賴的package包/類
private void writeJavaClass() {
    try {
        File sourceFile = new File(getLocationName() + ".java");
        verbose("Write collector class to '" + sourceFile.getAbsolutePath() + "'");

        if (sourceFile.exists() && !sourceFile.delete()) {
            throw new IOException("could not delete " + sourceFile);
        }
        writer = new BufferedWriter(new FileWriter(sourceFile));

        createClassHeader();
        createSuiteMethod();
        createClassFooter();

    } catch (IOException e) {
        log(StringUtils.getStackTrace(e));
    } finally {
        FileUtils.close(writer);
    }
}
 
開發者ID:apache,項目名稱:ant,代碼行數:21,代碼來源:FailureRecorder.java

示例8: getInputStream

import org.apache.tools.ant.util.FileUtils; //導入方法依賴的package包/類
/**
 * Return an InputStream for reading the contents of this Resource.
 * @return an InputStream object.
 * @throws IOException if the zip file cannot be opened,
 *         or the entry cannot be read.
 */
public InputStream getInputStream() throws IOException {
    if (isReference()) {
        return ((Resource) getCheckedRef()).getInputStream();
    }
    final ZipFile z = new ZipFile(getZipfile(), getEncoding());
    ZipEntry ze = z.getEntry(getName());
    if (ze == null) {
        z.close();
        throw new BuildException("no entry " + getName() + " in "
                                 + getArchive());
    }
    return new FilterInputStream(z.getInputStream(ze)) {
        public void close() throws IOException {
            FileUtils.close(in);
            z.close();
        }
        protected void finalize() throws Throwable {
            try {
                close();
            } finally {
                super.finalize();
            }
        }
    };
}
 
開發者ID:apache,項目名稱:ant,代碼行數:32,代碼來源:ZipResource.java

示例9: getDefaultDefinitions

import org.apache.tools.ant.util.FileUtils; //導入方法依賴的package包/類
/**
 * Load default task or type definitions - just the names,
 *  no class loading.
 * Caches results between calls to reduce overhead.
 * @param type true for typedefs, false for taskdefs
 * @return a mapping from definition names to class names
 * @throws BuildException if there was some problem loading
 *                        or parsing the definitions list
 */
private static synchronized Properties getDefaultDefinitions(boolean type)
        throws BuildException {
    int idx = type ? 1 : 0;
    if (defaultDefinitions[idx] == null) {
        String resource = type ? MagicNames.TYPEDEFS_PROPERTIES_RESOURCE
                : MagicNames.TASKDEF_PROPERTIES_RESOURCE;
        String errorString = type ? ERROR_NO_TYPE_LIST_LOAD : ERROR_NO_TASK_LIST_LOAD;
        InputStream in = null;
        try {
            in = ComponentHelper.class.getResourceAsStream(resource);
            if (in == null) {
                throw new BuildException(errorString);
            }
            Properties p = new Properties();
            p.load(in);
            defaultDefinitions[idx] = p;
        } catch (IOException e) {
            throw new BuildException(errorString, e);
        } finally {
            FileUtils.close(in);
        }
    }
    return defaultDefinitions[idx];
}
 
開發者ID:apache,項目名稱:ant,代碼行數:34,代碼來源:ComponentHelper.java

示例10: checkResource

import org.apache.tools.ant.util.FileUtils; //導入方法依賴的package包/類
/**
 * Check if a given resource can be loaded.
 */
private boolean checkResource(String resource) {
    InputStream is = null;
    try {
        if (loader != null) {
            is = loader.getResourceAsStream(resource);
        } else {
            ClassLoader cL = this.getClass().getClassLoader();
            if (cL != null) {
                is = cL.getResourceAsStream(resource);
            } else {
                is = ClassLoader.getSystemResourceAsStream(resource);
            }
        }
        return is != null;
    } finally {
        FileUtils.close(is);
    }
}
 
開發者ID:apache,項目名稱:ant,代碼行數:22,代碼來源:Available.java

示例11: loadPropertyFiles

import org.apache.tools.ant.util.FileUtils; //導入方法依賴的package包/類
/**
 * Load the property files specified by -propertyfile
 */
private void loadPropertyFiles() {
    for (String filename : propertyFiles) {
        Properties props = new Properties();
        FileInputStream fis = null;
        try {
            fis = new FileInputStream(filename);
            props.load(fis);
        } catch (IOException e) {
            System.out.println("Could not load property file " + filename + ": " + e.getMessage());
        } finally {
            FileUtils.close(fis);
        }

        // ensure that -D properties take precedence
        Enumeration<?> properties = props.propertyNames();
        while (properties.hasMoreElements()) {
            String name = (String) properties.nextElement();
            if (easyAntConfiguration.getDefinedProps().getProperty(name) == null) {
                easyAntConfiguration.getDefinedProps().put(name, props.getProperty(name));
            }
        }
    }
}
 
開發者ID:apache,項目名稱:ant-easyant-core,代碼行數:27,代碼來源:EasyAntMain.java

示例12: findProjectReferences

import org.apache.tools.ant.util.FileUtils; //導入方法依賴的package包/類
private Set<String> findProjectReferences() {
    final Set<String> references = new HashSet<String>();
    final Pattern p = Pattern
            .compile("\\$\\{(project|result\\.package)\\.([^\\.}]*)\\.");

    Properties parser = new Properties() {
        private static final long serialVersionUID = 1L;

        @Override
        public synchronized Object put(Object key, Object value) {
            String sourcepath = getProject().replaceProperties(
                    (String) value);
            checkUnresolvedProperties(sourcepath);

            Matcher m = p.matcher((String) value);
            if (m.find()) {
                references.add(m.group(2));
            }
            return null;
        }
    };

    InputStream in = null;
    try {
        in = new FileInputStream(packagefile);
        parser.load(in);
    } catch (IOException e) {
        throw new BuildException(e);
    } finally {
        if (in != null) {
            FileUtils.close(in);
        }
    }
    return references;
}
 
開發者ID:servicecatalog,項目名稱:development,代碼行數:36,代碼來源:LicensesPackageTask.java

示例13: writeTo

import org.apache.tools.ant.util.FileUtils; //導入方法依賴的package包/類
public void writeTo(OutputStream out) throws IOException {
    FileInputStream in = null;
    try {
        in = new FileInputStream(f);
        byte[] buffer = new byte[0x1000];
        int len;
        while ((len = in.read(buffer)) != -1)
            out.write(buffer, 0, len);
    } finally {
        if (in != null)
            FileUtils.close(in);
    }
}
 
開發者ID:servicecatalog,項目名稱:development,代碼行數:14,代碼來源:Files.java

示例14: endTestSuite

import org.apache.tools.ant.util.FileUtils; //導入方法依賴的package包/類
/**
 * The whole testsuite ended.
 * @param suite the testsuite.
 * @throws BuildException on error.
 */
public void endTestSuite(final JUnitTest suite) throws BuildException {
    rootElement.setAttribute(ATTR_TESTS, "" + suite.runCount());
    rootElement.setAttribute(ATTR_FAILURES, "" + suite.failureCount());
    rootElement.setAttribute(ATTR_ERRORS, "" + suite.errorCount());
    rootElement.setAttribute(ATTR_SKIPPED, "" + suite.skipCount());
    rootElement.setAttribute(
        ATTR_TIME, "" + (suite.getRunTime() / ONE_SECOND));
    if (out != null) {
        Writer wri = null;
        try {
            wri = new BufferedWriter(new OutputStreamWriter(out, "UTF8"));
            wri.write("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n");
            (new DOMElementWriter()).write(rootElement, wri, 0, "  ");
        } catch (final IOException exc) {
            throw new BuildException("Unable to write log file", exc);
        } finally {
            if (wri != null) {
                try {
                    wri.flush();
                } catch (final IOException ex) {
                    // ignore
                }
            }
            if (out != System.out && out != System.err) {
                FileUtils.close(wri);
            }
        }
    }
}
 
開發者ID:scylladb,項目名稱:scylla-tools-java,代碼行數:35,代碼來源:CassandraXMLJUnitResultFormatter.java

示例15: endTestSuite

import org.apache.tools.ant.util.FileUtils; //導入方法依賴的package包/類
/**
 * The whole testsuite ended.
 * @param suite the testsuite.
 * @throws BuildException on error.
 */
@Override
public void endTestSuite(final JUnitTest suite) throws BuildException {
    rootElement.setAttribute(ATTR_TESTS, Long.toString(suite.runCount()));
    rootElement.setAttribute(ATTR_FAILURES, Long.toString(suite.failureCount()));
    rootElement.setAttribute(ATTR_ERRORS, Long.toString(suite.errorCount()));
    rootElement.setAttribute(ATTR_SKIPPED, Long.toString(suite.skipCount()));
    rootElement.setAttribute(
        ATTR_TIME, Double.toString(suite.getRunTime() / ONE_SECOND));
    if (out != null) {
        Writer wri = null;
        try {
            wri = new BufferedWriter(new OutputStreamWriter(out, "UTF8"));
            wri.write("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n");
            new DOMElementWriter().write(rootElement, wri, 0, "  ");
        } catch (final IOException exc) {
            throw new BuildException("Unable to write log file", exc);
        } finally {
            if (wri != null) {
                try {
                    wri.flush();
                } catch (final IOException ex) {
                    // ignore
                }
            }
            if (out != System.out && out != System.err) {
                FileUtils.close(wri);
            }
        }
    }
}
 
開發者ID:apache,項目名稱:ant,代碼行數:36,代碼來源:XMLJUnitResultFormatter.java


注:本文中的org.apache.tools.ant.util.FileUtils.close方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。