Class Binaries


  • public class Binaries
    extends java.lang.Object
    Helper class for dealing with the rsync binaries. On Linux and OSX, rsync and ssh must be present.
    Author:
    FracPete (fracpete at waikato dot ac dot nz)
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected static java.lang.Boolean binariesExtracted
      for storing any previously extract binary.
      static java.lang.String LIBRARIES  
      protected static java.util.logging.Logger LOGGER
      for logging.
      static java.lang.String RESOURCE_DIR
      the resource prefix.
      static java.lang.String RSYNC4J_RSYNC
      the environment variable for the rsync binary (Linux/Mac).
      static java.lang.String RSYNC4J_SSH
      the environment variable for the ssh binary (Linux/Mac).
      static java.lang.String RSYNC4J_SSHKEYGEN
      the environment variable for the ssh-keygen binary (Linux/Mac).
      static java.lang.String RSYNC4J_SSHPASS
      the environment variable for the sshpass binary (Linux/Mac).
      protected static java.lang.String rsyncBinary
      the rsync binary.
      protected static java.lang.String sshBinary
      the ssh binary.
      protected static java.lang.String sshkeygenBinary
      the ssh-keygen binary.
      protected static java.lang.String sshpassBinary
      the sshpass binary.
      protected static boolean sshpassBinaryPresent
      whether the sshpass binary is present.
      static java.lang.String WINDOWS_DIR_64
      the sub-directory for the windows 64bit binaries.
      static java.lang.String WINDOWS_HOME_DIR
      the windows environment variable for the rsyncj4 home directory.
    • Constructor Summary

      Constructors 
      Constructor Description
      Binaries()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.lang.String convertPath​(java.lang.String path)
      Converts the path into cygwin notation on Windows platform.
      protected static java.lang.String copyResourceTo​(java.lang.String inDir, java.lang.String name, java.lang.String outDir)
      Copies the specified resource to the output directory.
      protected static void extractBinaries()
      Extracts the binaries to the tmp directory.
      static int getBitness()
      Returns the "bitness", ie 32 or 64 bit of the underlying OS.
      protected static java.util.List<java.lang.String> getLibraries()
      Returns the list of libraries to copy.
      protected static java.lang.String getWindowsDir()
      Returns the sub-directory for the Windows binaries, depending on the bitness.
      protected static java.lang.String homeDir()
      Returns the home directory to use for rsync4j.
      static java.lang.String quotePath​(java.lang.String path)
      Quotes the path if a single quote is in the name.
      static java.lang.String quotePath​(java.lang.String path, boolean force)
      Quotes the path if a single quote is in the name.
      static java.lang.String rsyncBinary()
      Returns the rsync binary (if necessary extracts the binaries to the temp directory).
      static java.lang.String sshBinary()
      Returns the ssh binary (if necessary extracts the binaries to the temp directory).
      static java.lang.String sshkeygenBinary()
      Returns the ssh-keygen binary (if necessary extracts the binaries to the temp directory).
      static java.lang.String sshpassBinary()
      Returns the sshpass binary (if necessary extracts the binaries to the temp directory).
      static boolean sshpassBinaryPresent()
      Returns whether the sshpass binary is present (if necessary extracts the binaries to the temp directory).
      • Methods inherited from class java.lang.Object

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

      • RESOURCE_DIR

        public static final java.lang.String RESOURCE_DIR
        the resource prefix.
        See Also:
        Constant Field Values
      • WINDOWS_DIR_64

        public static final java.lang.String WINDOWS_DIR_64
        the sub-directory for the windows 64bit binaries.
        See Also:
        Constant Field Values
      • WINDOWS_HOME_DIR

        public static final java.lang.String WINDOWS_HOME_DIR
        the windows environment variable for the rsyncj4 home directory.
        See Also:
        Constant Field Values
      • RSYNC4J_RSYNC

        public static final java.lang.String RSYNC4J_RSYNC
        the environment variable for the rsync binary (Linux/Mac).
        See Also:
        Constant Field Values
      • RSYNC4J_SSH

        public static final java.lang.String RSYNC4J_SSH
        the environment variable for the ssh binary (Linux/Mac).
        See Also:
        Constant Field Values
      • RSYNC4J_SSHPASS

        public static final java.lang.String RSYNC4J_SSHPASS
        the environment variable for the sshpass binary (Linux/Mac).
        See Also:
        Constant Field Values
      • RSYNC4J_SSHKEYGEN

        public static final java.lang.String RSYNC4J_SSHKEYGEN
        the environment variable for the ssh-keygen binary (Linux/Mac).
        See Also:
        Constant Field Values
      • binariesExtracted

        protected static java.lang.Boolean binariesExtracted
        for storing any previously extract binary.
      • rsyncBinary

        protected static java.lang.String rsyncBinary
        the rsync binary.
      • sshBinary

        protected static java.lang.String sshBinary
        the ssh binary.
      • sshkeygenBinary

        protected static java.lang.String sshkeygenBinary
        the ssh-keygen binary.
      • sshpassBinary

        protected static java.lang.String sshpassBinary
        the sshpass binary.
      • sshpassBinaryPresent

        protected static boolean sshpassBinaryPresent
        whether the sshpass binary is present.
      • LOGGER

        protected static java.util.logging.Logger LOGGER
        for logging.
    • Constructor Detail

      • Binaries

        public Binaries()
    • Method Detail

      • getBitness

        public static int getBitness()
        Returns the "bitness", ie 32 or 64 bit of the underlying OS.
        Returns:
        the number of bits
      • copyResourceTo

        protected static java.lang.String copyResourceTo​(java.lang.String inDir,
                                                         java.lang.String name,
                                                         java.lang.String outDir)
                                                  throws java.lang.Exception
        Copies the specified resource to the output directory.
        Parameters:
        inDir - the resource directory to use
        name - the name of the resource
        outDir - the output directory
        Returns:
        the full path
        Throws:
        java.lang.Exception
      • homeDir

        protected static java.lang.String homeDir()
        Returns the home directory to use for rsync4j. On Windows, use the WINDOWS_HOME_DIR environment variable to point it to a custom location.
        Returns:
        the directory
      • getWindowsDir

        protected static java.lang.String getWindowsDir()
        Returns the sub-directory for the Windows binaries, depending on the bitness.
        Returns:
        the sub-directory of the binaries
      • getLibraries

        protected static java.util.List<java.lang.String> getLibraries()
                                                                throws java.lang.Exception
        Returns the list of libraries to copy.
        Returns:
        the libraries
        Throws:
        java.lang.Exception - if reading
      • extractBinaries

        protected static void extractBinaries()
                                       throws java.lang.Exception
        Extracts the binaries to the tmp directory.
        Throws:
        java.lang.Exception - if extraction fails
      • rsyncBinary

        public static java.lang.String rsyncBinary()
                                            throws java.lang.Exception
        Returns the rsync binary (if necessary extracts the binaries to the temp directory).
        Returns:
        the filename of the binary
        Throws:
        java.lang.Exception - if extraction fails
      • sshBinary

        public static java.lang.String sshBinary()
                                          throws java.lang.Exception
        Returns the ssh binary (if necessary extracts the binaries to the temp directory).
        Returns:
        the filename of the binary
        Throws:
        java.lang.Exception - if extraction fails
      • sshkeygenBinary

        public static java.lang.String sshkeygenBinary()
                                                throws java.lang.Exception
        Returns the ssh-keygen binary (if necessary extracts the binaries to the temp directory).
        Returns:
        the filename of the binary
        Throws:
        java.lang.Exception - if extraction fails
      • sshpassBinaryPresent

        public static boolean sshpassBinaryPresent()
                                            throws java.lang.Exception
        Returns whether the sshpass binary is present (if necessary extracts the binaries to the temp directory).
        Returns:
        true if present
        Throws:
        java.lang.Exception - if extraction fails
      • sshpassBinary

        public static java.lang.String sshpassBinary()
                                              throws java.lang.Exception
        Returns the sshpass binary (if necessary extracts the binaries to the temp directory).
        Returns:
        the filename of the binary
        Throws:
        java.lang.Exception - if extraction fails
      • quotePath

        public static java.lang.String quotePath​(java.lang.String path)
        Quotes the path if a single quote is in the name.
        Parameters:
        path - the path to quote
        Returns:
        the (potentially) double quoted path
      • quotePath

        public static java.lang.String quotePath​(java.lang.String path,
                                                 boolean force)
        Quotes the path if a single quote is in the name.
        Parameters:
        path - the path to quote
        force - forces double quoting
        Returns:
        the (potentially) double quoted path
      • convertPath

        public static java.lang.String convertPath​(java.lang.String path)
        Converts the path into cygwin notation on Windows platform.
        Parameters:
        path - the path to convert
        Returns:
        the (potentially) converted path