Class Utils

java.lang.Object
com.logviewer.utils.Utils

public class Utils extends Object
  • Field Details

    • MAX_TIME_MILLIS

      public static final long MAX_TIME_MILLIS
      See Also:
    • EMPTY_BYTE_ARRAY

      public static final byte[] EMPTY_BYTE_ARRAY
    • EMPTY_INT_ARRAY

      public static final int[] EMPTY_INT_ARRAY
    • EMPTY_BYTE_BUFFER

      public static final ByteBuffer EMPTY_BYTE_BUFFER
    • EMPTY_OBJECTS

      public static final Object[] EMPTY_OBJECTS
    • LOCAL_HOST_NAME

      public static final String LOCAL_HOST_NAME
  • Method Details

    • closeQuietly

      public static void closeQuietly(@Nullable AutoCloseable closeable)
    • deleteContent

      public static void deleteContent(Path path) throws IOException
      Throws:
      IOException
    • title

      public static String title(@Nullable String logPath)
    • readFully

      public static void readFully(ReadableByteChannel channel, ByteBuffer buf, int length) throws IOException
      Throws:
      IOException
    • readFully

      public static void readFully(ReadableByteChannel channel, ByteBuffer buf) throws IOException
      Throws:
      IOException
    • isIdentifier

      public static boolean isIdentifier(String s)
    • toString

      public static String toString(ByteBuffer buffer)
    • toString

      public static String toString(ByteBuffer buffer, Charset charsets)
    • isSubdirectory

      public static boolean isSubdirectory(String directory, String child)
    • compareFileNames

      public static int compareFileNames(@NonNull String f1, @NonNull String f2)
    • containsIgnoreCase

      public static boolean containsIgnoreCase(String str, String searchStr)
    • indexOf

      public static <T> int indexOf(List<? extends T> list, Predicate<T> predicate)
    • getFormatHash

      public static Long getFormatHash(LogFormat format)
    • safeGet

      public static <T> T safeGet(Future<T> future)
    • normalizePath

      public static String normalizePath(String path)
    • propagate

      public static RuntimeException propagate(@NonNull Throwable t)
    • putUnencodedChars

      public static void putUnencodedChars(MessageDigest digest, String s)
    • putUnencodedChars

      public static void putUnencodedChars(MessageDigest digest, char c)
    • putInt

      public static void putInt(MessageDigest digest, int x)
    • newMap

      public static <K, V> Map<K,V> newMap(Object... keysAndValues)
    • getStackTraceAsString

      @NonNull public static String getStackTraceAsString(@NonNull Throwable throwable)
    • assertValidTimestamp

      public static void assertValidTimestamp(long nano)
    • getTempDir

      @NonNull public static Path getTempDir() throws IOException
      Throws:
      IOException
    • removeAsciiColorCodes

      public static String removeAsciiColorCodes(String s)
    • decode

      public static Pair<String,Integer> decode(byte[] data, Charset encoding)
      Decodes text from a byte array. The end of the data may be broken UTF8 sequence, skip it.
      Parameters:
      data - The bytes to decode
      encoding - The encoding
      Returns:
      A pair of the decoded text and the actual size of the text in bytes.
    • setPositionSafely

      public static void setPositionSafely(ByteBuffer byteBuffer, int newPosition)
      We cannot call ByteBuffer.position(int) directly because it doesn't work with Java 8. In the Java 8 the return type is ByteBuffer, but in Java 11 the return type is Buffer. This method calls `position(int)` on Buffer class. It works with both Java 8 and Java 11.
    • setLimitSafely

      public static void setLimitSafely(ByteBuffer byteBuffer, int newLimit)
      We cannot call ByteBuffer.limit(int) directly because it doesn't work with Java 8. In the Java 8 the return type is ByteBuffer, but in Java 11 the return type is Buffer. This method calls `position(int)` on Buffer class. It works with both Java 8 and Java 11.