Class FileUtil

java.lang.Object
com.mirth.connect.server.userutil.FileUtil

public class FileUtil extends Object
Provides file utility methods.
See Also:
  • FileUtils
  • Method Summary

    Modifier and Type
    Method
    Description
    static byte[]
    decode(String data)
    Decodes a Base64 string into octets.
    static boolean
    Deletes a specified File.
    static String
    encode(byte[] data)
    Encoded binary data into a Base64 string.
    static String
    read(String fileName)
    Returns the contents of the file as a string, using the system default charset encoding.
    static byte[]
    readBytes(String fileName)
    Returns the contents of the file as a byte array.
    static String
    rtfToPlainText(String message, String replaceLinebreaksWith)
    Converts an RTF into plain text using the Swing RTFEditorKit.
    static void
    write(String fileName, boolean append, byte[] bytes)
    Writes a byte array to a file, creating the file if it does not exist.
    static void
    write(String fileName, boolean append, String data)
    Writes a string to a specified file, creating the file if it does not exist.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • write

      public static void write(String fileName, boolean append, String data) throws IOException
      Writes a string to a specified file, creating the file if it does not exist.
      Parameters:
      fileName - The pathname string of the file to write to.
      append - If true, the data will be added to the end of the file rather than overwriting the file.
      data - The content to write to the file.
      Throws:
      IOException - If an I/O error occurred.
      See Also:
      • FileUtils.writeStringToFile(File, String)
    • decode

      public static byte[] decode(String data)
      Decodes a Base64 string into octets.
      Parameters:
      data - The Base64 string to decode.
      Returns:
      The decoded data, as a byte array.s
    • encode

      public static String encode(byte[] data)
      Encoded binary data into a Base64 string.
      Parameters:
      data - The binary data to encode (byte array).
      Returns:
      The encoded Base64 string.
    • write

      public static void write(String fileName, boolean append, byte[] bytes) throws IOException
      Writes a byte array to a file, creating the file if it does not exist.
      Parameters:
      fileName - The pathname string of the file to write to.
      append - If true, the data will be added to the end of the file rather than overwriting the file.
      bytes - The binary content to write to the file.
      Throws:
      IOException - If an I/O error occurred.
      See Also:
      • FileUtils.writeByteArrayToFile(File, byte[])
    • readBytes

      public static byte[] readBytes(String fileName) throws IOException
      Returns the contents of the file as a byte array.
      Parameters:
      fileName - The pathname string of the file to read from.
      Returns:
      The byte array representation of the file.
      Throws:
      IOException - If an I/O error occurred.
      See Also:
      • FileUtils.readFileToByteArray(File)
    • read

      public static String read(String fileName) throws IOException
      Returns the contents of the file as a string, using the system default charset encoding.
      Parameters:
      fileName - The pathname string of the file to read from.
      Returns:
      The string representation of the file.
      Throws:
      IOException - If an I/O error occurred.
      See Also:
      • FileUtils.readFileToString(File)
    • deleteFile

      public static boolean deleteFile(File file) throws SecurityException
      Deletes a specified File. In Rhino and E4X 'delete' is a keyword, so File.delete() can't be called within Mirth directly.
      Parameters:
      file - The File to delete.
      Returns:
      true if and only if the file or directory is successfully deleted; false otherwise
      Throws:
      SecurityException - If the security manager denies access to delete the file.
    • rtfToPlainText

      public static String rtfToPlainText(String message, String replaceLinebreaksWith) throws IOException, BadLocationException
      Converts an RTF into plain text using the Swing RTFEditorKit.
      Parameters:
      message - The RTF message to convert.
      replaceLinebreaksWith - If not null, any line breaks in the converted message will be replaced with this string.
      Returns:
      The converted plain text message.
      Throws:
      IOException - If an I/O error occurred.
      BadLocationException - If an invalid location within the document is used.