本文整理汇总了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());
}
示例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;
}
示例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;
}
示例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);
}
}
}
}
示例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);
}
}
}
示例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");
}
示例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) {
}
}
}
示例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();
}
示例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());
}
}
}
示例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);
}
}
}
示例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;
}
示例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;
}
示例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();
}
}
};
}
示例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>]]>"
+ "</ERROR>") > 0);
} finally {
if (reader != null) {
reader.close();
}
f.delete();
}
}
}
示例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);
}
}