/*
- * 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.
*/
package org.wamblee.io;
-import junit.framework.Assert;
-import junit.framework.TestCase;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
-
import java.net.URL;
import java.net.URLDecoder;
-
import java.nio.MappedByteBuffer;
import java.nio.channels.FileChannel;
-
import java.security.CodeSource;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import junit.framework.Assert;
+import junit.framework.TestCase;
/**
* File system utilities.
* @author Erik Brakkee
*/
public final class FileSystemUtils {
- private static final Log LOG = LogFactory.getLog(FileSystemUtils.class);
+ private static final Logger LOG = Logger.getLogger(FileSystemUtils.class
+ .getName());
/**
* Test output directory relative to the sub project.
CodeSource source = aTestClass.getProtectionDomain().getCodeSource();
if (source == null) {
- LOG.warn("Could not obtain path for '" + aRelativePath +
+ LOG.warning("Could not obtain path for '" + aRelativePath +
"' for class " + aTestClass + ", using relative path as is");
return new File(aRelativePath);
String protocol = location.getProtocol();
if (!protocol.equals("file")) {
- LOG.warn("protocol is not 'file': " + location);
+ LOG.warning("protocol is not 'file': " + location);
return new File(aRelativePath);
}
path = URLDecoder.decode(location.getPath(), "UTF-8");
} catch (UnsupportedEncodingException e) {
// ignore it.. just don't decode
- LOG.warn("Decoding path failed: '" + location.getPath() + "'", e);
+ LOG.log(Level.WARNING, "Decoding path failed: '" +
+ location.getPath() + "'", e);
}
return new File(new File(path).getParentFile(), aRelativePath);
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();
/**
* Remove all regular files within a given directory.
*
- * @param outputDirName
+ * @param aDir Directory to clean.
*/
public static void cleanDir(File aDir) {
if (!aDir.exists()) {