Package io.github.classgraph.utils
Class FileUtils
- java.lang.Object
-
- io.github.classgraph.utils.FileUtils
-
public class FileUtils extends Object
File utilities.
-
-
Field Summary
Fields Modifier and Type Field Description static StringCURR_DIR_PATHThe current directory path (only reads the current directory once, the first time this field is accessed, so will not reflect subsequent changes to the current directory).static intFILECHANNEL_FILE_SIZE_THRESHOLDThe minimum filesize at which it becomes more efficient to read a file with a memory-mapped file channel rather than an InputStream.
-
Constructor Summary
Constructors Constructor Description FileUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static InputStreambyteBufferToInputStream(ByteBuffer byteBuffer)Produce anInputStreamthat is able to read from aByteBuffer.static booleancanRead(File file)static booleanisClassfile(String path)static byte[]readAllBytesAsArray(InputStream inputStream, long fileSize, LogNode log)Read all the bytes in anInputStreamas a byte array.static StringreadAllBytesAsString(InputStream inputStream, long fileSize, LogNode log)Read all the bytes in anInputStreamas a String.
-
-
-
Field Detail
-
CURR_DIR_PATH
public static final String CURR_DIR_PATH
The current directory path (only reads the current directory once, the first time this field is accessed, so will not reflect subsequent changes to the current directory).
-
FILECHANNEL_FILE_SIZE_THRESHOLD
public static final int FILECHANNEL_FILE_SIZE_THRESHOLD
The minimum filesize at which it becomes more efficient to read a file with a memory-mapped file channel rather than an InputStream. Based on benchmark testing using the following benchmark, averaged over three separate runs, then plotted as a speedup curve for 1, 2, 4 and 8 concurrent threads: https://github.com/lukehutch/FileReadingBenchmark
-
-
Method Detail
-
readAllBytesAsArray
public static byte[] readAllBytesAsArray(InputStream inputStream, long fileSize, LogNode log) throws IOException
Read all the bytes in anInputStreamas a byte array.- Parameters:
inputStream- TheInputStream.fileSize- The file size, if known, otherwise -1L.log- The log.- Returns:
- The contents of the
InputStreamas a byte array. - Throws:
IOException- If the contents could not be read.
-
readAllBytesAsString
public static String readAllBytesAsString(InputStream inputStream, long fileSize, LogNode log) throws IOException
Read all the bytes in anInputStreamas a String.- Parameters:
inputStream- TheInputStream.fileSize- The file size, if known, otherwise -1L.log- The log.- Returns:
- The contents of the
InputStreamas a String. - Throws:
IOException- If the contents could not be read.
-
byteBufferToInputStream
public static InputStream byteBufferToInputStream(ByteBuffer byteBuffer)
Produce anInputStreamthat is able to read from aByteBuffer.- Parameters:
byteBuffer- TheByteBuffer.- Returns:
- An
InputStreamthat reads from theByteBuffer.
-
isClassfile
public static boolean isClassfile(String path)
- Parameters:
path- A file path.- Returns:
- true if path has a ".class" extension, ignoring case.
-
-