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.FileUtilBunch of file reading and writing utilities, so I don't have to boilerplate 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 read/write functions- readBinaryFile(State, String)- returns byte array
- writeBinaryFile(State, String, byte[])-- writes a byte array
- readTextFile(State, String)- reads a text file as a string
- readTextFileAsLines(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 SummaryNested Classes Modifier and Type Class Description static classQDLFileUtil.FileAttributes
 - 
Constructor SummaryConstructors Constructor Description QDLFileUtil()
 - 
Method SummaryAll Methods Static Methods Concrete Methods Modifier and Type Method Description static booleancanRead(State state, String path)static voidcopy(State state, String source, String target)static longcopyStream(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 booleanexists(State state, String path)static booleanisAbsolute(String path)static booleanisDirectory(State state, String path)static StringisToString(InputStream inputStream)Reads anInputStreamas a string, does not close it when done!static booleanisVFSPath(String path)static longlength(State state, String path)static voidmain(String[] args)static QDLFileUtil.FileAttributesreadAttributes(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 StringreaderToString(Reader reader)static InputStreamreadFileAsInputStream(State state, String fullPath)static QDLStemreadFileAsStem(String fileName)static StringreadTextFile(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 QDLStemreadTextFileAsStem(State state, String fullPath)main entry point for reading a text file as a stem.static StringreadTextVFS(State state, String path)static StringresolvePath(String parent, String target)Resolves paths against a parent if the target is relative.static voidwriteBinaryFile(State state, String fullPath, byte[] bytes)Main entry point for writing a binary filestatic voidwriteBinaryVFS(State state, String path, byte[] bytes)Write the set of bytes to the given VFS file.static voidwriteStemToFile(String filename, QDLStem contents)Note that this is a stem list or the output is random.static voidwriteTextFile(State state, String fullPath, String contents)static voidwriteTextFile(State state, String fullPath, List<String> contents)static voidwriteTextVFS(State state, String path, String content)
 
- 
- 
- 
Method Detail- 
isToStringpublic static String isToString(InputStream inputStream) throws IOException Reads anInputStreamas a string, does not close it when done!- Parameters:
- inputStream-
- Returns:
- Throws:
- Throwable
- IOException
 
 - 
readerToStringpublic static String readerToString(Reader reader) throws IOException - Throws:
- IOException
 
 - 
readFileAsStempublic static QDLStem readFileAsStem(String fileName) throws Throwable - Throws:
- Throwable
 
 - 
readTextFileAsLinespublic 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
 
 - 
readTextFilepublic 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
 
 - 
readTextFileAsStempublic 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
 
 - 
readBinaryFilepublic static byte[] readBinaryFile(State state, String fullPath) throws Throwable Main entry point for reading a binary file.- Parameters:
- state-
- fullPath-
- Returns:
- Throws:
- Throwable
 
 - 
writeBinaryFilepublic 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
 
 - 
writeTextFilepublic static void writeTextFile(State state, String fullPath, String contents) throws Throwable - Throws:
- Throwable
 
 - 
writeTextFilepublic static void writeTextFile(State state, String fullPath, List<String> contents) throws Throwable - Throws:
- Throwable
 
 - 
writeStemToFilepublic 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
 
 - 
writeBinaryVFSpublic 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
 
 - 
writeTextVFSpublic static void writeTextVFS(State state, String path, String content) throws Throwable - Throws:
- Throwable
 
 - 
readBinaryVFSpublic 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
 
 - 
readTextVFSpublic static String readTextVFS(State state, String path) throws Throwable - Throws:
- Throwable
 
 - 
isAbsolutepublic static boolean isAbsolute(String path) 
 - 
isVFSPathpublic static boolean isVFSPath(String path) 
 - 
resolvePathpublic static String resolvePath(String parent, String target) Resolves paths against a parent if the target is relative.- Parameters:
- parent-
- target-
- Returns:
 
 - 
isDirectorypublic static boolean isDirectory(State state, String path) throws Throwable - Throws:
- Throwable
 
 - 
dirpublic static String[] dir(State state, String path, WorkspaceCommands.RegexFileFilter regexFileFilter) throws Throwable - Throws:
- Throwable
 
 - 
readAttributespublic 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
 
 - 
readFileAsInputStreampublic static InputStream readFileAsInputStream(State state, String fullPath) throws Throwable - Throws:
- Throwable
 
 - 
copypublic static void copy(State state, String source, String target) throws Throwable - Throws:
- Throwable
 
 - 
mainpublic static void main(String[] args) 
 - 
copyStreampublic 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
 
 
- 
 
-