Package com.thebuzzmedia.exiftool
Class ExifToolBuilder
- java.lang.Object
-
- com.thebuzzmedia.exiftool.ExifToolBuilder
-
public class ExifToolBuilder extends Object
Builder forExifTool
instance. This builder should be used to create instance ofExifTool
.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 callingSystem.setProperty(String, String)
before this class is loaded. -
Default value is
exiftool
. In this case,exiftool
command must be globally available.
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 isexiftool
. 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 thatnew 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 implementCommandExecutor
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: Ifstay_open
flag is enabled, then an instance ofUnsupportedFeatureException
may be thrown during ExifTool creation. If this exception occurs, then you should probably:- Update your ExifTool version.
- Create new ExifTool without this feature.
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 thewithStrategy(com.thebuzzmedia.exiftool.ExecutionStrategy)
method. Usage:ExifTool exifTool = new ExifToolBuilder() .withStrategy(new MyCustomStrategy()) .build();
-
From system property. This system property can be set on startup
with
-
-
Constructor Summary
Constructors Constructor Description ExifToolBuilder()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description ExifTool
build()
Create exiftool instance with previous settings.ExifToolBuilder
enableStayOpen()
Enablestay_open
feature.ExifToolBuilder
enableStayOpen(long cleanupDelay)
Enablestay_open
feature.ExifToolBuilder
enableStayOpen(Scheduler scheduler)
Enablestay_open
feature and perform cleanup task using givenscheduler
.ExifToolBuilder
withExecutor(CommandExecutor executor)
Override default exifTool executor.ExifToolBuilder
withPath(File path)
Override default path.ExifToolBuilder
withPath(String path)
Override default path.ExifToolBuilder
withPoolSize(int poolSize)
Override default execution strategy: a pool ofStayOpenStrategy
with a size ofpoolSize
will be used. No cleanup scheduler will be used (usewithPoolSize(int, long)
instead.ExifToolBuilder
withPoolSize(int poolSize, long cleanupDelay)
Override default execution strategy: a pool ofStayOpenStrategy
with a size ofpoolSize
will be used. Default scheduler instances will be used with a delay ofcleanupDelay
.ExifToolBuilder
withStrategy(ExecutionStrategy strategy)
Override default execution strategy.
-
-
-
Method Detail
-
withPath
public ExifToolBuilder withPath(String path)
Override default path. Default path is defined by the environment propertyexiftool.path
or is set withexiftool
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 propertyexiftool.path
or is set withexiftool
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()
Enablestay_open
feature.- Returns:
- Current builder.
-
enableStayOpen
public ExifToolBuilder enableStayOpen(long cleanupDelay)
Enablestay_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.
-
enableStayOpen
public ExifToolBuilder enableStayOpen(Scheduler scheduler)
Enablestay_open
feature and perform cleanup task using givenscheduler
. Note:- If
withStrategy(com.thebuzzmedia.exiftool.ExecutionStrategy)
has already been called, then calling is useless. -
If
enableStayOpen(long)
has already been called, then givendelay
will be ignored and the specified scheduler will be used.
- Parameters:
scheduler
- Scheduler used to process automatic cleanup task..- Returns:
- Current builder.
- If
-
withStrategy
public ExifToolBuilder withStrategy(ExecutionStrategy strategy)
Override default execution strategy. IfenableStayOpen()
has been called, then strategy associated withstay_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 ofpoolSize
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.
- a pool of
-
withPoolSize
public ExifToolBuilder withPoolSize(int poolSize)
Override default execution strategy:- a pool of
StayOpenStrategy
with a size ofpoolSize
will be used. - No cleanup scheduler will be used (use
withPoolSize(int, long)
instead.
- Parameters:
poolSize
- Pool size.- Returns:
- Current builder.
- a pool of
-
build
public ExifTool build()
Create exiftool instance with previous settings.- Returns:
- Exiftool instance.
-
-