/*
- * Copyright 2006 the original author or authors.
- *
+ * Copyright 2005-2010 the original author or authors.
+ *
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- */
+ */
package org.wamblee.io;
import junit.framework.Assert;
import java.security.CodeSource;
-
/**
* File system utilities.
- *
+ *
* @author Erik Brakkee
*/
public final class FileSystemUtils {
/*
* Disabled.
- *
*/
private FileSystemUtils() {
// Empty
/**
* Deletes a directory recursively. The test case will fail if the directory
* does not exist or if deletion fails.
- *
+ *
* @param aDir
* Directory to delete.
*/
/**
* Deletes a directory recursively. See {@link #deleteDirRecursively}.
- *
+ *
* @param aDir
* Directory.
*/
* Deletes a file or directory. The test case will fail if the file or
* directory does not exist or if deletion fails. Deletion of a non-empty
* directory will always fail.
- *
+ *
* @param aFile
* File or directory to delete.
*/
* Gets a path relative to a sub project. This utility should be used to
* easily access file paths within a subproject without requiring any
* specific Eclipse configuration.
- *
+ *
* @param aRelativePath
* Relative path.
* @param aTestClass
/**
* Ensures that a directory hierarchy exists (recursively if needed). If it
* is not possible to create the directory, then the test case will fail.
- *
+ *
* @param aDir
* Directory to create.
*/
/**
* Creates a file in a directory.
- * @param aDir Directory path. Will be created if it does not exist.
- * @param aName Filename.
- * @param aContents Contents.
+ *
+ * @param aDir
+ * Directory path. Will be created if it does not exist.
+ * @param aName
+ * Filename.
+ * @param aContents
+ * Contents.
*/
public static void createFile(File aDir, String aName, InputStream aContents) {
createDir(aDir);
/**
* Gets the test output directory for a specific test class.
- *
+ *
* @param aTestClass
* Test class.
* @return Test output directory.
/**
* Gets the test input directory for a specific test class.
- *
+ *
* @param aTestClass
* Test class.
* @return Test input directory.
/**
* Creates a directory hierarchy for the output directory of a test class if
* needed.
- *
+ *
* @param aTestClass
* Test class
* @return Test directory.
* Gets a test output file name. This returns a File object representing the
* output file and ensures that the directory where the file will be created
* already exists.
- *
+ *
* @param aName
* Name of the file.
* @param aTestClass
/**
* Copies an input stream to an output stream.
- *
+ *
* @param aIs
* Input stream.
* @param aOs
/**
* Recursively copy a directory.
- *
+ *
* @param aSrc
* Source directory
* @param aTarget
Assert.assertTrue(aSrc.isDirectory());
Assert.assertTrue(!aTarget.exists());
- aTarget.mkdirs();
+ if (!aTarget.mkdirs()) {
+ Assert.fail("Could not create target directory '" + aTarget + "'");
+ }
File[] files = aSrc.listFiles();
if (file.isDirectory()) {
if (!file.getName().equals(".svn")) {
- copyDir(new File(aSrc, file.getName()),
- new File(aTarget, file.getName()));
+ copyDir(new File(aSrc, file.getName()), new File(aTarget,
+ file.getName()));
}
} else {
copyFile(file, new File(aTarget, file.getName()));
/**
* Copy a file. If copying fails then the testcase will fail.
- *
+ *
* @param aSrc
* Source file.
* @param aTarget
// map input file
MappedByteBuffer mbb = fcin.map(FileChannel.MapMode.READ_ONLY, 0,
- fcin.size());
+ fcin.size());
// do the file copy
fcout.write(mbb);
* This only attempts to remove regular files and not directories within the
* directory. If the directory contains a nested directory, the deletion
* will fail. The test case will fail if this fails.
- *
+ *
* @param aDir
* Directory to remove.
*/
/**
* Remove all regular files within a given directory.
- *
+ *
* @param outputDirName
*/
public static void cleanDir(File aDir) {