Class Util
- java.lang.Object
-
- org.jenkinsci.plugins.periodicbackup.Util
-
public class Util extends Object
-
-
Constructor Summary
Constructors Constructor Description Util()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static File
createBackupObjectFile(BackupObject backupObject, String destinationDir, String fileNameBase)
Creates the backupObject File from given BackupObject, fileNameBase and destination pathstatic String
createFileName(String fileName, String extension)
Puts the filename and the extension togetherstatic FileFilter
extensionFileFilter(String extension)
Creates FileFilter for files with the given extensionstatic String
generateFileNameBase(Date date)
Generates unique file name (without extension)static String
getExtension(File f)
This returns extension of the given File object, returns null if the file has no extensionstatic String
getFormattedDate(String pattern, Date date)
This returns timestamp Stringstatic String
getRelativePath(File file, File baseDir)
This returns relative path of given file with respect to given base directorystatic boolean
isValidBackupObjectFile(File backupObjectFile)
This test if a given file is a valid serialized BackupObject filestatic boolean
isWritableDirectory(File directory)
static File[]
listFiles(File directory)
static File[]
listFiles(File directory, FileFilter fileFilter)
Secure version of the listFiles() logic
-
-
-
Method Detail
-
getRelativePath
public static String getRelativePath(File file, File baseDir)
This returns relative path of given file with respect to given base directory- Parameters:
file
- input filebaseDir
- base directory- Returns:
- String with relative @file path with respect to its @baseDir
-
generateFileNameBase
public static String generateFileNameBase(Date date)
Generates unique file name (without extension)- Parameters:
date
- Date object for the timestamp- Returns:
- unique filename
-
getFormattedDate
public static String getFormattedDate(String pattern, Date date)
This returns timestamp String- Parameters:
pattern
- A pattern used to format the timestampdate
- Date used as timestamp- Returns:
- timestamp String
-
createFileName
public static String createFileName(String fileName, String extension)
Puts the filename and the extension together- Parameters:
fileName
- filename without extensionextension
- extension of the file- Returns:
- filename with extension
-
createBackupObjectFile
public static File createBackupObjectFile(BackupObject backupObject, String destinationDir, String fileNameBase) throws IOException
Creates the backupObject File from given BackupObject, fileNameBase and destination path- Parameters:
backupObject
- BackupObject given to be serializeddestinationDir
- String with path to the directory where the file will be createdfileNameBase
- first part of the filename- Returns:
- serialized BackupObject File
- Throws:
IOException
- If an IO problem occurs
-
isValidBackupObjectFile
public static boolean isValidBackupObjectFile(File backupObjectFile) throws IOException
This test if a given file is a valid serialized BackupObject file- Parameters:
backupObjectFile
- File to test- Returns:
- true if valid, false otherwise
- Throws:
IOException
- If an IO problem occurs
-
extensionFileFilter
public static FileFilter extensionFileFilter(String extension)
Creates FileFilter for files with the given extension- Parameters:
extension
- file extension- Returns:
- FileFilter
-
getExtension
public static String getExtension(File f)
This returns extension of the given File object, returns null if the file has no extension- Parameters:
f
- given File- Returns:
- String with the extension of the given file
-
isWritableDirectory
public static boolean isWritableDirectory(File directory)
-
listFiles
public static File[] listFiles(@Nonnull File directory) throws org.jenkinsci.plugins.periodicbackup.PeriodicBackupException
- Throws:
org.jenkinsci.plugins.periodicbackup.PeriodicBackupException
-
listFiles
@Nonnull @Restricted(org.kohsuke.accmod.restrictions.NoExternalUse.class) public static File[] listFiles(@Nonnull File directory, @CheckForNull FileFilter fileFilter) throws org.jenkinsci.plugins.periodicbackup.PeriodicBackupException
Secure version of the listFiles() logic- Parameters:
directory
- Directory to be listedfileFilter
- Optional file filter- Returns:
- Files in the directory. If the directory does not exist, an empty list will be returned
- Throws:
org.jenkinsci.plugins.periodicbackup.PeriodicBackupException
- Whatever error
-
-