Package org.gitlab4j.api.utils
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 Summary
Constructors Constructor Description FileUtils()
-
Method Summary
Modifier and Type Method Description static File
createUniqueFile(File directory, String filename)
Creates a File that is unique in the specified directory.static String
getFileContentAsString(File file, Constants.Encoding encoding)
Reads the content of a File instance and returns it as a String of either text or base64 encoded text.static String
getFilenameFromContentDisposition(javax.ws.rs.core.Response response)
Get the filename from the "Content-Disposition" header of a JAX-RS response.static String
getReaderContentAsString(Reader reader)
Reads the content of a Reader instance and returns it as a String.static String
readFileContents(File file)
Reads the contents of a File to a String.
-
Constructor Details
-
FileUtils
public FileUtils()
-
-
Method Details
-
createUniqueFile
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 infilename
- 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
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
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
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 IOExceptionReads 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 fromencoding
- 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
-