Package org.qdl_lang.util
Class QDLFileUtil
- java.lang.Object
-
- edu.uiuc.ncsa.security.core.util.FileUtil
-
- org.qdl_lang.util.QDLFileUtil
-
public class QDLFileUtil extends edu.uiuc.ncsa.security.core.util.FileUtil
Bunch of file reading and writing utilities so I don't have to boiler plate this stuff Note that these are all VFS aware and server mode aware, so exceptions are thrown if, e.g., a read attempt is made of a native file in server mode.Always use this for file reads and writes.
Main functions
readBinaryFile(State, String)
- returns byte arraywriteBinaryFile(State, String, byte[])
-- writes a byte arrayreadTextFile(State, String)
- reads a text file as a stringreadTextFileAsLines(State, String)
- reads a text file as an array of strings.readTextFileAsStem(State, String)
- reads a text file as a stem list.writeTextFile(State, String, String)
readAttributes(State, String)
- get the attributes for a file (length, name, path...)
Created by Jeff Gaynor
on 1/29/20 at 9:52 AM
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
QDLFileUtil.FileAttributes
-
Constructor Summary
Constructors Constructor Description QDLFileUtil()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static boolean
canRead(State state, String path)
static void
copy(State state, String source, String target)
static long
copyStream(InputStream inputStream, OutputStream outputStream)
Copies one stream to another.static String[]
dir(State state, String path)
static String[]
dir(State state, String path, WorkspaceCommands.RegexFileFilter regexFileFilter)
static boolean
exists(State state, String path)
static boolean
isAbsolute(String path)
static boolean
isDirectory(State state, String path)
static String
isToString(InputStream inputStream)
Reads anInputStream
as a string, does not close it when done!static boolean
isVFSPath(String path)
static long
length(State state, String path)
static void
main(String[] args)
static QDLFileUtil.FileAttributes
readAttributes(State state, String fullPath)
Read off the file attributes (such as name, length etc.) from the given filestatic byte[]
readBinaryFile(State state, String fullPath)
Main entry point for reading a binary file.static byte[]
readBinaryVFS(State state, String path)
Read the bytes from the VFS file.static String
readerToString(Reader reader)
static InputStream
readFileAsInputStream(State state, String fullPath)
static QDLStem
readFileAsStem(String fileName)
static String
readTextFile(State state, String fullPath)
Main entry point for reading a text file as linesstatic List<String>
readTextFileAsLines(State state, String fullPath)
Main entry point for reading a text file as lines.static QDLStem
readTextFileAsStem(State state, String fullPath)
main entry point for reading a text file as a stem.static String
readTextVFS(State state, String path)
static String
resolvePath(String parent, String target)
Resolves paths against a parent if the target is relative.static void
writeBinaryFile(State state, String fullPath, byte[] bytes)
Main entry point for writing a binary filestatic void
writeBinaryVFS(State state, String path, byte[] bytes)
Write the set of bytes to the given VFS file.static void
writeStemToFile(String filename, QDLStem contents)
Note that this is a stem list or the output is random.static void
writeTextFile(State state, String fullPath, String contents)
static void
writeTextFile(State state, String fullPath, List<String> contents)
static void
writeTextVFS(State state, String path, String content)
-
-
-
Method Detail
-
isToString
public static String isToString(InputStream inputStream) throws IOException
Reads anInputStream
as a string, does not close it when done!- Parameters:
inputStream
-- Returns:
- Throws:
Throwable
IOException
-
readerToString
public static String readerToString(Reader reader) throws IOException
- Throws:
IOException
-
readFileAsStem
public static QDLStem readFileAsStem(String fileName) throws Throwable
- Throws:
Throwable
-
readTextFileAsLines
public static List<String> readTextFileAsLines(State state, String fullPath) throws Throwable
Main entry point for reading a text file as lines. This is VFS aware.- Parameters:
state
-fullPath
-- Returns:
- Throws:
Throwable
-
readTextFile
public static String readTextFile(State state, String fullPath) throws Throwable
Main entry point for reading a text file as lines- Parameters:
state
-fullPath
-- Returns:
- Throws:
Throwable
-
readTextFileAsStem
public static QDLStem readTextFileAsStem(State state, String fullPath) throws Throwable
main entry point for reading a text file as a stem.- Parameters:
state
-fullPath
-- Returns:
- Throws:
Throwable
-
readBinaryFile
public static byte[] readBinaryFile(State state, String fullPath) throws Throwable
Main entry point for reading a binary file.- Parameters:
state
-fullPath
-- Returns:
- Throws:
Throwable
-
writeBinaryFile
public static void writeBinaryFile(State state, String fullPath, byte[] bytes) throws Throwable
Main entry point for writing a binary file- Parameters:
state
-fullPath
-bytes
-- Throws:
Throwable
-
writeTextFile
public static void writeTextFile(State state, String fullPath, String contents) throws Throwable
- Throws:
Throwable
-
writeTextFile
public static void writeTextFile(State state, String fullPath, List<String> contents) throws Throwable
- Throws:
Throwable
-
writeStemToFile
public static void writeStemToFile(String filename, QDLStem contents) throws Throwable
Note that this is a stem list or the output is random.- Parameters:
filename
-- Throws:
Throwable
-
writeBinaryVFS
public static void writeBinaryVFS(State state, String path, byte[] bytes) throws Throwable
Write the set of bytes to the given VFS file. Unlike using the file_write API, this handles the bytes directly -- no base64 encoding, hence allows for dealing with things like pass through files that were written by another application and are really just blobs of bytes.- Parameters:
state
-path
-bytes
-- Throws:
Throwable
-
writeTextVFS
public static void writeTextVFS(State state, String path, String content) throws Throwable
- Throws:
Throwable
-
readBinaryVFS
public static byte[] readBinaryVFS(State state, String path) throws Throwable
Read the bytes from the VFS file. Unlike the file_read API, this just writes the bytes directly -- no base 64 encoding.- Parameters:
state
-path
-- Returns:
- Throws:
Throwable
-
readTextVFS
public static String readTextVFS(State state, String path) throws Throwable
- Throws:
Throwable
-
isAbsolute
public static boolean isAbsolute(String path)
-
isVFSPath
public static boolean isVFSPath(String path)
-
resolvePath
public static String resolvePath(String parent, String target)
Resolves paths against a parent if the target is relative.- Parameters:
parent
-target
-- Returns:
-
isDirectory
public static boolean isDirectory(State state, String path) throws Throwable
- Throws:
Throwable
-
dir
public static String[] dir(State state, String path, WorkspaceCommands.RegexFileFilter regexFileFilter) throws Throwable
- Throws:
Throwable
-
readAttributes
public static QDLFileUtil.FileAttributes readAttributes(State state, String fullPath) throws Throwable
Read off the file attributes (such as name, length etc.) from the given file- Parameters:
state
-fullPath
-- Returns:
- Throws:
Throwable
-
readFileAsInputStream
public static InputStream readFileAsInputStream(State state, String fullPath) throws Throwable
- Throws:
Throwable
-
copy
public static void copy(State state, String source, String target) throws Throwable
- Throws:
Throwable
-
main
public static void main(String[] args)
-
copyStream
public static long copyStream(InputStream inputStream, OutputStream outputStream) throws IOException
Copies one stream to another. Does not close or flush! This returns the total number of bytes copied.- Parameters:
inputStream
-outputStream
-- Returns:
- Throws:
IOException
-
-