Class Util
- Author:
- Kohsuke Kawaguchi
-
Field Summary
Modifier and TypeFieldDescriptionstatic boolean
On Unix environment that cannot run "ln", set this to true.static final org.apache.commons.lang.time.FastDateFormat
Deprecated.static boolean
static final org.apache.commons.lang.time.FastDateFormat
Deprecated.static final DateTimeFormatter
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic File
changeExtension
(File dst, String ext) Returns a file name by changing its extension.static void
closeAndLogFailures
(Closeable toClose, Logger logger, String closeableName, String closeableOwner) Closes the item and logs error to the log in the case of error.static String
Deprecated.Use individual localization methods instead.static void
Deprecated.since 2.335; useFiles.copy(Path, Path, CopyOption...)
directlystatic void
copyStream
(InputStream in, OutputStream out) Deprecated.UseIOUtils.copy(InputStream, OutputStream)
static void
copyStream
(Reader in, Writer out) Deprecated.UseIOUtils.copy(Reader, Writer)
static void
copyStreamAndClose
(InputStream in, OutputStream out) Deprecated.UseIOUtils.copy(InputStream, OutputStream)
in atry
-with-resources blockstatic void
copyStreamAndClose
(Reader in, Writer out) Deprecated.UseIOUtils.copy(Reader, Writer)
in atry
-with-resources blockstatic Path
createDirectories
(Path dir, FileAttribute<?>... attrs) Create a directory by creating all nonexistent parent directories first.static org.apache.tools.ant.types.FileSet
createFileSet
(File baseDir, String includes) static org.apache.tools.ant.types.FileSet
createFileSet
(File baseDir, String includes, String excludes) Creates AntFileSet
with the base dir and include pattern.static <T> List<T>
createSubList
(Collection<?> source, Class<T> type) Create a sub-list by only picking up instances of the specified type.static void
createSymlink
(File baseDir, String targetPath, String symlinkPath, TaskListener listener) Creates a symlink to targetPath at baseDir+symlinkPath.static File
Creates a new temporary directory.static long
daysBetween
(Date a, Date b) Compute the number of calendar days elapsed since the given date.static long
daysElapsedSince
(Date date) static void
deleteContentsRecursive
(File file) Deletes the contents of the given directory (but not the directory itself) recursively.static void
deleteContentsRecursive
(Path path, PathRemover.PathChecker pathChecker) Deletes the given directory contents (but not the directory itself) recursively using a PathChecker.static void
deleteFile
(File f) Deletes this file (and does not take no for an answer).static void
deleteRecursive
(File dir) Deletes the given directory (including its contents) recursively.static void
deleteRecursive
(Path dir, PathRemover.PathChecker pathChecker) Deletes the given directory and contents recursively using a filter.static void
displayIOException
(IOException e, TaskListener listener) On Windows, error messages for IOException aren't very helpful.static String
Escapes non-ASCII characters in URL.static String
encodeRFC2396
(String url) Deprecated.since 2008-05-13.static String
ensureEndsWith
(String subject, String suffix) Ensure string ends with suffixstatic String
Escapes HTML unsafe characters like <, & to the respective character entities.static Path
fileToPath
(File file) static <T> List<T>
Creates a filtered sublist.static <T> List<T>
Creates a filtered sublist.static String
Convert empty string to null.static String
Convert empty string to null, and trim whitespace.static <T> Iterable<T>
static String
Convert null to "".static <T> Collection<T>
fixNull
(Collection<T> l) static <T> List<T>
static <T> Set<T>
static <T> T
fixNull
(T s, T defaultValue) Convertnull
to a default value.static byte[]
fromHexString
(String data) static String
fullEncode
(String s) Encode a single path component for use in an HTTP URL.static String
getDigestOf
(File file) Computes the MD5 digest of a file.static String
getDigestOf
(InputStream source) Computes MD5 digest of the given input stream.static String
getDigestOf
(String text) static String
getFileName
(String filePath) Cuts all the leading path portion and get just the file name.static String
getHexOfSHA256DigestOf
(byte[] input) Returns Hex string of SHA-256 Digest of passed inputstatic String
Guesses the current host name.static <T> T
getNearestAncestorOfTypeOrThrow
(org.kohsuke.stapler.StaplerRequest2 request, Class<T> clazz) Find the specific ancestor, or throw an exception.static <T> T
getNearestAncestorOfTypeOrThrow
(org.kohsuke.stapler.StaplerRequest request, Class<T> clazz) Deprecated.static String
getPastTimeString
(long duration) Deprecated.Actually identical togetTimeSpanString(long)
, does not addago
.static byte[]
getSHA256DigestOf
(byte[] input) Returns SHA-256 Digest of input bytesstatic String
getTimeSpanString
(long duration) Returns a human readable text of the time duration, for example "3 minutes 40 seconds".static String
getWin32ErrorMessage
(int n) Gets a human readable message for the given Win32 error code.static String
static String
Extracts the Win32 error message fromThrowable
if possible.static <T> T
ifOverridden
(Supplier<T> supplier, Class<?> base, Class<?> derived, String methodName, Class<?>... types) Calls the given supplier if the method defined on the base type with the given arguments is overridden in the given derived type.static String
Null-safe String intern method.static boolean
isAbsoluteUri
(String uri) Deprecated.UseisSafeToRedirectTo(java.lang.String)
instead if your goal is to prevent open redirectsstatic boolean
isDescendant
(File forParent, File potentialChild) A check if a file path is a descendant of a parent pathstatic boolean
isOverridden
(Class<?> base, Class<?> derived, String methodName, Class<?>... types) Checks whether the method defined on the base type with the given arguments is overridden in the given derived type.static boolean
isRelativePath
(String path) A mostly accurate check of whether a path is a relative path or not.static boolean
isSafeToRedirectTo
(String uri) Return true iff the parameter does not denote an absolute URI and not a scheme-relative URI.static boolean
Checks if the given file represents a symlink.static boolean
static String
join
(Collection<?> strings, String separator) Deprecated.since 2.292; useString.join(CharSequence, Iterable)
static <T> List<T>
join
(Collection<? extends T>... items) Combines all the given collections into a single list.static String
Deprecated.callloadFile(java.io.File, java.nio.charset.Charset)
instead to specify the charset to use for decoding (preferablyStandardCharsets.UTF_8
).static String
Reads the entire contents of the text file atlogfile
into a string usingcharset
for decoding.static Properties
loadProperties
(String properties) Loads a key/value pair string asProperties
static String[]
Converts the map format of the environment variables to the K=V format in the array.static int
min
(int x, int... values) static Set<PosixFilePermission>
modeToPermissions
(int mode) static String
static int
permissionsToMode
(Set<PosixFilePermission> permissions) static void
printRedirect
(String contextPath, String redirectUrl, String message, PrintWriter out) static String
Encode a single path component for use in an HTTP URL.static String
static String
replaceMacro
(String s, VariableResolver<String> resolver) Replaces the occurrence of '$key' byresolver.get('key')
.static String
replaceMacro
(String s, Map<String, String> properties) Replaces the occurrence of '$key' byproperties.get('key')
.static String
resolveSymlink
(File link) Resolves symlink, if the given file is a symlink.static String
resolveSymlink
(File link, TaskListener listener) Deprecated.as of 1.456 UseresolveSymlink(File)
static File
resolveSymlinkToFile
(File link) Resolves a symlink to theFile
that points to.static String
Surrounds by a single-quote.static SecretKey
Converts a string into 128-bit AES key.static String
toHexString
(byte[] bytes) static String
toHexString
(byte[] data, int start, int len) static String[]
static String[]
Tokenizes the text separated by delimiters.static void
Creates an empty file if nonexistent or truncates the existing file.static Number
tryParseNumber
(String numberStr, Number defaultNumber) Returns the parsed string if parsed successful; otherwise returns the default number.static String
Wraps with the error icon and the CSS class to render error message.static String
-
Field Details
-
XS_DATETIME_FORMATTER
Deprecated. -
XS_DATETIME_FORMATTER2
-
RFC822_DATETIME_FORMATTER
@Deprecated public static final org.apache.commons.lang.time.FastDateFormat RFC822_DATETIME_FORMATTERDeprecated. -
NO_SYMLINK
public static boolean NO_SYMLINKOn Unix environment that cannot run "ln", set this to true. -
SYMLINK_ESCAPEHATCH
public static boolean SYMLINK_ESCAPEHATCH
-
-
Constructor Details
-
Util
public Util()
-
-
Method Details
-
filter
Creates a filtered sublist.- Since:
- 1.176
-
filter
Creates a filtered sublist. -
replaceMacro
@Nullable public static String replaceMacro(@CheckForNull String s, @NonNull Map<String, String> properties) Replaces the occurrence of '$key' byproperties.get('key')
.Unlike shell, undefined variables are left as-is (this behavior is the same as Ant.)
-
replaceMacro
@Nullable public static String replaceMacro(@CheckForNull String s, @NonNull VariableResolver<String> resolver) Replaces the occurrence of '$key' byresolver.get('key')
.Unlike shell, undefined variables are left as-is (this behavior is the same as Ant.)
-
loadFile
Deprecated.callloadFile(java.io.File, java.nio.charset.Charset)
instead to specify the charset to use for decoding (preferablyStandardCharsets.UTF_8
).Reads the entire contents of the text file atlogfile
into a string using thedefault charset
for decoding. If no such file exists, an empty string is returned.- Parameters:
logfile
- The text file to read in its entirety.- Returns:
- The entire text content of
logfile
. - Throws:
IOException
- If an error occurs while reading the file.
-
loadFile
@NonNull public static String loadFile(@NonNull File logfile, @NonNull Charset charset) throws IOException Reads the entire contents of the text file atlogfile
into a string usingcharset
for decoding. If no such file exists, an empty string is returned.- Parameters:
logfile
- The text file to read in its entirety.charset
- The charset to use for decoding the bytes inlogfile
.- Returns:
- The entire text content of
logfile
. - Throws:
IOException
- If an error occurs while reading the file.
-
deleteContentsRecursive
Deletes the contents of the given directory (but not the directory itself) recursively. It does not take no for an answer - if necessary, it will have multiple attempts at deleting things.- Throws:
IOException
- if the operation fails.
-
deleteContentsRecursive
@Restricted(org.kohsuke.accmod.restrictions.NoExternalUse.class) public static void deleteContentsRecursive(@NonNull Path path, @NonNull PathRemover.PathChecker pathChecker) throws IOException Deletes the given directory contents (but not the directory itself) recursively using a PathChecker.- Parameters:
path
- a directory to deletepathChecker
- a security check to validate a path before deleting- Throws:
IOException
- if the operation fails
-
deleteFile
Deletes this file (and does not take no for an answer). If necessary, it will have multiple attempts at deleting things.- Parameters:
f
- a file to delete- Throws:
IOException
- if it exists but could not be successfully deleted
-
deleteRecursive
Deletes the given directory (including its contents) recursively. It does not take no for an answer - if necessary, it will have multiple attempts at deleting things.- Throws:
IOException
- if the operation fails.
-
deleteRecursive
@Restricted(org.kohsuke.accmod.restrictions.NoExternalUse.class) public static void deleteRecursive(@NonNull Path dir, @NonNull PathRemover.PathChecker pathChecker) throws IOException Deletes the given directory and contents recursively using a filter.- Parameters:
dir
- a directory to deletepathChecker
- a security check to validate a path before deleting- Throws:
IOException
- if the operation fails
-
isSymlink
Checks if the given file represents a symlink. UnlikeFiles.isSymbolicLink(Path)
, this method also considers NTFS junction points as symbolic links.- Throws:
IOException
-
isSymlink
@Restricted(org.kohsuke.accmod.restrictions.NoExternalUse.class) public static boolean isSymlink(@NonNull Path path) -
isRelativePath
A mostly accurate check of whether a path is a relative path or not. This is designed to take a path against an unknown operating system so may give invalid results.- Parameters:
path
- the path.- Returns:
true
if the path looks relative.- Since:
- 1.606
-
isDescendant
A check if a file path is a descendant of a parent path- Parameters:
forParent
- the parent the child should be a descendant ofpotentialChild
- the path to check- Returns:
- true if so
- Throws:
IOException
- for invalid paths- Since:
- 2.80
- See Also:
-
createTempDir
Creates a new temporary directory.- Throws:
IOException
-
displayIOException
On Windows, error messages for IOException aren't very helpful. This method generates additional user-friendly error message to the listener -
getWin32ErrorMessage
-
getWin32ErrorMessage
Extracts the Win32 error message fromThrowable
if possible.- Returns:
- null if there seems to be no error code or if the platform is not Win32.
-
getWin32ErrorMessage
Gets a human readable message for the given Win32 error code.- Returns:
- null if no such message is available.
-
getHostName
Guesses the current host name. -
copyStream
@Deprecated public static void copyStream(@NonNull InputStream in, @NonNull OutputStream out) throws IOException Deprecated.UseIOUtils.copy(InputStream, OutputStream)
- Throws:
IOException
-
copyStream
@Deprecated public static void copyStream(@NonNull Reader in, @NonNull Writer out) throws IOException Deprecated.UseIOUtils.copy(Reader, Writer)
- Throws:
IOException
-
copyStreamAndClose
@Deprecated public static void copyStreamAndClose(@NonNull InputStream in, @NonNull OutputStream out) throws IOException Deprecated.UseIOUtils.copy(InputStream, OutputStream)
in atry
-with-resources block- Throws:
IOException
-
copyStreamAndClose
@Deprecated public static void copyStreamAndClose(@NonNull Reader in, @NonNull Writer out) throws IOException Deprecated.UseIOUtils.copy(Reader, Writer)
in atry
-with-resources block- Throws:
IOException
-
tokenize
Tokenizes the text separated by delimiters.In 1.210, this method was changed to handle quotes like Unix shell does. Before that, this method just used
StringTokenizer
.- Since:
- 1.145
- See Also:
-
tokenize
-
mapToEnv
Converts the map format of the environment variables to the K=V format in the array. -
min
public static int min(int x, @NonNull int... values) -
nullify
-
removeTrailingSlash
-
ensureEndsWith
@Nullable public static String ensureEndsWith(@CheckForNull String subject, @CheckForNull String suffix) Ensure string ends with suffix- Parameters:
subject
- Examined stringsuffix
- Desired suffix- Returns:
- Original subject in case it already ends with suffix, null in case subject was null and subject + suffix otherwise.
- Since:
- 1.505
-
getDigestOf
Computes MD5 digest of the given input stream. This method should only be used for non-security applications where the MD5 weakness is not a problem.- Parameters:
source
- The stream will be closed by this method at the end of this method.- Returns:
- 32-char wide string
- Throws:
IOException
- See Also:
-
DigestUtils.md5Hex(InputStream)
-
getDigestOf
-
getDigestOf
Computes the MD5 digest of a file.- Parameters:
file
- a file- Returns:
- a 32-character string
- Throws:
IOException
- in case reading fails- Since:
- 1.525
-
toAes128Key
Converts a string into 128-bit AES key.- Since:
- 1.308
-
toHexString
-
toHexString
-
fromHexString
-
getTimeSpanString
Returns a human readable text of the time duration, for example "3 minutes 40 seconds". This version should be used for representing a duration of some activity (like build)- Parameters:
duration
- number of milliseconds.
-
getPastTimeString
Deprecated.Actually identical togetTimeSpanString(long)
, does not addago
.Get a human readable string representing strings like "xxx days ago", which should be used to point to the occurrence of an event in the past. -
combine
Deprecated.Use individual localization methods instead. SeeMessages.Util_year(Object)
for an example. Deprecated since 2009-06-24, remove method after 2009-12-24.Combines number and unit, with a plural suffix if needed. -
createSubList
@NonNull public static <T> List<T> createSubList(@NonNull Collection<?> source, @NonNull Class<T> type) Create a sub-list by only picking up instances of the specified type. -
encode
Escapes non-ASCII characters in URL.Note that this methods only escapes non-ASCII but leaves other URL-unsafe characters, such as '#'.
rawEncode(String)
should generally be used instead, though be careful to pass only a single path component to that method (it will encode /, but this method does not). -
rawEncode
Encode a single path component for use in an HTTP URL. Escapes all non-ASCII, general unsafe (space and"#%<>[\]^`{|}~
) and HTTP special characters (/;:?
) as specified in RFC1738. (so alphanumeric and!@$&*()-_=+',.
are not encoded) Note that slash (/
) is encoded, so the given string should be a single path component used in constructing a URL. Method name inspired by PHP's rawurlencode. -
fullEncode
Encode a single path component for use in an HTTP URL. Escapes all special characters including those outside of the characters specified in RFC1738. All characters outside numbers and letters without diacritic are encoded. Note that slash (/
) is encoded, so the given string should be a single path component used in constructing a URL.- Since:
- 2.308
-
singleQuote
Surrounds by a single-quote. -
escape
Escapes HTML unsafe characters like <, & to the respective character entities. -
xmlEscape
-
touch
Creates an empty file if nonexistent or truncates the existing file. Note: The behavior of this method in the case where the file already exists is unlike the POSIXtouch
utility which merely updates the file's access and/or modification time.- Throws:
IOException
-
copyFile
@Deprecated @Restricted(org.kohsuke.accmod.restrictions.NoExternalUse.class) @RestrictedSince("2.335") public static void copyFile(@NonNull File src, @NonNull File dst) throws org.apache.tools.ant.BuildException Deprecated.since 2.335; useFiles.copy(Path, Path, CopyOption...)
directlyCopies a single file by using Ant.- Throws:
org.apache.tools.ant.BuildException
-
fixNull
Convert null to "". -
fixNull
@NonNull public static <T> T fixNull(@CheckForNull T s, @NonNull T defaultValue) Convertnull
to a default value.- Parameters:
defaultValue
- Default value. It may be immutable or not, depending on the implementation.- Since:
- 2.144
-
fixEmpty
Convert empty string to null. -
fixEmptyAndTrim
Convert empty string to null, and trim whitespace.- Since:
- 1.154
-
fixNull
- Type Parameters:
T
- Type of the list.- Parameters:
l
- list to check.- Returns:
l
if l is notnull
. An empty immutable list if l isnull
.
-
fixNull
- Type Parameters:
T
- Type of the set.- Parameters:
l
- set to check.- Returns:
l
if l is notnull
. An empty immutable set if l isnull
.
-
fixNull
- Type Parameters:
T
- Type of the collection.- Parameters:
l
- collection to check.- Returns:
l
if l is notnull
. An empty immutable set if l isnull
.
-
fixNull
- Type Parameters:
T
- Type of the iterable.- Parameters:
l
- iterable to check.- Returns:
l
if l is notnull
. An empty immutable set if l isnull
.
-
getFileName
Cuts all the leading path portion and get just the file name. -
join
@Deprecated @NonNull public static String join(@NonNull Collection<?> strings, @NonNull String separator) Deprecated.since 2.292; useString.join(CharSequence, Iterable)
Concatenate multiple strings by inserting a separator. -
join
Combines all the given collections into a single list. -
createFileSet
@NonNull public static org.apache.tools.ant.types.FileSet createFileSet(@NonNull File baseDir, @NonNull String includes, @CheckForNull String excludes) Creates AntFileSet
with the base dir and include pattern.The difference with this and using
AbstractFileSet.setIncludes(String)
is that this method doesn't treat whitespace as a pattern separator, which makes it impossible to use space in the file path.- Parameters:
includes
- String like "foo/bar/*.xml" Multiple patterns can be separated by ',', and whitespace can surround ',' (so that you can write "abc, def" and "abc,def" to mean the same thing.excludes
- Exclusion pattern. Follows the same format as the 'includes' parameter. Can be null.- Since:
- 1.172
-
createFileSet
-
createSymlink
public static void createSymlink(@NonNull File baseDir, @NonNull String targetPath, @NonNull String symlinkPath, @NonNull TaskListener listener) throws InterruptedException Creates a symlink to targetPath at baseDir+symlinkPath.If there's a prior symlink at baseDir+symlinkPath, it will be overwritten.
- Parameters:
baseDir
- Base directory to resolve the 'symlinkPath' parameter.targetPath
- The file that the symlink should point to. Usually relative to the directory of the symlink but may instead be an absolute path.symlinkPath
- Where to create a symlink in (relative tobaseDir
)- Throws:
InterruptedException
-
resolveSymlink
@Deprecated public static String resolveSymlink(File link, TaskListener listener) throws InterruptedException, IOException Deprecated.as of 1.456 UseresolveSymlink(File)
- Throws:
InterruptedException
IOException
-
resolveSymlinkToFile
@CheckForNull public static File resolveSymlinkToFile(@NonNull File link) throws InterruptedException, IOException Resolves a symlink to theFile
that points to.- Returns:
- null if the specified file is not a symlink.
- Throws:
InterruptedException
IOException
-
resolveSymlink
Resolves symlink, if the given file is a symlink. Otherwise return null.If the resolution fails, report an error.
- Returns:
- null if the given file is not a symlink. If the symlink is absolute, the returned string is an absolute path. If the symlink is relative, the returned string is that relative representation. The relative path is meant to be resolved from the location of the symlink.
- Throws:
IOException
-
encodeRFC2396
Deprecated.since 2008-05-13. This method is broken (see JENKINS-1666). It should probably be removed but I'm not sure if it is considered part of the public API that needs to be maintained for backwards compatibility. Useencode(String)
instead.Encodes the URL by RFC 2396. I thought there's another spec that refers to UTF-8 as the encoding, but don't remember it right now.- Since:
- 1.204
-
wrapToErrorSpan
Wraps with the error icon and the CSS class to render error message.- Since:
- 1.173
-
tryParseNumber
@CheckForNull public static Number tryParseNumber(@CheckForNull String numberStr, @CheckForNull Number defaultNumber) Returns the parsed string if parsed successful; otherwise returns the default number. If the string is null, empty or a ParseException is thrown then the defaultNumber is returned.- Parameters:
numberStr
- string to parsedefaultNumber
- number to return if the string can not be parsed- Returns:
- returns the parsed string; otherwise the default number
-
isOverridden
public static boolean isOverridden(@NonNull Class<?> base, @NonNull Class<?> derived, @NonNull String methodName, @NonNull Class<?>... types) Checks whether the method defined on the base type with the given arguments is overridden in the given derived type.- Parameters:
base
- The base type.derived
- The derived type.methodName
- The name of the method.types
- The types of the arguments for the method.- Returns:
true
whenderived
provides the specified method other than as inherited frombase
.- Throws:
IllegalArgumentException
- Whenderived
does not derive frombase
, or whenbase
does not contain the specified method.
-
ifOverridden
public static <T> T ifOverridden(Supplier<T> supplier, @NonNull Class<?> base, @NonNull Class<?> derived, @NonNull String methodName, @NonNull Class<?>... types) Calls the given supplier if the method defined on the base type with the given arguments is overridden in the given derived type.- Parameters:
supplier
- The supplier to call if the method is indeed overridden.base
- The base type.derived
- The derived type.methodName
- The name of the method.types
- The types of the arguments for the method.- Returns:
true
whenderived
provides the specified method other than as inherited frombase
.- Throws:
IllegalArgumentException
- Whenderived
does not derive frombase
, or whenbase
does not contain the specified method.AbstractMethodError
- If the derived class doesn't override the given method.- Since:
- 2.259
-
changeExtension
Returns a file name by changing its extension.- Parameters:
ext
- For example, ".zip"
-
intern
Null-safe String intern method.- Returns:
- A canonical representation for the string object. Null for null input strings
-
isAbsoluteUri
@Deprecated @RestrictedSince("1.651.2 / 2.3") @Restricted(org.kohsuke.accmod.restrictions.NoExternalUse.class) public static boolean isAbsoluteUri(@NonNull String uri) Deprecated.UseisSafeToRedirectTo(java.lang.String)
instead if your goal is to prevent open redirectsReturn true if the systemId denotes an absolute URI . The same algorithm can be seen inURI
, but implementing this by ourselves allow it to be more lenient about escaping of URI. -
isSafeToRedirectTo
Return true iff the parameter does not denote an absolute URI and not a scheme-relative URI.- Since:
- 2.3 / 1.651.2
-
loadProperties
Loads a key/value pair string asProperties
- Throws:
IOException
- Since:
- 1.392
-
closeAndLogFailures
@Restricted(org.kohsuke.accmod.restrictions.NoExternalUse.class) public static void closeAndLogFailures(@CheckForNull Closeable toClose, @NonNull Logger logger, @NonNull String closeableName, @NonNull String closeableOwner) Closes the item and logs error to the log in the case of error. Logging will be performed on theWARNING
level.- Parameters:
toClose
- Item to close. Nothing will happen if it isnull
logger
- Logger, which receives the errorcloseableName
- Name of the closeable itemcloseableOwner
- String representation of the closeable holder- Since:
- 2.19, but TODO update once un-restricted
-
permissionsToMode
@Restricted(org.kohsuke.accmod.restrictions.NoExternalUse.class) public static int permissionsToMode(Set<PosixFilePermission> permissions) -
modeToPermissions
@Restricted(org.kohsuke.accmod.restrictions.NoExternalUse.class) public static Set<PosixFilePermission> modeToPermissions(int mode) throws IOException - Throws:
IOException
-
fileToPath
@Restricted(org.kohsuke.accmod.restrictions.NoExternalUse.class) @NonNull public static Path fileToPath(@NonNull File file) throws IOException - Throws:
IOException
- iff.toPath()
throwsInvalidPathException
.
-
createDirectories
@Restricted(org.kohsuke.accmod.restrictions.NoExternalUse.class) public static Path createDirectories(@NonNull Path dir, FileAttribute<?>... attrs) throws IOException Create a directory by creating all nonexistent parent directories first.Unlike
Files.createDirectory(java.nio.file.Path, java.nio.file.attribute.FileAttribute<?>...)
, an exception is not thrown if the directory could not be created because it already exists. UnlikeFiles.createDirectories(java.nio.file.Path, java.nio.file.attribute.FileAttribute<?>...)
, an exception is not thrown if the directory (or one of its parents) is a symbolic link.The
attrs
parameter contains optionalfile attributes
to set atomically when creating the nonexistent directories. Each file attribute is identified by itsFileAttribute.name()
. If more than one attribute of the same name is included in the array, then all but the last occurrence is ignored.If this method fails, then it may do so after creating some, but not all, of the parent directories.
- Parameters:
dir
- The directory to create.attrs
- An optional list of file attributes to set atomically when creating the directory.- Returns:
- The directory.
- Throws:
UnsupportedOperationException
- If the array contains an attribute that cannot be set atomically when creating the directory.FileAlreadyExistsException
- Ifdir
exists but is not a directory.IOException
- If an I/O error occurs.- See Also:
-
daysBetween
@Restricted(org.kohsuke.accmod.restrictions.NoExternalUse.class) public static long daysBetween(@NonNull Date a, @NonNull Date b) Compute the number of calendar days elapsed since the given date. As it's only the calendar days difference that matter, "11.00pm" to "2.00am the day after" returns 1, even if there are only 3 hours between. As well as "10am" to "2pm" both on the same day, returns 0. -
daysElapsedSince
@Restricted(org.kohsuke.accmod.restrictions.NoExternalUse.class) public static long daysElapsedSince(@NonNull Date date) - Returns:
- positive number of days between the given date and now
- See Also:
-
getNearestAncestorOfTypeOrThrow
@Restricted(org.kohsuke.accmod.restrictions.NoExternalUse.class) @NonNull public static <T> T getNearestAncestorOfTypeOrThrow(@NonNull org.kohsuke.stapler.StaplerRequest2 request, @NonNull Class<T> clazz) Find the specific ancestor, or throw an exception. Useful for an ancestor we know is inside the URL to ease readability- Since:
- 2.475
-
getNearestAncestorOfTypeOrThrow
@Deprecated @Restricted(org.kohsuke.accmod.restrictions.NoExternalUse.class) @NonNull public static <T> T getNearestAncestorOfTypeOrThrow(@NonNull org.kohsuke.stapler.StaplerRequest request, @NonNull Class<T> clazz) Deprecated. -
printRedirect
@Restricted(org.kohsuke.accmod.restrictions.NoExternalUse.class) public static void printRedirect(String contextPath, String redirectUrl, String message, PrintWriter out) -
getSHA256DigestOf
@Restricted(org.kohsuke.accmod.restrictions.NoExternalUse.class) public static byte[] getSHA256DigestOf(@NonNull byte[] input) Returns SHA-256 Digest of input bytes -
getHexOfSHA256DigestOf
@Restricted(org.kohsuke.accmod.restrictions.NoExternalUse.class) public static String getHexOfSHA256DigestOf(byte[] input) throws IOException Returns Hex string of SHA-256 Digest of passed input- Throws:
IOException
-
DateTimeFormatter.RFC_1123_DATE_TIME