Class FileUtils

java.lang.Object
fr.paris.lutece.plugins.resource.util.FileUtils

public class FileUtils extends Object
  • Field Details

  • Constructor Details

    • FileUtils

      public FileUtils()
  • Method Details

    • createTempFile

      public static File createTempFile(String prefix, String suffix, File parentDir)

      Create a temporary file in a given directory.

      The file denoted by the returned abstract pathname did not exist before this method was invoked, any subsequent invocation of this method will yield a different file name.

      The filename is prefixNNNNNsuffix where NNNN is a random number

      This method is different to File.createTempFile(String, String, File) of JDK 1.2 as it doesn't create the file itself. It uses the location pointed to by java.io.tmpdir when the parentDir attribute is null.

      To delete automatically the file created by this method, use the File.deleteOnExit() method.

      Parameters:
      prefix - prefix before the random number
      suffix - file extension; include the '.'
      parentDir - Directory to create the temporary file in -java.io.tmpdir used if not specificed
      Returns:
      a File reference to the new temporary file.
    • copy

      public static void copy(InputStream input, Writer output, String encoding, int bufferSize) throws IOException
      Copy and convert bytes from an InputStream to chars on a Writer, using the specified encoding.
      Parameters:
      input - to convert
      output - the result
      encoding - The name of a supported character encoding. See the IANA Charset Registry for a list of valid encoding types.
      bufferSize - Size of internal buffer to use.
      Throws:
      IOException - io issue
    • copy

      public static void copy(Reader input, Writer output, int bufferSize) throws IOException
      Copy chars from a Reader to a Writer.
      Parameters:
      input - to convert
      output - the result
      bufferSize - Size of internal buffer to use.
      Throws:
      IOException - io issue
    • toString

      public static String toString(InputStream input, String encoding) throws IOException
      Parameters:
      input - to convert
      encoding - The name of a supported character encoding. See the IANA Charset Registry for a list of valid encoding types.
      Returns:
      Get the contents of an InputStream as a String.
      Throws:
      IOException - io issue
    • toString

      public static String toString(InputStream input, String encoding, int bufferSize) throws IOException
      Parameters:
      input - to convert
      encoding - The name of a supported character encoding. See the IANA Charset Registry for a list of valid encoding types.
      bufferSize - Size of internal buffer to use.
      Returns:
      Get the contents of an InputStream as a String.
      Throws:
      IOException - io issue
    • copy

      public static void copy(InputStream input, OutputStream output, int bufferSize) throws IOException
      Copy bytes from an InputStream to an OutputStream.
      Parameters:
      input - to convert
      output - the result
      bufferSize - Size of internal buffer to use.
      Throws:
      IOException - io issue
    • copy

      public static void copy(InputStream input, OutputStream output) throws IOException
      Copy bytes from an InputStream to an OutputStream.
      Parameters:
      input - to convert
      output - the result
      Throws:
      IOException - io issue
    • fileRead

      public static String fileRead(File file, String encoding) throws IOException
      Parameters:
      file - the file path
      encoding - the wanted encoding
      Returns:
      the file content using the specified encoding.
      Throws:
      IOException - if any
    • fileRead

      public static String fileRead(Path path, String encoding) throws IOException
      Throws:
      IOException
    • fileWrite

      public static void fileWrite(Path path, String encoding, String data, OpenOption... openOptions) throws IOException
      Throws:
      IOException
    • forceDelete

      public static void forceDelete(File file) throws IOException
      Delete a file. If file is directory delete it and all sub-directories.
      Parameters:
      file - a file
      Throws:
      IOException - if any
    • deleteDirectory

      public static void deleteDirectory(File directory) throws IOException
      Recursively delete a directory.
      Parameters:
      directory - a directory
      Throws:
      IOException - if any
    • cleanDirectory

      public static void cleanDirectory(File directory) throws IOException
      Clean a directory without deleting it.
      Parameters:
      directory - a directory
      Throws:
      IOException - if any
    • getBasedir

      public static String getBasedir()