Class SystemUtil


  • public class SystemUtil
    extends java.lang.Object
    This file contains basic utility functions.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static com.google.common.base.Splitter COLON_SPLITTER
      A splitter that splits on colons.
      static com.google.common.base.Splitter COMMA_SPLITTER
      A splitter that splits on commas.
      static com.google.common.base.Splitter DOT_SPLITTER
      A splitter that splits on periods.
      static int jreVersion
      The major version number of the Java runtime (JRE), such as 8, 11, or 17.
      static com.google.common.base.Splitter PATH_SEPARATOR_SPLITTER
      A splitter that splits on File.pathSeparator.
    • Method Summary

      All Methods Static Methods Concrete Methods Deprecated Methods 
      Modifier and Type Method Description
      static @Nullable java.lang.Integer available​(java.io.InputStream is)
      Calls InputStream.available(), but returns null instead of throwing an IOException.
      static int getJreVersion()
      Deprecated.
      use field jreVersion instead
      static java.util.List<java.lang.String> getPathsProperty​(java.lang.String propName)
      Like System.getProperty, but splits on the path separator and never returns null.
      static @Nullable java.lang.String getReleaseValue​(javax.annotation.processing.ProcessingEnvironment env)
      Returns the release value passed to the compiler or null if release was not passed.
      static @Nullable java.lang.String getToolsJar()
      Returns the pathname to the tools.jar file, or null if it does not exist.
      static @Nullable java.lang.Boolean isWhitespaceOnly​(java.io.InputStream is, int readLimit)
      Returns true if the first readLimit bytes of the input stream consist only of whitespace.
      static int readCodePoint​(java.io.InputStream is)
      Reads a Unicode code point from an input stream.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • DOT_SPLITTER

        public static final com.google.common.base.Splitter DOT_SPLITTER
        A splitter that splits on periods. The result contains no empty strings.
      • COMMA_SPLITTER

        public static final com.google.common.base.Splitter COMMA_SPLITTER
        A splitter that splits on commas. The result contains no empty strings.
      • COLON_SPLITTER

        public static final com.google.common.base.Splitter COLON_SPLITTER
        A splitter that splits on colons. The result contains no empty strings.
      • PATH_SEPARATOR_SPLITTER

        public static final com.google.common.base.Splitter PATH_SEPARATOR_SPLITTER
        A splitter that splits on File.pathSeparator. The result contains no empty strings.
      • jreVersion

        public static final int jreVersion
        The major version number of the Java runtime (JRE), such as 8, 11, or 17.
    • Method Detail

      • getPathsProperty

        public static final java.util.List<java.lang.String> getPathsProperty​(java.lang.String propName)
        Like System.getProperty, but splits on the path separator and never returns null.
        Parameters:
        propName - a system property name
        Returns:
        the paths in the system property; may be an empty array
      • available

        public static @Nullable java.lang.Integer available​(java.io.InputStream is)
        Calls InputStream.available(), but returns null instead of throwing an IOException.
        Parameters:
        is - an input stream
        Returns:
        is.available(), or null if that throws an exception
      • isWhitespaceOnly

        public static @Nullable java.lang.Boolean isWhitespaceOnly​(java.io.InputStream is,
                                                                   int readLimit)
        Returns true if the first readLimit bytes of the input stream consist only of whitespace.
        Parameters:
        is - an input stream
        readLimit - how many bytes to look ahead in the input stream
        Returns:
        null if !is.markSupported(); otherwise, true if the first readLimit characters of the input stream consist only of whitespace
      • readCodePoint

        public static int readCodePoint​(java.io.InputStream is)
        Reads a Unicode code point from an input stream.
        Parameters:
        is - an input stream
        Returns:
        the Unicode code point for the next character in the input stream
      • getJreVersion

        @Deprecated
        public static int getJreVersion()
        Deprecated.
        use field jreVersion instead
        Returns the major version number from the "java.version" system property, such as 8, 11, or 17.

        This is different from the version passed to the compiler via --release; use getReleaseValue(ProcessingEnvironment) to get that version.

        Two possible formats of the "java.version" system property are considered. Up to Java 8, from a version string like `1.8.whatever`, this method extracts 8. Since Java 9, from a version string like `11.0.1`, this method extracts 11.

        Starting in Java 9, there is the int Runtime.version().feature(), but that does not exist on JDK 8.

        Returns:
        the major version of the Java runtime
      • getReleaseValue

        public static @Nullable java.lang.String getReleaseValue​(javax.annotation.processing.ProcessingEnvironment env)
        Returns the release value passed to the compiler or null if release was not passed.
        Parameters:
        env - the ProcessingEnvironment
        Returns:
        the release value or null if none was passed
      • getToolsJar

        public static @Nullable java.lang.String getToolsJar()
        Returns the pathname to the tools.jar file, or null if it does not exist. Returns null on Java 9 and later.
        Returns:
        the pathname to the tools.jar file, or null