Class Utils

java.lang.Object
com.sshtools.common.util.Utils

public class Utils extends Object
  • Constructor Details

    • Utils

      public Utils()
  • Method Details

    • before

      public static String before(String value, char token)
    • after

      public static String after(String value, char token)
    • after

      public static String after(String value, String token)
    • before

      public static String before(String value, String token)
    • bytesToHex

      public static String bytesToHex(byte[] bytes)
    • bytesToHex

      public static String bytesToHex(byte[] bytes, int off, int len)
    • bytesToHex

      public static String bytesToHex(byte[] bytes, int bytesPerLine, boolean separateBytes, boolean showText)
    • bytesToHex

      public static String bytesToHex(byte[] bytes, int off, int len, int bytesPerLine, boolean separateBytes, boolean showText)
    • stripLeadingZeros

      public static byte[] stripLeadingZeros(byte[] data)
    • nearestMultipleOf

      public static int nearestMultipleOf(int length, int i)
    • splitToArgsArray

      public static String[] splitToArgsArray(String args)
    • generateThreadDump

      public static String generateThreadDump(Thread.State... states)
      From https://crunchify.com/how-to-generate-java-thread-dump-programmatically/
      Returns:
    • isBlank

      public static boolean isBlank(String str)
    • isNotBlank

      public static boolean isNotBlank(String str)
    • mergeToArgsString

      public static String mergeToArgsString(String[] args)
    • getUTF8Bytes

      public static byte[] getUTF8Bytes(String str)
    • join

      public static String join(String[] args, String str)
    • rightPad

      public static String rightPad(String rendered, int minWidth)
    • defaultString

      public static String defaultString(String value, String defaultValue)
    • csv

      public static String csv(String... elements)
    • csv

      public static String csv(Collection<String> elements)
    • csv

      public static String csv(String separator, String... elements)
    • csv

      public static String csv(String separator, Collection<String> elements)
    • randomAlphaNumericString

      public static String randomAlphaNumericString(int length)
    • exec

      public static String exec(String... cmd) throws IOException, InterruptedException
      Throws:
      IOException
      InterruptedException
    • prompt

      public static String prompt(BufferedReader reader, String message) throws IOException
      Throws:
      IOException
    • prompt

      public static String prompt(BufferedReader reader, String message, String defaultValue) throws IOException
      Throws:
      IOException
    • hasPort

      public static boolean hasPort(String hostname)
    • formatHostnameAndPort

      public static String formatHostnameAndPort(String hostname, int port)
    • getPort

      public static int getPort(String hostname)
    • hexToBytes

      public static byte[] hexToBytes(String s)
      Converts a hex string to bytes.
      Parameters:
      s - the hex string to be converted.
      Returns:
      the byte[]
    • pad

      public static String pad(int num)
    • emptyOptionalIfBlank

      public static Optional<String> emptyOptionalIfBlank(String str)
    • emptyOptionalIfBlank

      public static Optional<char[]> emptyOptionalIfBlank(char[] str)
    • translatePathString

      public static String translatePathString(Path path)
    • encodeUserInfo

      public static String encodeUserInfo(String userinfo)