Class ExifToolBuilder


  • public class ExifToolBuilder
    extends Object
    Builder for ExifTool instance. This builder should be used to create instance of ExifTool.

    Settings

    Path

    Set the absolute withPath to the ExifTool executable on the host system running this class as defined by the `exiftool.withPath` system property. If set, value will be used, otherwise, withPath will be read:
    • From system property. This system property can be set on startup with -Dexiftool.withPath=/withPath/to/exiftool or by calling System.setProperty(String, String) before this class is loaded.
    • Default value is exiftool. In this case, exiftool command must be globally available.
    If ExifTool is on your system withPath and running the command exiftool successfully executes it, leaving this value unchanged will work fine on any platform. If the ExifTool executable is named something else or not in the system withPath, then this property will need to be set to point at it before using this class. On Windows be sure to double-escape the withPath to the tool, for example: -Dexiftool.withPath=C:\\Tools\\exiftool.exe. Default value is exiftool. Relative withPath values (e.g. bin/tools/exiftool) are executed with relation to the base directory the VM process was started in. Essentially the directory that new File(".").getAbsolutePath() points at during runtime.

    Executor

    Executor is the component responsible for executing command line on the system. Most of the time, the default should be fine, but if you want to tune the used withExecutor, then this property is for you. Custom withExecutor must implement CommandExecutor interface.

    Stay Open Strategy

    ExifTool 8.36 added a new persistent-process feature that allows ExifTool to stay running in a daemon mode and continue accepting commands via a file or stdin. This feature is disabled by default. NOTE: If stay_open flag is enabled, then an instance of UnsupportedFeatureException may be thrown during ExifTool creation. If this exception occurs, then you should probably:
    • Update your ExifTool version.
    • Create new ExifTool without this feature.
    . Usage:
    
         final ExifTool exifTool;
         try {
             exifTool = new ExifToolBuilder()
                 .enableStayOpen()
                 .build();
         }
         catch (UnsupportedFeatureException ex) {
             exifTool = new ExifToolBuilder().build();
         }
     

    Custom Strategies

    If default strategies are not enough, you can easily provide your own using the withStrategy(com.thebuzzmedia.exiftool.ExecutionStrategy) method. Usage:
    
       ExifTool exifTool = new ExifToolBuilder()
         .withStrategy(new MyCustomStrategy())
         .build();
     
    • Constructor Detail

      • ExifToolBuilder

        public ExifToolBuilder()
    • Method Detail

      • withPath

        public ExifToolBuilder withPath​(String path)
        Override default path. Default path is defined by the environment property exiftool.path or is set with exiftool otherwise. Setting the path explicitly will disable automatic lookup.
        Parameters:
        path - New path.
        Returns:
        Current builder.
      • withPath

        public ExifToolBuilder withPath​(File path)
        Override default path. Default path is defined by the environment property exiftool.path or is set with exiftool otherwise. Setting the path explicitly will disable automatic lookup.
        Note: If path is not an executable file, a warning will be logged but it will not fail.
        Parameters:
        path - New path.
        Returns:
        Current builder.
      • withExecutor

        public ExifToolBuilder withExecutor​(CommandExecutor executor)
        Override default exifTool executor.
        Parameters:
        executor - New withExecutor.
        Returns:
        Current builder.
      • enableStayOpen

        public ExifToolBuilder enableStayOpen()
        Enable stay_open feature.
        Returns:
        Current builder.
      • enableStayOpen

        public ExifToolBuilder enableStayOpen​(long cleanupDelay)
        Enable stay_open feature. Note:
        • If {link #withStrategy} is called, then calling this method is useless.
        • If {link #enableStayOpen(scheduler} is called, then calling this method is useless.
        Parameters:
        cleanupDelay - Interval (in milliseconds) between automatic clean operation.
        Returns:
        Current builder.
      • withStrategy

        public ExifToolBuilder withStrategy​(ExecutionStrategy strategy)
        Override default execution strategy. If enableStayOpen() has been called, then strategy associated with stay_open flag will be ignored.
        Parameters:
        strategy - Strategy.
        Returns:
        Current builder.
      • withPoolSize

        public ExifToolBuilder withPoolSize​(int poolSize,
                                            long cleanupDelay)
        Override default execution strategy:
        • a pool of StayOpenStrategy with a size of poolSize will be used.
        • Default scheduler instances will be used with a delay of cleanupDelay.
        Parameters:
        poolSize - Pool size.
        cleanupDelay - Cleanup delay for each scheduler of pool elements.
        Returns:
        Current builder.
      • withPoolSize

        public ExifToolBuilder withPoolSize​(int poolSize)
        Override default execution strategy:
        Parameters:
        poolSize - Pool size.
        Returns:
        Current builder.
      • build

        public ExifTool build()
        Create exiftool instance with previous settings.
        Returns:
        Exiftool instance.