Class IOUtils
java.lang.Object
com.mcpdbwizard.pub.IOUtils
A set of useful static methods for working with files.
Copyright 2003-2026 ATB Consultancy Services Ltd (formerly Orinda Software Ltd, Dublin, Ireland)
- Version:
- 7
- Author:
- devteam@mcpdbwizard.com
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringDefault prefix for temporary files holding downloaded LONG/LOB/BFILE data, used when no application-specific prefix has been configured.static final StringDefault suffix for temporary files holding downloaded LONG/LOB/BFILE data, used when no application-specific suffix has been configured.static final intDefault block size for IO operations -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic FileconfirmDirectory(String directoryName) Make sure directorydirectoryNameexists.static voidCopies a file.static FileReturn the OS-specific temporary directory File.static StringgetStringFromConsole(String theMessage, boolean noNewline) Get the user to enter a Stringstatic booleanAn extremely crude implemtation of 'grep'static FileloadByteArrayIntoFile(byte[] theBytes, File newFile, LogInterface theLog) Turn a byte array into a File.static FileloadByteArrayIntoFile(byte[] theBytes, String tempFilePrefix, String tempFileSuffix, String tempFileDir, LogInterface theLog) Turn a byte array into a Temporary File.static FileloadCharArrayIntoFile(char[] theChars, File newFile, LogInterface theLog) Turn a char array into a File.static FileloadCharArrayIntoFile(char[] theChars, String tempFilePrefix, String tempFileSuffix, String tempFileDir, LogInterface theLog) Turn a char array into a Temporary File.static byte[]loadFileIntoByteArray(File inFile) Loads a file into a byte array.static char[]loadFileIntoCharArray(File inFile) Loads a file into a char array.static StringloadFileIntoString(File inFile) Loads a file into a String.static FileloadStringIntoFile(String theString, File newFile, LogInterface theLog) Turn a String into a File.static FileloadStringIntoFile(String theString, String tempFilePrefix, String tempFileSuffix, String tempFileDir, LogInterface theLog) Turn a String into a File.
-
Field Details
-
IO_BUFFER_SIZE
public static final int IO_BUFFER_SIZEDefault block size for IO operations- See Also:
-
DEFAULT_TEMP_FILE_PREFIX
Default prefix for temporary files holding downloaded LONG/LOB/BFILE data, used when no application-specific prefix has been configured.- See Also:
-
DEFAULT_TEMP_FILE_SUFFIX
Default suffix for temporary files holding downloaded LONG/LOB/BFILE data, used when no application-specific suffix has been configured.- See Also:
-
-
Constructor Details
-
IOUtils
public IOUtils()IOUtils is a set of static methods for working with files.
-
-
Method Details
-
confirmDirectory
Make sure directorydirectoryNameexists.- Parameters:
directoryName-- Returns:
- A file object contaning the directory in question.
- Throws:
CSIOException- if the file isn't a writable, readable, directory.
-
getStringFromConsole
Get the user to enter a String- Parameters:
theMessage- A message to be sent to Standard OutputnoNewline- Whether a newline character is printed aftertheMessage.- Returns:
- String whatever the user typed prior to presssing 'Enter'.
-
getOsTempDir
Return the OS-specific temporary directory File.Uses the JVM's
java.io.tmpdirproperty, which is the canonical OS temp directory on every platform (e.g./tmpon Linux,/var/folders/...on macOS,%TEMP%on Windows) and is always guaranteed to exist. This is preferred over the current working directory so that downloaded LONG/LOB/BFILE temp files do not litter the directory the application happens to be launched from. -
copyFile
Copies a file.- Parameters:
oldFile- the file you want copiednewFile- the file you want it copied to- Throws:
CSException
-
loadFileIntoByteArray
Loads a file into a byte array. Note that this will not work with really big files. Non-existant or zero length files are returned as a zero length array. This routine has been tested with files up to 1MB in size.- Parameters:
inFile- the file you want copied- Returns:
- byte[] a byte array
- Throws:
CSException- Since:
- 4.0.2108
-
grep
-
loadFileIntoString
Loads a file into a String. Note that this will not work with really big files. Non-existant or zero length files are returned as a zero length String.This routine has been tested with files up to 1MB in size.- Parameters:
inFile- the file you want turned into a String- Returns:
- String a String
- Throws:
CSException- Since:
- 4.0.2108
-
loadStringIntoFile
public static File loadStringIntoFile(String theString, String tempFilePrefix, String tempFileSuffix, String tempFileDir, LogInterface theLog) throws CSException Turn a String into a File. A null String will be turned into a zero length file.- Parameters:
theString-tempFilePrefix-tempFileSuffix-tempFileDir-theLog-- Throws:
CSException- Since:
- 4.0.2098
-
loadStringIntoFile
public static File loadStringIntoFile(String theString, File newFile, LogInterface theLog) throws CSException Turn a String into a File. A null String will be turned into a zero length file.- Parameters:
theString-newFile-- Throws:
CSException- Since:
- 6.0.2746
-
loadCharArrayIntoFile
public static File loadCharArrayIntoFile(char[] theChars, String tempFilePrefix, String tempFileSuffix, String tempFileDir, LogInterface theLog) throws CSException Turn a char array into a Temporary File. A null value fortheCharswill be turned into a zero length file. java.io.File.createTempFile() is used to create what is supposed to be a unique file.- Parameters:
theChars- The chars you wish to be turned into a temporary FiletempFilePrefix- The prefix for the temporary file's nametempFileSuffix- The suffix for the temporary file's nametempFileDir- The directory for the temporary files.theLog- A logging mechanism.- Throws:
CSException- Since:
- 4.0.2098
-
loadCharArrayIntoFile
public static File loadCharArrayIntoFile(char[] theChars, File newFile, LogInterface theLog) throws CSException Turn a char array into a File. A null Array will be turned into a zero length file.- Parameters:
theChars-newFile-theLog-- Throws:
CSException- Since:
- 4.0.2108
-
loadByteArrayIntoFile
public static File loadByteArrayIntoFile(byte[] theBytes, String tempFilePrefix, String tempFileSuffix, String tempFileDir, LogInterface theLog) throws CSException Turn a byte array into a Temporary File. A null value fortheByteswill be turned into a zero length file. java.io.File.createTempFile() is used to create what is supposed to be a unique file.- Parameters:
theBytes- The bytes you wish to be turned into a temporary FiletempFilePrefix- The prefix for the temporary file's nametempFileSuffix- The suffix for the temporary file's nametempFileDir- The directory for the temporary files.theLog- A logging mechanism.- Throws:
CSException- Since:
- 4.0.2098
-
loadByteArrayIntoFile
public static File loadByteArrayIntoFile(byte[] theBytes, File newFile, LogInterface theLog) throws CSException Turn a byte array into a File. A null Array will be turned into a zero length file.- Parameters:
theBytes-newFile-theLog-- Throws:
CSException- Since:
- 4.0.2108
-
loadFileIntoCharArray
Loads a file into a char array. Note that this will not work with really big files. Non-existant or zero length files are returned as a zero length array. This routine has been tested with files up to 1MB in size.- Parameters:
inFile- the file you want copied- Returns:
- char[] a char array
- Throws:
CSException- Since:
- 4.0.2108
-