Package kvd.common
Class Utils
java.lang.Object
kvd.common.Utils
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic void
checkKey
(byte[] key) static void
checkTimeout
(long startNs, long timeoutSeconds) static void
static void
closeSocketQuietly
(Socket socket) static long
copyLarge
(InputStream input, OutputStream output, byte[] buffer) Copies bytes from a large (over 2GB)InputStream
to anOutputStream
.static String
fromUTF8
(byte[] buf) static File
static String
humanReadableByteCountBin
(long bytes) static String
humanReadableByteCountSI
(long bytes) static boolean
isBlank
(CharSequence cs) static boolean
isTimeout
(long startNs, long timeoutSeconds) static int
length
(CharSequence cs) static byte[]
toByteArray
(InputStream input) static Charset
Returns a Charset for the named charset.static byte[]
-
Field Details
-
EOF
public static final int EOF- See Also:
-
-
Constructor Details
-
Utils
public Utils()
-
-
Method Details
-
closeSocketQuietly
-
closeQuietly
-
isTimeout
public static boolean isTimeout(long startNs, long timeoutSeconds) -
checkTimeout
public static void checkTimeout(long startNs, long timeoutSeconds) -
toUTF8
-
fromUTF8
-
isBlank
-
length
-
checkKey
public static void checkKey(byte[] key) -
getUserHome
-
toCharset
Returns a Charset for the named charset. If the name is null, return the default Charset.- Parameters:
charsetName
- The name of the requested charset, may be null.- Returns:
- a Charset for the named charset
- Throws:
UnsupportedCharsetException
- If the named charset is unavailable
-
copyLarge
public static long copyLarge(InputStream input, OutputStream output, byte[] buffer) throws IOException Copies bytes from a large (over 2GB)InputStream
to anOutputStream
.This method uses the provided buffer, so there is no need to use a
BufferedInputStream
.- Parameters:
input
- theInputStream
to read fromoutput
- theOutputStream
to write tobuffer
- the buffer to use for the copy- Returns:
- the number of bytes copied. or
0
ifinput is null
. - Throws:
IOException
- if an I/O error occurs- Since:
- 2.2
-
toByteArray
- Throws:
IOException
-
humanReadableByteCountSI
-
humanReadableByteCountBin
-