Package kvd.common

Class Utils

java.lang.Object
kvd.common.Utils

public class Utils extends Object
  • Field Details

  • Constructor Details

    • Utils

      public Utils()
  • Method Details

    • 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 an OutputStream.

      This method uses the provided buffer, so there is no need to use a BufferedInputStream.

      Parameters:
      input - the InputStream to read from
      output - the OutputStream to write to
      buffer - the buffer to use for the copy
      Returns:
      the number of bytes copied. or 0 if input 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)