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


Java FileUtils類代碼示例

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


FileUtils類屬於org.apache.tools.ant.util包,在下文中一共展示了FileUtils類的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: scanSuiteSources

import org.apache.tools.ant.util.FileUtils; //導入依賴的package包/類
private static Map<String,Entry> scanSuiteSources(Map<String,Object> properties, Project project) throws IOException {
    File basedir = new File((String) properties.get("basedir"));
    String suiteDir = (String) properties.get("suite.dir");
    if (suiteDir == null) {
        throw new IOException("No definition of suite.dir in " + basedir);
    }
    File suite = FileUtils.getFileUtils().resolveFile(basedir, suiteDir);
    if (!suite.isDirectory()) {
        throw new IOException("No such suite " + suite);
    }
    Map<String,Entry> entries = SUITE_SCAN_CACHE.get(suite);
    if (entries == null) {
        if (project != null) {
            project.log("Scanning for modules in suite " + suite);
        }
        entries = new HashMap<>();
        doScanSuite(entries, suite, properties, project);
        if (project != null) {
            project.log("Found modules: " + entries.keySet(), Project.MSG_VERBOSE);
        }
        SUITE_SCAN_CACHE.put(suite, entries);
    }
    return entries;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:25,代碼來源:ModuleListParser.java

示例3: 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

示例4: 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

示例5: 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

示例6: expand

import org.apache.tools.ant.util.FileUtils; //導入依賴的package包/類
/**
 * 解壓縮jar包
 *
 */
public void expand()
    throws IOException
{
    File[] fs = jarsDir.listFiles(new JarFilter());
    if (fs == null)
    {
       return; 
    }
    
    for (File f : fs)
    {
        LOG.info("start to unzip jar {}", f.getName());
        unzipJar(f.getCanonicalPath());
        FileUtils.delete(f);
    }

    LOG.info("finished to unzip jar to dir");
}
 
開發者ID:HuaweiBigData,項目名稱:StreamCQL,代碼行數:23,代碼來源:JarExpander.java

示例7: writeScript

import org.apache.tools.ant.util.FileUtils; //導入依賴的package包/類
/**
 * Writes the script lines to a temp file.
 */
protected void writeScript() throws BuildException {
	FileOutputStream os = null;
	try {
		FileUtils fileUtils = FileUtils.newFileUtils();
		// NB: use File.io.createTempFile whenever jdk 1.2 is allowed
		tmpFile = fileUtils.createTempFile("script", tmpSuffix, null);
		os = new java.io.FileOutputStream(tmpFile);
		String string = script.toString();
		os.write(string.getBytes(), 0, string.length());
		os.close();
	} catch (Exception e) {
		throw new BuildException(e);
	} finally {
		try {
			os.close();
		} catch (Throwable t) {
		}
	}
}
 
開發者ID:cniweb,項目名稱:ant-contrib,代碼行數:23,代碼來源:ShellScriptTask.java

示例8: run

import org.apache.tools.ant.util.FileUtils; //導入依賴的package包/類
private boolean run() {
    if (logFile.exists()) {
        if (! readLogFile()) {
            return false;
        }
        try {
            FileUtils.getFileUtils().copyFile(logFile.getAbsolutePath(), logFile.getAbsolutePath()+".bak");
        } catch (IOException ex) {
            System.err.println("Error creating backup of log-file.");
            System.err.println("Cowardly refusing to overwrite old file.");
            return false;
        }
    }
    
    tests.addAll(newResults.data.keySet());
    
    return writeLogFile();
}
 
開發者ID:unktomi,項目名稱:form-follows-function,代碼行數:19,代碼來源:Logger.java

示例9: addFiles

import org.apache.tools.ant.util.FileUtils; //導入依賴的package包/類
protected void addFiles(File base, String[] files, Commandline cmdl)
{
    FileUtils utils = FileUtils.getFileUtils();

    if (spec == null)
    {
        for (int i = 0; i < files.length; i++)
        {
            cmdl.createArgument().setValue(utils.resolveFile(base, files[i]).getAbsolutePath());
        }
    }
    else
    {
        for (int i = 0; i < files.length; i++)
        {
            cmdl.createArgument().setValue("-" + spec.getFullName() + equalString() +
                                           utils.resolveFile(base, files[i]).getAbsolutePath());
        }
    }
}
 
開發者ID:BowlerHatLLC,項目名稱:feathers-sdk,代碼行數:21,代碼來源:FlexFileSet.java

示例10: addFiles

import org.apache.tools.ant.util.FileUtils; //導入依賴的package包/類
protected void addFiles(File base, String[] files, Commandline cmdl)
{
    FileUtils utils = FileUtils.getFileUtils();
 
    for (int i = 0; i < files.length; ++i)
    {
        File f = utils.resolveFile(base, files[i]);
        String absolutePath = f.getAbsolutePath();

        if( f.isFile() && !absolutePath.endsWith(".swc") && !absolutePath.endsWith(".ane") )
        	continue;

        if (spec != null)
        {
            cmdl.createArgument().setValue("-" + spec.getFullName() + equalString() + absolutePath);
        }
        else
        {
            cmdl.createArgument().setValue(absolutePath);
        }
    }    
}
 
開發者ID:BowlerHatLLC,項目名稱:feathers-sdk,代碼行數:23,代碼來源:FlexSwcFileSet.java

示例11: getProcessorByService

import org.apache.tools.ant.util.FileUtils; //導入依賴的package包/類
private ArgumentProcessor getProcessorByService(InputStream is)
        throws IOException {
    InputStreamReader isr = null;
    try {
        try {
            isr = new InputStreamReader(is, "UTF-8");
        } catch (UnsupportedEncodingException e) {
            isr = new InputStreamReader(is);
        }
        BufferedReader rd = new BufferedReader(isr);
        String processorClassName = rd.readLine();
        if (processorClassName != null && !"".equals(processorClassName)) {
            return getProcessor(processorClassName);
        }
    } finally {
        FileUtils.close(isr);
    }
    return null;
}
 
開發者ID:apache,項目名稱:ant,代碼行數:20,代碼來源:ArgumentProcessorRegistry.java

示例12: relativizePaths

import org.apache.tools.ant.util.FileUtils; //導入依賴的package包/類
public static @Nullable String relativizePaths(
        @NotNull String aAbsolutePath,
        @NotNull String bAbsolutePath
) {
    String relPath;
    try {
        relPath = FileUtils.getRelativePath(new File(aAbsolutePath), new File(bAbsolutePath));
        // If the first character is not a '.' we add a ./ to indicate that
        // the file is in the same directory and not a node module
        if (relPath.charAt(0) != '.') {
            relPath = "./".concat(relPath);
        }
    } catch (Exception e) {
        return null;
    }
    return relPath;
}
 
開發者ID:jballant,項目名稱:CommonJSAutoComplete,代碼行數:18,代碼來源:StringUtil.java

示例13: 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

示例14: testBuildfile

import org.apache.tools.ant.util.FileUtils; //導入依賴的package包/類
@Test
public void testBuildfile() throws IOException {
    buildRule.configureProject(DIR + "/cdataoutput.xml");
    if (buildRule.getProject().getProperty("cdata.inner") == null) {
        // avoid endless loop
        buildRule.executeTarget("run-junit");
        File f = buildRule.getProject().resolveFile(REPORT);
        FileReader reader = null;
        try {
            reader = new FileReader(f);
            String content = FileUtils.readFully(reader);
            assertTrue(content.indexOf("</RESPONSE>&#x5d;&#x5d;&gt;"
                                       + "</ERROR>") > 0);
        } finally {
            if (reader != null) {
                reader.close();
            }
            f.delete();
        }
    }
}
 
開發者ID:apache,項目名稱:ant,代碼行數:22,代碼來源:XMLFormatterWithCDATAOnSystemOut.java

示例15: getValue

import org.apache.tools.ant.util.FileUtils; //導入依賴的package包/類
/**
 * Computes a 'hashvalue' for a file content.
 * It reads the content of a file, convert that to String and use the
 * String.hashCode() method.
 * @param file  The file for which the value should be computed
 * @return the hashvalue or <i>null</i> if the file couldn't be read
 */
 // Because the content is only read the file will not be damaged. I tested
 // with JPG, ZIP and PDF as binary files.
public String getValue(File file) {
    Reader r = null;
    try {
        if (!file.canRead()) {
            return null;
        }
        r = new FileReader(file);
        int hash = FileUtils.readFully(r).hashCode();
        return Integer.toString(hash);
    } catch (Exception e) {
        return null;
    } finally {
        FileUtils.close(r);
    }
}
 
開發者ID:apache,項目名稱:ant,代碼行數:25,代碼來源:HashvalueAlgorithm.java


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