Package org.openjdk.jmh.util
Class FileUtils
- java.lang.Object
-
- org.openjdk.jmh.util.FileUtils
-
public class FileUtils extends java.lang.Object
A utility class for File creation and manipulation.
-
-
Field Summary
Fields Modifier and Type Field Description (package private) static TempFileManager
TEMP_FILE_MANAGER
-
Constructor Summary
Constructors Modifier Constructor Description private
FileUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static void
appendLines(java.io.File file, java.util.Collection<java.lang.String> lines)
static void
copy(java.lang.String src, java.lang.String dst)
static java.lang.String
createTempFileWithLines(java.lang.String suffix, java.lang.Iterable<java.lang.String> lines)
Create a temporary file (seeFile.createTempFile(String, String)
) and fill it with the given lines.static java.io.File
extractFromResource(java.lang.String name)
Helper method for extracting a given resource to Filestatic java.util.Collection<java.io.File>
getClasses(java.io.File root)
static void
purgeTemps()
static java.util.Collection<java.lang.String>
readAllLines(java.io.File file)
static java.util.Collection<java.lang.String>
readAllLines(java.io.InputStream stream)
static java.util.Collection<java.lang.String>
readAllLines(java.io.Reader src)
static <T extends java.io.Flushable & java.io.Closeable>
voidsafelyClose(T obj)
static java.util.Collection<java.lang.String>
tail(java.io.File file, int num)
static java.io.File
tempFile(java.lang.String suffix)
Creates the temp file with given suffix.static void
touch(java.lang.String f)
static TempFile
weakTempFile(java.lang.String suffix)
Creates the temp file, and retains it as long as the reference to it is reachable.static void
writeLines(java.io.File file, java.util.Collection<java.lang.String> lines)
-
-
-
Field Detail
-
TEMP_FILE_MANAGER
static final TempFileManager TEMP_FILE_MANAGER
-
-
Method Detail
-
weakTempFile
public static TempFile weakTempFile(java.lang.String suffix) throws java.io.IOException
Creates the temp file, and retains it as long as the reference to it is reachable.- Parameters:
suffix
- suffix- Returns:
- temp file
- Throws:
java.io.IOException
- if things go crazy
-
purgeTemps
public static void purgeTemps()
-
tempFile
public static java.io.File tempFile(java.lang.String suffix) throws java.io.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:
java.io.IOException
- if things go crazy
-
extractFromResource
public static java.io.File extractFromResource(java.lang.String name) throws java.io.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:
java.io.IOException
- if things go crazy
-
createTempFileWithLines
public static java.lang.String createTempFileWithLines(java.lang.String suffix, java.lang.Iterable<java.lang.String> lines) throws java.io.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:
java.io.IOException
- on file creation error
-
tail
public static java.util.Collection<java.lang.String> tail(java.io.File file, int num) throws java.io.IOException
- Throws:
java.io.IOException
-
readAllLines
public static java.util.Collection<java.lang.String> readAllLines(java.io.Reader src) throws java.io.IOException
- Throws:
java.io.IOException
-
readAllLines
public static java.util.Collection<java.lang.String> readAllLines(java.io.File file) throws java.io.IOException
- Throws:
java.io.IOException
-
readAllLines
public static java.util.Collection<java.lang.String> readAllLines(java.io.InputStream stream) throws java.io.IOException
- Throws:
java.io.IOException
-
writeLines
public static void writeLines(java.io.File file, java.util.Collection<java.lang.String> lines) throws java.io.IOException
- Throws:
java.io.IOException
-
appendLines
public static void appendLines(java.io.File file, java.util.Collection<java.lang.String> lines) throws java.io.IOException
- Throws:
java.io.IOException
-
getClasses
public static java.util.Collection<java.io.File> getClasses(java.io.File root)
-
copy
public static void copy(java.lang.String src, java.lang.String dst) throws java.io.IOException
- Throws:
java.io.IOException
-
safelyClose
public static <T extends java.io.Flushable & java.io.Closeable> void safelyClose(T obj)
-
safelyClose
public static <T extends java.io.Closeable> void safelyClose(T obj)
-
touch
public static void touch(java.lang.String f) throws java.io.IOException
- Throws:
java.io.IOException
-
-