public final class Util extends Object
Modifier and Type | Field and Description |
---|---|
static Class<?>[] |
PRIMITIVE_TYPES
Java's primitive types:
Number
String
Boolean
Character
Date
java.sql.Date
Color
URL
URI
|
Modifier and Type | Method and Description |
---|---|
static <O> Iterable<O> |
asIterable(Enumeration<O> enumeration)
|
static long |
copyAndClose(InputStream is,
OutputStream os)
Copies all data from input to output and closes the streams afterwards.
|
static long |
copyStream(InputStream is,
OutputStream os)
Copies all data from input to output.
|
static boolean |
deleteAllBelow(File dir)
Recursively delete everything below a given directory, but don't remove the directory itself.
|
static boolean |
deleteRecursively(Collection<File> files)
Recursively delete several
File s or directories. |
static boolean |
deleteRecursively(File file)
Recursively delete a
File or directory. |
static long |
discardStream(InputStream inputStream)
Discards all data from a given
InputStream but does not close it. |
static String |
fileToURL(File file)
Create a correct file URL that LibreOffice can handle.
|
static <K,V> Map<V,K> |
invertMap(Map<K,V> map)
Inverts a
Map from <K> → <V> to <V>
→ <K>. |
static boolean |
isPrimitivObject(Object obj,
boolean considerCollections)
Checks if a given object is an instance of a
PRIMITIVE_TYPES or a Collection / Array /
Map assembled of primitive types. |
static String |
join(Collection<String> values,
String glue)
Joins the given Strings as one single string, separated by the value glue.
|
static <K,V> void |
put(Map<K,Set<V>> multimap,
K key,
V value)
Utility method for putting values into a multimap.
|
static com.levigo.jadice.document.io.SeekableInputStream |
wrapSeekable(InputStream is)
Wraps a given InputStream into a seekable input stream (i.e.
|
public static final Class<?>[] PRIMITIVE_TYPES
Number
String
Boolean
Character
Date
java.sql.Date
Color
URL
URI
public static String fileToURL(File file) throws IOException
IOException
public static long copyStream(InputStream is, OutputStream os) throws IOException
is
- the source streamos
- the target streamIOException
public static long copyAndClose(InputStream is, OutputStream os) throws IOException
is
- the source streamos
- the target streamIOException
public static long discardStream(InputStream inputStream) throws IOException
InputStream
but does not close it. This method
can used as a /dev/null
device.inputStream
- The stream to discardIOException
- if an I/O error occurs.public static com.levigo.jadice.document.io.SeekableInputStream wrapSeekable(InputStream is) throws IOException
MemoryInputStream
) if it is not already seekable.is
- The stream to wrapIOException
public static boolean deleteRecursively(File file)
File
or directory.file
- The file or directory to deletetrue
iff the file or directory and all of its content is successfully
deletedFile.delete()
public static boolean deleteRecursively(Collection<File> files)
File
s or directories.files
- The files or directories to deletetrue
iff all files or directories and all of its contents are successfully
deletedFile.delete()
public static boolean deleteAllBelow(File dir)
dir
- The directory to deletetrue
iff all of the directory's content is successfully deletedFile.delete()
public static <K,V> Map<V,K> invertMap(Map<K,V> map)
Map
from <K> → <V> to <V>
→ <K>.
If the given map is not symmetric or contains null
as key or value the result will
differ from the expected resultK
- former key typeV
- former value typemap
- the map to invertpublic static <K,V> void put(Map<K,Set<V>> multimap, K key, V value)
Utility method for putting values into a multimap.
Implementation note: If no entry is found so under the given key, a HashSet
the will be
created as the Set
where the value is stored. So, the same value cannot be stored
multiple times under a given key.
K
- key typeV
- value typmultimap
- where to store the valuekey
- key with which the specified value is to be associated.value
- value to be associated with the specified key.public static boolean isPrimitivObject(Object obj, boolean considerCollections)
Checks if a given object is an instance of a PRIMITIVE_TYPES
or a Collection / Array /
Map assembled of primitive types.
Caveat: If considerCollections
is true
, empty collections will
result with true
as the generic type information is lost while the compilation.
obj
- the object to checkconsiderCollections
- if true
Collections / Arrays / Maps are checked
recursivelytrue
iff the given object is a primitive object (or assembled of them)public static String join(Collection<String> values, String glue)
Joins the given Strings as one single string, separated by the value glue. This is the inverse
operation to String.split(String)
.
Example: join({"a","b","c","d"}, ", ") ⇒ "a, b, c, d"
values
- the String literals to joinglue
- a value that is glued between the single literals, might also be empty or
null
String.split(String)
public static <O> Iterable<O> asIterable(Enumeration<O> enumeration)
Enumeration
as a read-only Iterable
so that it can be used in enhanced
for
-loops. This wrapping is not thread-safe.O
- The enumeration's objects typeenumeration
- the (old-fashioned) Enumeration
Iterable
Copyright © 2017 levigo holding gmbh. All rights reserved.