public class SimpleGMService extends Object implements GMService
GMService that creates a new GraphicsMagick process every time getConnection() is
called.| Modifier and Type | Field and Description |
|---|---|
static String |
DEFAULT_GM_PATH
Default path to GraphcisMagick executable is simply "gm".
|
| Constructor and Description |
|---|
SimpleGMService()
Create a new instance of SimpleGMService.
|
| Modifier and Type | Method and Description |
|---|---|
String |
execute(List<String> command)
Executes the command using the underlying GraphicsMagick process.
|
String |
execute(String command,
String... arguments)
Executes the GraphisMagick command and return the result.
|
GMConnection |
getConnection()
Gets an instance of
GMConnection. |
String |
getGMPath()
Gets the path to GraphicsMagick executable set by
setGMPath(String) or DEFAULT_GM_PATH if it
was not explicitly set. |
void |
setGMPath(String gmPath)
Sets the path to GraphicsMagick executable.
|
public static final String DEFAULT_GM_PATH
public SimpleGMService()
@Nonnull public String getGMPath()
setGMPath(String) or DEFAULT_GM_PATH if it
was not explicitly set.public void setGMPath(@Nonnull String gmPath)
gmPath - the path to GraphicsMagick executablepublic String execute(@Nonnull String command, String... arguments) throws GMException, GMServiceException, IOException
This is a convenient method to get the connection,
execute the command once and close
it. It is functionally equivalent to code below, but actual implementation may optimize this for better
efficiency.
final GMConnection connection = gmService.getConnection();
try {
return connection.execute(command, argument1, argument2, ...);
} finally {
connection.close();
}
This method is thread safe.
execute in interface GMExecutorexecute in interface GMServicecommand - the command to be executedarguments - arguments of the command.GMException - when GraphicsMagick returns non-IO error executing the commandGMServiceException - when there is error communicating with the underlying GraphicsMagick processIOException - when GM encounter IO error executing the commandGMExecutor.execute(List)public String execute(List<String> command) throws GMException, GMServiceException, IOException
This is a convenient method to get the connection, execute the command once and close it. It is functionally equivalent to code below,
but actual implementation may optimize this for better efficiency.
final GMConnection connection = gmService.getConnection();
try {
return connection.execute(command);
} finally {
connection.close();
}
This method is thread safe.
execute in interface GMExecutorexecute in interface GMServicecommand - the command and arguments to be executedGMException - when GraphicsMagick returns non-IO error executing the commandGMServiceException - when there is error communicating with the underlying GraphicsMagick processIOException - when GM encounter IO error executing the commandGMService.execute(String, String...)@Nonnull public GMConnection getConnection() throws GMServiceException
GMConnection. Depends on the implementation, the instance can be newly created or
from a pool.
This method is thread safe. This implementation creates a new instance.
getConnection in interface GMServiceGMServiceException - when communicate error occurs between the physical GraphicsMagick process.Copyright © 2016. All Rights Reserved.