Class IOUtil

java.lang.Object
io.strimzi.kafka.oauth.common.IOUtil

public class IOUtil extends Object
A helper class that contains commonly used methods for I/O operations
  • Constructor Details

    • IOUtil

      public IOUtil()
  • Method Details

    • copy

      public static void copy(InputStream input, OutputStream output) throws IOException
      Copy the content of specified InputStream into the specified OutputStream
      Parameters:
      input - The input stream to read from
      output - The output stream to write to
      Throws:
      IOException - an exception if the copy operation fails
    • randomHexString

      public static String randomHexString()
      Generate a random 8 character string of hexadecimal digits
      Returns:
      a hexadecimal String of length 8
    • randomHexString

      public static String randomHexString(int length)
      Generate a random string of hexadecimal digits of the specified length
      Parameters:
      length - The length of the resulting string
      Returns:
      a hexadecimal String of the specified length
    • asHexString

      public static String asHexString(byte[] bytes)
      Convert a byte array into a hexadecimal string
      Parameters:
      bytes - A byte array
      Returns:
      a hexadecimal string
    • hashForObjects

      public static String hashForObjects(Object... args)
      Generate a predictable (deterministic) hash string of length 8 for an array of objects
      Parameters:
      args - The objects to take as input for the calculation
      Returns:
      a hash string of length 8
    • crc32

      public static long crc32(String content)
      Calculate a CRC32 for the specified String
      Parameters:
      content - The input string
      Returns:
      CRC32 as long value
    • isFileAccessLimitedToOwner

      public static boolean isFileAccessLimitedToOwner(Path file) throws IOException
      Check that there are minimal permissions on the file (owner access only)

      In POSIX compatible environment there should be no permissions for group and other users. In ACL compatible environment there should be no permissions for anyone other than current user, Administrators or SYSTEM.

      Parameters:
      file - Path object representing an existing file to check file permissions for
      Returns:
      true if file permissions limit access to this file to the owner
      Throws:
      IllegalArgumentException - if file doesn't exist or is not a regular file (not a directory)
      UnsupportedOperationException - if filesystem doesn't support POSIX or ACL file permissions
      IOException - if an I/O error occurs