Class IOUtils

java.lang.Object
com.mcpdbwizard.pub.IOUtils

public class IOUtils extends Object
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 Details

    • IO_BUFFER_SIZE

      public static final int IO_BUFFER_SIZE
      Default block size for IO operations
      See Also:
    • DEFAULT_TEMP_FILE_PREFIX

      public static final String 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

      public static final String 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

      public static File confirmDirectory(String directoryName) throws CSIOException
      Make sure directory directoryName exists.
      Parameters:
      directoryName -
      Returns:
      A file object contaning the directory in question.
      Throws:
      CSIOException - if the file isn't a writable, readable, directory.
    • getStringFromConsole

      public static String getStringFromConsole(String theMessage, boolean noNewline)
      Get the user to enter a String
      Parameters:
      theMessage - A message to be sent to Standard Output
      noNewline - Whether a newline character is printed after theMessage.
      Returns:
      String whatever the user typed prior to presssing 'Enter'.
    • getOsTempDir

      public static File getOsTempDir()
      Return the OS-specific temporary directory File.

      Uses the JVM's java.io.tmpdir property, which is the canonical OS temp directory on every platform (e.g. /tmp on 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

      public static void copyFile(File oldFile, File newFile) throws CSException
      Copies a file.
      Parameters:
      oldFile - the file you want copied
      newFile - the file you want it copied to
      Throws:
      CSException
    • loadFileIntoByteArray

      public static byte[] loadFileIntoByteArray(File inFile) throws CSException
      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

      public static boolean grep(String searchString, File searchFile)
      An extremely crude implemtation of 'grep'
    • loadFileIntoString

      public static String loadFileIntoString(File inFile) throws CSException
      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 for theChars will 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 File
      tempFilePrefix - The prefix for the temporary file's name
      tempFileSuffix - The suffix for the temporary file's name
      tempFileDir - 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 for theBytes will 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 File
      tempFilePrefix - The prefix for the temporary file's name
      tempFileSuffix - The suffix for the temporary file's name
      tempFileDir - 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

      public static char[] loadFileIntoCharArray(File inFile) throws CSException
      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