Class OSAdapter

java.lang.Object
org.ka2ddo.yaac.os.OSAdapter

public abstract class OSAdapter extends Object
This abstract class provides service methods for accessing operating-system-specific information. No instances of this class should ever be instantiated, as all methods are static.
Author:
Andrew Pavlin, KA2DDO
  • Method Details

    • getSerialPortListGetter

      public static OSAdapter.SerialPortListGetter getSerialPortListGetter()
      Get the existing SerialPortListGetter.
      Returns:
      SerialPortListGetter currently in use
    • setSerialPortListGetter

      public static void setSerialPortListGetter(OSAdapter.SerialPortListGetter serialPortListGetter)
      Replace the SerialPortListGetter with a different one if the serial port library is changed by a plugin. Should only be called by plugins.
      Parameters:
      serialPortListGetter - SerialPortListGetter instance
    • getSerialPortNames

      public static String[] getSerialPortNames(String currentDevName)
      Obtain the list of unused serial ports on this system.
      Parameters:
      currentDevName - String of an already-busy device name to add to list, or null for no additional name
      Returns:
      array String device names, or null if the system does not have access to serial ports
    • getCachedSerialPortNames

      public static String[] getCachedSerialPortNames(String deviceName)
      Get the list of serial port device names, including the specified name.
      Parameters:
      deviceName - device name to include (in case the device is already open)
      Returns:
      array of device name Strings
    • purgeSerialPortCache

      public static void purgeSerialPortCache()
      Purge the cached list of serial port device names, so the next query will have to build the list from scratch.
    • isWindows

      public static boolean isWindows()
      Test if the host operating system is Microsoft Windows.
      Returns:
      boolean true if running on Microsoft Windows (any release), false for any other operating system
    • openURL

      public static void openURL(String url)
      Launch O/S-specific browser to view a particular URL. Must be called from AWT dispatch thread.
      Parameters:
      url - String representation of URL to view
    • sendEmail

      public static void sendEmail(String emailAddr) throws Throwable
      Launch O/S-specific email client to compose an outgoing email. Must be called from AWT dispatch thread.
      Parameters:
      emailAddr - String representation of recipient email address
      Throws:
      Throwable - if email client could not be launched for any reason
    • getDirectoryFromCache

      public static File getDirectoryFromCache(String cacheId)
      Get a File representing a remembered directory for a particular type of file operation.
      Parameters:
      cacheId - String name of file operation (such as log files, or tile files)
      Returns:
      File pointing at the last directory for such operations, or null if never yet cached
    • putDirectoryToCache

      public static void putDirectoryToCache(String cacheId, File dir)
      remember the last directory used for a type of file operation.
      Parameters:
      cacheId - String name of file type
      dir - File pointing to the last directory used for those files
    • markStreamAsSequential

      public static void markStreamAsSequential(FileInputStream is)
      If O/S and available libraries allow it, mark open file as only sequentially accessed.
      Parameters:
      is - FileInputStream whose file descriptor will be accessed
    • releaseOldPages

      public static long releaseOldPages(FileInputStream is, long startForFlush)
      If O/S and available libraries allow it, mark every page prior to the current seek position as no longer needed.
      Parameters:
      is - FileInputStream whose file descriptor will be accessed
      startForFlush - file position where no-longer-needed file system cache pages should start being released
      Returns:
      file position where pages stopped being released
    • releaseOldPages

      public static long releaseOldPages(FileOutputStream os, long startForFlush)
      If O/S and available libraries allow it, mark every page prior to the current seek position as no longer needed.
      Parameters:
      os - FileOutputStream whose file descriptor will be accessed
      startForFlush - file position where no-longer-needed file system cache pages should start being released
      Returns:
      file position where pages stopped being released
    • releaseOldPages

      public static void releaseOldPages(RandomAccessFile raf)
      If O/S and available libraries allow it, mark every page in the RandomAccessFile as no longer needed. Note that any user-mode cached data should be flushed to the operating system kernel prior to calling this method.
      Parameters:
      raf - RandomAccessFile whose file descriptor will be accessed
      See Also:
    • releaseOldPages

      public static void releaseOldPages(RandomAccessFile raf, long startPos, long endPos)
      If O/S and available libraries allow it, mark every page in the RandomAccessFile as no longer needed. Note that any user-mode cached data should be flushed to the operating system kernel prior to calling this method.
      Parameters:
      raf - RandomAccessFile whose file descriptor will be accessed
      startPos - starting offset in file to release
      endPos - ending offset in file to release
      See Also:
    • markStreamAsSequential

      public static void markStreamAsSequential(FileOutputStream os)
      If O/S and available libraries allow it, mark open file as only sequentially accessed.
      Parameters:
      os - FileOutputStream whose file descriptor will be accessed
    • markFileAsRandom

      public static void markFileAsRandom(RandomAccessFile raf)
      If O/S and available libraries allow it, mark open file as only randomly accessed.
      Parameters:
      raf - RandomAccessFile whose file descriptor will be accessed