Class FileUtils

java.lang.Object
org.gitlab4j.api.utils.FileUtils

public class FileUtils
extends Object
This class provides static utility methods used throughout GitLab4J.
  • Constructor Details

    • FileUtils

      public FileUtils()
  • Method Details

    • createUniqueFile

      public static File createUniqueFile​(File directory, String filename) throws IOException
      Creates a File that is unique in the specified directory. If the specified filename exists in the directory, "-#" will be appended to the filename until a unique filename can be created.
      Parameters:
      directory - the directory to create the file in
      filename - the base filename with extension
      Returns:
      a File that is unique in the specified directory
      Throws:
      IOException - if any error occurs during file creation
    • getFilenameFromContentDisposition

      public static String getFilenameFromContentDisposition​(javax.ws.rs.core.Response response)
      Get the filename from the "Content-Disposition" header of a JAX-RS response.
      Parameters:
      response - the JAX-RS Response instance to get the "Content-Disposition" header filename from
      Returns:
      the filename from the "Content-Disposition" header of a JAX-RS response, or null if the "Content-Disposition" header is not present in the response
    • readFileContents

      public static String readFileContents​(File file) throws IOException
      Reads the contents of a File to a String.
      Parameters:
      file - the File instance to read the contents from
      Returns:
      the contents of file as a String
      Throws:
      IOException - if any errors occur while opening or reading the file
    • getReaderContentAsString

      public static String getReaderContentAsString​(Reader reader) throws IOException
      Reads the content of a Reader instance and returns it as a String.
      Parameters:
      reader - the Reader instance to read the content from
      Returns:
      the content of a Reader instance as a String
      Throws:
      IOException - if any error occurs
    • getFileContentAsString

      public static String getFileContentAsString​(File file, Constants.Encoding encoding) throws IOException
      Reads the content of a File instance and returns it as a String of either text or base64 encoded text.
      Parameters:
      file - the File instance to read from
      encoding - whether to encode as Base64 or as Text, defaults to Text if null
      Returns:
      the content of the File as a String
      Throws:
      IOException - if any error occurs