patterntesting.runtime.io.FileHelper Maven / Gradle / Ivy
Go to download
PatternTesting Runtime (patterntesting-rt) is the runtime component for
the PatternTesting framework. It provides the annotations and base classes
for the PatternTesting testing framework (e.g. patterntesting-check,
patterntesting-concurrent or patterntesting-exception) but can be also
used standalone for classpath monitoring or profiling.
It uses AOP and AspectJ to perform this feat.
The newest version!
/**
* $Id: FileHelper.java,v 1.10 2009/12/20 15:18:10 oboehm Exp $
*
* Copyright (c) 2008 by Oliver Boehm
*
* 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 orimplied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* (c)reated 11.09.2008 by oliver ([email protected])
*/
package patterntesting.runtime.io;
import java.io.*;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.impl.LogFactoryImpl;
/**
* The Class FileHelper.
*
* @author oliver
* @since 11.09.2008
* @version $Revision: 1.10 $
*/
public class FileHelper {
private static Log log = LogFactoryImpl.getLog(FileHelper.class);
/**
* Gets the tmpdir.
*
* @return the tmpdir
*/
public static File getTmpdir() {
return new File(System.getProperty("java.io.tmpdir"));
}
/**
* Gets the tmpdir.
*
* @param file the file
*
* @return the tmpdir
*/
public static File getTmpdir(File file) {
return getTmpdir(file.toString());
}
/**
* Gets the tmpdir.
*
* @param filename the filename
*
* @return the tmpdir
*/
public static File getTmpdir(String filename) {
return new File(getTmpdir(), filename);
}
/**
* Will be removed in 1.0
*
* @param ioe the ioe
* @param file the file
*
* @return the IO exception
*
* @deprecated use IOExceptionHelper in PatternTesting Exception
*/
public static IOException betterIOException(IOException ioe, File file) {
return betterIOException(ioe, file.getAbsolutePath());
}
/**
* Gets the home dir.
*
* @return the home dir
*/
public static File getHomeDir() {
return new File(System.getProperty("user.home"));
}
/**
* The cause of the given IOException is ignored for the moment bcause
* the constructor IOException(String s, Throwable t) is not available
* in Java 5.
* Will be removed in 1.0.
*
* @param ioe the original IOException
* @param filename which caused the IOExeption
*
* @return a better IOException
*
* @deprecated use IOExceptionHelper in PatternTesting Exception
*/
public static IOException betterIOException(IOException ioe,
String filename) {
String msg = ioe.getMessage() + ": " + filename;
Throwable cause = ioe.getCause();
if (cause == null) {
return new IOException(msg);
} else {
log.warn("cause: " + cause);
return new IOException(msg);
}
}
}
/**
* $Log: FileHelper.java,v $
* Revision 1.10 2009/12/20 15:18:10 oboehm
* FindBugs and Checkstyle warnings fixed
* ready for delivery
*
* Revision 1.9 2009/12/19 22:34:09 oboehm
* trailing spaces removed
*
* Revision 1.8 2009/12/14 17:14:31 oboehm
* trailing tabs removed
*
* Revision 1.7 2009/09/25 14:49:43 oboehm
* javadocs completed with the help of JAutodoc
*
* Revision 1.6 2009/09/18 13:54:53 oboehm
* javadoc warnings fixed
*
* Revision 1.5 2009/06/10 19:56:57 oboehm
* DontLogMe annotation added to hide parameters logged by @ProfileMe
*
* Revision 1.4 2009/05/12 20:02:07 oboehm
* fixing 2787695
*
* Revision 1.3 2009/03/23 15:27:41 oboehm
* IOExceptionAspect moved to patterntesting-exception
*
* Revision 1.2 2009/02/14 22:19:51 oboehm
* javadoc comments added and updated
*
* $Source: /cvsroot/patterntesting/PatternTesting08/patterntesting-rt/src/main/java/patterntesting/runtime/io/FileHelper.java,v $
*/