Package kvd.common
Class Utils
- java.lang.Object
-
- kvd.common.Utils
-
public class Utils extends Object
-
-
Field Summary
Fields Modifier and Type Field Description static int
EOF
-
Constructor Summary
Constructors Constructor Description Utils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static void
checkKey(byte[] key)
static void
checkTimeout(long startNs, long timeoutSeconds)
static void
closeQuietly(AutoCloseable c)
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
getUserHome()
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
toCharset(String charsetName)
Returns a Charset for the named charset.static byte[]
toUTF8(String s)
-
-
-
Field Detail
-
EOF
public static final int EOF
- See Also:
- Constant Field Values
-
-
Method Detail
-
closeSocketQuietly
public static void closeSocketQuietly(Socket socket)
-
closeQuietly
public static void closeQuietly(AutoCloseable c)
-
isTimeout
public static boolean isTimeout(long startNs, long timeoutSeconds)
-
checkTimeout
public static void checkTimeout(long startNs, long timeoutSeconds)
-
toUTF8
public static byte[] toUTF8(String s)
-
fromUTF8
public static String fromUTF8(byte[] buf)
-
isBlank
public static boolean isBlank(CharSequence cs)
-
length
public static int length(CharSequence cs)
-
checkKey
public static void checkKey(byte[] key)
-
getUserHome
public static File getUserHome()
-
toCharset
public static Charset toCharset(String charsetName)
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
public static byte[] toByteArray(InputStream input) throws IOException
- Throws:
IOException
-
humanReadableByteCountSI
public static String humanReadableByteCountSI(long bytes)
-
humanReadableByteCountBin
public static String humanReadableByteCountBin(long bytes)
-
-