Package org.gitlab4j.api.utils
Class FileUtils
- java.lang.Object
-
- org.gitlab4j.api.utils.FileUtils
-
public class FileUtils extends java.lang.ObjectThis class provides static utility methods used throughout GitLab4J.
-
-
Constructor Summary
Constructors Constructor Description FileUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.io.FilecreateUniqueFile(java.io.File directory, java.lang.String filename)Creates a File that is unique in the specified directory.static java.lang.StringgetFileContentAsString(java.io.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 java.lang.StringgetFilenameFromContentDisposition(jakarta.ws.rs.core.Response response)Get the filename from the "Content-Disposition" header of a JAX-RS response.static java.lang.StringgetReaderContentAsString(java.io.Reader reader)Reads the content of a Reader instance and returns it as a String.static java.lang.StringreadFileContents(java.io.File file)Reads the contents of a File to a String.
-
-
-
Method Detail
-
createUniqueFile
public static java.io.File createUniqueFile(java.io.File directory, java.lang.String filename) throws java.io.IOExceptionCreates 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:
java.io.IOException- if any error occurs during file creation
-
getFilenameFromContentDisposition
public static java.lang.String getFilenameFromContentDisposition(jakarta.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 java.lang.String readFileContents(java.io.File file) throws java.io.IOExceptionReads 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:
java.io.IOException- if any errors occur while opening or reading the file
-
getReaderContentAsString
public static java.lang.String getReaderContentAsString(java.io.Reader reader) throws java.io.IOExceptionReads 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:
java.io.IOException- if any error occurs
-
getFileContentAsString
public static java.lang.String getFileContentAsString(java.io.File file, Constants.Encoding encoding) throws java.io.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:
java.io.IOException- if any error occurs
-
-