|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.aragost.javahg.internals.Utils
public class Utils
Miscellaneous utils methods for JavaHg.
Constructor Summary | |
---|---|
Utils()
|
Method Summary | ||
---|---|---|
static
|
arrayConcat(T[] a,
T[] b)
Concatenate two arrays. |
|
static
|
arrayUnshift(T first,
T[] rest)
Insert an element as the first to an array. |
|
static RuntimeException |
asRuntime(Throwable e)
Convert the specified exception into a RuntimeException |
|
static void |
consumeAll(InputStream stream)
Read and discard everything from the specified InputStream |
|
static File |
createTempFile(String suffix)
Create a temporary file. |
|
static String |
decodeBytes(byte[] bytes,
CharsetDecoder decoder)
Decode the bytes with the decoder |
|
static void |
deleteTempDir(File file)
Delete a directory in the system temporary directory (java.io.tmpdir). |
|
static String[] |
fileArray2StringArray(File[] files)
Convert an array of Files to an array of Strings. |
|
static Charset |
getUtf8Charset()
|
|
static boolean |
isSymlink(File file)
Determines whether the specified file is a Symbolic Link rather than an actual file. |
|
static boolean |
isWindows()
|
|
static String |
obfuscateLoginData(String line)
|
|
static byte[] |
randomBytes()
Generate some random bytes that is printable Ascii characters. |
|
static int |
readBigEndian(InputStream stream)
Read four bytes from the stream, and return the integer represented by these bytes in big endian. |
|
static String |
readStream(InputStream in,
CharsetDecoder decoder)
Read everything from the stream and return it as a String |
|
static File |
resolveSymlinks(File file)
Return a new File object where symlinks are resolved. |
|
static File |
resourceAsFile(String resourceName)
Return a File that is created from a resource name found on the classpath. |
|
static File |
resourceAsFile(String resourceName,
Map<String,byte[]> replacements)
Return a File that is created from a resource name found on the classpath. |
|
static
|
single(Collection<T> coll)
Return the single element in the specified Collection. |
|
static File[] |
stringArray2FileArray(File baseDir,
String[] strings)
|
|
static void |
writeBigEndian(int n,
OutputStream stream)
Write 4 bytes representing the specified integer in big-endian. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public Utils()
Method Detail |
---|
public static boolean isWindows()
public static Charset getUtf8Charset()
public static int readBigEndian(InputStream stream) throws IOException
stream
- the input stream
IOException
public static void writeBigEndian(int n, OutputStream stream) throws IOException
n
- the integerstream
- the output stream
IOException
public static void consumeAll(InputStream stream) throws IOException
stream
-
IOException
public static String readStream(InputStream in, CharsetDecoder decoder)
in
- the input streamdecoder
- the CharsetDecoder
encapsulating the policy
of handling errors while decoding.
public static String decodeBytes(byte[] bytes, CharsetDecoder decoder)
bytes
- decoder
-
public static <T> T[] arrayUnshift(T first, T[] rest)
T
- first
- element to insert at position 0 in the result.rest
- elements to insert at position 1 to
rest.length
.
1 + rest.length
.public static <T> T[] arrayConcat(T[] a, T[] b)
T
- a
- b
-
a.length + b.length
.public static String[] fileArray2StringArray(File[] files)
Each file is converted with the getPath() method.
files
-
public static File[] stringArray2FileArray(File baseDir, String[] strings)
baseDir
- strings
-
public static File resolveSymlinks(File file)
file
-
public static <T> T single(Collection<T> coll)
If the collection is empty null is return
- Parameters:
coll
-
- Returns:
- null or the singleton element in the collection
- Throws:
IllegalArgumentException
- if the collection has more than one element
createTempFile
public static File createTempFile(String suffix)
- Create a temporary file.
This method is identical to
File.createTempFile(String, String)
except it
throws a RuntimeIOException
.
- Parameters:
suffix
-
- Returns:
- the temporary file
isSymlink
public static boolean isSymlink(File file)
- Determines whether the specified file is a Symbolic Link rather
than an actual file.
Will not return true if there is a Symbolic Link anywhere in
the path, only if the specific file is.
Note: The implementation is adapted from the similar method in
Apache Commons IO
- Parameters:
file
- the file to check
- Returns:
- true if the file is a Symbolic Link
asRuntime
public static RuntimeException asRuntime(Throwable e)
- Convert the specified exception into a RuntimeException
- Parameters:
e
-
- Returns:
- the RuntimeException
deleteTempDir
public static void deleteTempDir(File file)
throws IOException
- Delete a directory in the system temporary directory
(java.io.tmpdir).
- Throws:
IOException
resourceAsFile
public static File resourceAsFile(String resourceName)
- Return a File that is created from a resource name found on the
classpath. The resource is written into the File the first time
it's needed.
- Parameters:
resourceName
-
- Returns:
- the File
- Throws:
IOException
resourceAsFile
public static File resourceAsFile(String resourceName,
Map<String,byte[]> replacements)
- Return a File that is created from a resource name found on the
classpath. The resource is written into the File the first time
it's needed.
Patterns of the form %{name} will be replace with the
corresponding value from the replacement map.
- Parameters:
resourceName
-
- Returns:
- the File
- Throws:
IOException
randomBytes
public static byte[] randomBytes()
- Generate some random bytes that is printable Ascii characters.
They will be used in a Mercurial style file. To make it easy to
use the bytes in the style file the characters '"' and '\' will
not be part of the byte array.
- Returns:
obfuscateLoginData
public static String obfuscateLoginData(String line)
Overview
Package
Class
Use
Tree
Deprecated
Index
Help
PREV CLASS
NEXT CLASS
FRAMES
NO FRAMES
All Classes
SUMMARY: NESTED | FIELD | CONSTR | METHOD
DETAIL: FIELD | CONSTR | METHOD
Copyright © 2011-2013 aragost Trifork ag. All Rights Reserved.