Package org.openjdk.jmh.util
Class FileUtils
- java.lang.Object
-
- org.openjdk.jmh.util.FileUtils
-
public class FileUtils extends Object
A utility class for File creation and manipulation.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static void
appendLines(File file, Collection<String> lines)
static void
copy(String src, String dst)
static String
createTempFileWithLines(String suffix, Iterable<String> lines)
Create a temporary file (seeFile.createTempFile(String, String)
) and fill it with the given lines.static File
extractFromResource(String name)
Helper method for extracting a given resource to Filestatic Collection<File>
getClasses(File root)
static void
purgeTemps()
static Collection<String>
readAllLines(File file)
static Collection<String>
readAllLines(InputStream stream)
static Collection<String>
readAllLines(Reader src)
static <T extends Flushable & Closeable>
voidsafelyClose(T obj)
static Collection<String>
tail(File file, int num)
static File
tempFile(String suffix)
Creates the temp file with given suffix.static void
touch(String f)
static TempFile
weakTempFile(String suffix)
Creates the temp file, and retains it as long as the reference to it is reachable.static void
writeLines(File file, Collection<String> lines)
-
-
-
Method Detail
-
weakTempFile
public static TempFile weakTempFile(String suffix) throws IOException
Creates the temp file, and retains it as long as the reference to it is reachable.- Parameters:
suffix
- suffix- Returns:
- temp file
- Throws:
IOException
- if things go crazy
-
purgeTemps
public static void purgeTemps()
-
tempFile
public static File tempFile(String suffix) throws IOException
Creates the temp file with given suffix. The file would be removed on JVM exit, or when caller deletes the file itself.- Parameters:
suffix
- suffix- Returns:
- temporary file
- Throws:
IOException
- if things go crazy
-
extractFromResource
public static File extractFromResource(String name) throws IOException
Helper method for extracting a given resource to File- Parameters:
name
- name of the resource- Returns:
- a File pointing to the extracted resource
- Throws:
IOException
- if things go crazy
-
createTempFileWithLines
public static String createTempFileWithLines(String suffix, Iterable<String> lines) throws IOException
Create a temporary file (seeFile.createTempFile(String, String)
) and fill it with the given lines.- Parameters:
suffix
- file suffixFile.createTempFile(String, String)
lines
- to be written- Returns:
- the temporary file absolute path
- Throws:
IOException
- on file creation error
-
tail
public static Collection<String> tail(File file, int num) throws IOException
- Throws:
IOException
-
readAllLines
public static Collection<String> readAllLines(Reader src) throws IOException
- Throws:
IOException
-
readAllLines
public static Collection<String> readAllLines(File file) throws IOException
- Throws:
IOException
-
readAllLines
public static Collection<String> readAllLines(InputStream stream) throws IOException
- Throws:
IOException
-
writeLines
public static void writeLines(File file, Collection<String> lines) throws IOException
- Throws:
IOException
-
appendLines
public static void appendLines(File file, Collection<String> lines) throws IOException
- Throws:
IOException
-
getClasses
public static Collection<File> getClasses(File root)
-
copy
public static void copy(String src, String dst) throws IOException
- Throws:
IOException
-
safelyClose
public static <T extends Closeable> void safelyClose(T obj)
-
touch
public static void touch(String f) throws IOException
- Throws:
IOException
-
-