Package snap.util

Class SnapUtils

java.lang.Object
snap.util.SnapUtils

public class SnapUtils extends Object
This class provides general utility methods.
  • Field Details

    • isWindows

      public static boolean isWindows
    • isMac

      public static boolean isMac
    • isTeaVM

      public static boolean isTeaVM
    • isWebVM

      public static boolean isWebVM
  • Constructor Details

    • SnapUtils

      public SnapUtils()
  • Method Details

    • getPlatform

      public static SnapUtils.Platform getPlatform()
      Returns the current platform.
    • clone

      public static <T> T clone(T anObj)
      Returns a clone of the given object (supports List, Map, Cloneable and null). If object not cloneable, returns object.
    • cloneDeep

      public static <T> T cloneDeep(T anObj)
      Clones the given object, recursively, if the object is a collection.
    • compare

      public static int compare(Object anObj1, Object anObj2)
      Returns result of comparing two values.
    • getTempDir

      public static String getTempDir()
      Returns the temp directory for this machine.
    • getBytes

      public static byte[] getBytes(Object aSource)
      Returns a byte array from a File, String path, InputStream, URL, byte[], etc.
    • getBytesOrThrow

      public static byte[] getBytesOrThrow(Object aSource) throws IOException
      Returns a byte array from a File, String path, InputStream, URL, byte[], etc.
      Throws:
      IOException
    • getBytes

      public static byte[] getBytes(InputStream aStream)
      Returns bytes for an input stream.
    • getBytesOrThrow

      public static byte[] getBytesOrThrow(InputStream aStream) throws IOException
      Returns bytes for an input stream.
      Throws:
      IOException
    • getText

      public static String getText(Object aSource)
      Returns text for a source.
    • getBytes

      public static byte[] getBytes(Class<?> aClass, String aName)
      Returns bytes for a class and name/path.
    • getText

      public static String getText(Class<?> aClass, String aName)
      Returns text string for a class and name/path.
    • getInputStream

      public static InputStream getInputStream(Object aSource)
      Returns an input stream from a File, String path, URL, byte array, InputStream, etc.
    • writeBytes

      public static void writeBytes(byte[] bytes, Object aDest)
      Writes the given bytes to the given output object (string path or file).
    • getHostname

      public static String getHostname()
      Returns the hostname for this machine.
    • getBuildInfo

      public static String getBuildInfo()
      Returns a build date string (eg, "Jan-26-03") as generated into BuildInfo.txt at build time.
    • getProcessorCount

      public static int getProcessorCount()
      Returns the number of processors on this machine.
    • doOnce

      public static boolean doOnce(String anId)
      Returns whether to do something once based on given unique id string.
    • printlnOnce

      public static void printlnOnce(PrintStream aStream, String aString)
      Does a println of a given message to given print writer once.
    • notImpl

      public static RuntimeException notImpl(Object anObj, String aStr)
      Returns a "not implemented" exception for string (method name).