public static void convert(String inputFilePath, String outputFilePath) throws CommandNotAvailable, CommandException { CommandLineExecutorService cles = Framework.getService(CommandLineExecutorService.class); CmdParameters params = cles.getDefaultCmdParameters(); params.addNamedParameter("inputFilePath", inputFilePath); params.addNamedParameter("outputFilePath", outputFilePath); ExecResult res = cles.execCommand("converter", params); if (!res.isSuccessful()) { throw res.getError(); } }
public static ExecResult getIdentifyResult(String inputFilePath) throws CommandNotAvailable { CommandLineExecutorService cles = Framework.getService(CommandLineExecutorService.class); CmdParameters params = cles.getDefaultCmdParameters(); params.addNamedParameter("inputFilePath", inputFilePath); return cles.execCommand("identify", params); }
@Override public boolean isAvailable() { CommandLineExecutorService cles = Framework.getService(CommandLineExecutorService.class); CommandAvailability commandAvailability = cles.getCommandAvailability("identify"); return commandAvailability.isAvailable(); }
String command = ignorePrefix ? BinaryMetadataConstants.EXIFTOOL_WRITE_NOPREFIX : BinaryMetadataConstants.EXIFTOOL_WRITE; CommandAvailability ca = commandLineService.getCommandAvailability(command); if (!ca.isAvailable()) { throw new BinaryMetadataException("Command '" + command + "' is not available."); CmdParameters params = commandLineService.getDefaultCmdParameters(); params.addNamedParameter("inFilePath", newBlob.getFile()); params.addNamedParameter("tagList", getCommandTags(metadata)); ExecResult er = commandLineService.execCommand(command, params); boolean success = er.isSuccessful(); if (!success) { log.error("There was an error executing " + "the following command: " + er.getCommandLine() + ". \n" + er.getOutput()); return null;
CommandAvailability commandAvailability = cles.getCommandAvailability(THUMBNAIL_COMMAND); if (!commandAvailability.isAvailable()) { return null; targetBlob.setMimeType("image/png"); try (CloseableFile source = blob.getCloseableFile()) { CmdParameters params = cles.getDefaultCmdParameters(); String size = parameters == null ? THUMBNAIL_DEFAULT_SIZE : (String) parameters.getOrDefault(THUMBNAIL_SIZE_PARAMETER_NAME, THUMBNAIL_DEFAULT_SIZE); params.addNamedParameter(THUMBNAIL_SIZE_PARAMETER_NAME, size); params.addNamedParameter("inputFilePath", source.getFile()); params.addNamedParameter("outputFilePath", targetBlob.getFile()); ExecResult res = cles.execCommand(THUMBNAIL_COMMAND, params); if (!res.isSuccessful()) { throw res.getError();
private Blob call(Blob blob, String finalFormat, final int width, final int height, final ImageInfoExtended info) { CommandAvailability availability = cles.getCommandAvailability("resizer"); if (!availability.isAvailable()) { return null; CmdParameters params = new CmdParameters(); String commandName = "resizer"; try { params.addNamedParameter("quality", quality); params.addNamedParameter("targetWidth", String.valueOf(width)); params.addNamedParameter("targetHeight", String.valueOf(height)); params.addNamedParameter("inputFilePath", sourceFile.getAbsolutePath()); params.addNamedParameter("outputFilePath", targetFile.getAbsolutePath()); params.addNamedParameter("targetDepth", String.valueOf(info.getDepth())); ExecResult res = execCommand(commandName, params); if (!res.isSuccessful()) { throw res.getError();
protected Map<String, Object> readMetadata(String command, Blob blob, List<String> metadata, boolean ignorePrefix) { CommandAvailability ca = commandLineService.getCommandAvailability(command); if (!ca.isAvailable()) { throw new BinaryMetadataException("Command '" + command + "' is not available."); } if (blob == null) { throw new BinaryMetadataException("The following command " + ca + " cannot be executed with a null blob"); } try { ExecResult er; try (CloseableFile source = getTemporaryFile(blob)) { CmdParameters params = commandLineService.getDefaultCmdParameters(); params.addNamedParameter("inFilePath", source.getFile()); if (metadata != null) { params.addNamedParameter("tagList", getCommandTags(metadata)); } er = commandLineService.execCommand(command, params); } return returnResultMap(er); } catch (CommandNotAvailable commandNotAvailable) { throw new RuntimeException("Command '" + command + "' is not available.", commandNotAvailable); } catch (IOException ioException) { throw new BinaryMetadataException(ioException); } }
private ImageInfoExtended getInfo(String inputFilePath) throws CommandNotAvailable, CommandException { ExecResult result = getIdentifyResult(inputFilePath); if (!result.isSuccessful()) { log.debug("identify failed for file: " + inputFilePath); throw result.getError(); } String out = result.getOutput().get(result.getOutput().size() > 1 ? result.getOutput().size() - 1 : 0); String[] res = out.split(" "); return new ImageInfoExtended(res[1], res[2], res[0], res[3], res[4], res[5], inputFilePath); }
protected CmdParameters setupCmdParameters(Map<String, String> parameters) { CmdParameters cmdParameters = new CmdParameters(); for (String param: parameters.keySet()) { cmdParameters.addNamedParameter(param, parameters.get(param)); } return cmdParameters; }
private static ExecResult execCommand(String commandName, CmdParameters params) throws CommandNotAvailable { CommandLineExecutorService cles = Framework.getLocalService(CommandLineExecutorService.class); return cles.execCommand(commandName, params); }
@Override protected BlobHolder buildResult(List<String> cmdOutput, CmdParameters cmdParams) throws ConversionException { final ParameterValue outputPath = cmdParams.getParameters().get("outDirPath"); final File outputDir = new File(outputPath.getValue()); final File[] files = outputDir.listFiles(); final List<Blob> blobs = new ArrayList<>(); for (final File file : files) { final Blob blob = new FileBlob(file); blob.setFilename(file.getName()); if (file.getName().equalsIgnoreCase("index.html")) { blobs.add(0, blob); } else { blobs.add(blob); } } return new SimpleCachableBlobHolder(blobs); }
@Override protected BlobHolder buildResult(List<String> cmdOutput, CmdParameters cmdParams) { try { return super.buildResult(cmdOutput, cmdParams); } finally { // delete the temp folder String userInstallationPath = cmdParams.getParameter(USER_INSTALLATION_PATH_KEY); if (userInstallationPath != null) { deleteTempDirectory(userInstallationPath); } } }
public static void rotate(String inputFile, String outputFile, int angle) throws CommandNotAvailable, CommandException { CommandLineExecutorService cles = Framework.getService(CommandLineExecutorService.class); CmdParameters params = cles.getDefaultCmdParameters(); params.addNamedParameter("angle", String.valueOf(angle)); params.addNamedParameter("inputFilePath", inputFile); params.addNamedParameter("outputFilePath", outputFile); ExecResult result = cles.execCommand("rotate", params); if (!result.isSuccessful()) { throw result.getError(); } }
public static ImageInfo getInfo(String inputFilePath) throws CommandNotAvailable, CommandException { ExecResult result = getIdentifyResult(inputFilePath); if (!result.isSuccessful()) { log.debug("identify failed for file: " + inputFilePath); throw result.getError(); } String out = result.getOutput().get(result.getOutput().size() > 1 ? result.getOutput().size() - 1 : 0); String[] res = out.split(" "); return new ImageInfo(res[1], res[2], res[0], res[3], res[4], inputFilePath); }
public boolean isToolAvailable(String toolName) { String commandLine; try { VideoTool tool = (VideoTool) videoTools.get(toolName).newInstance(); commandLine = tool.getCommandLineName(); } catch (InstantiationException e) { throw new NuxeoException("The video tool is not available.", e); } catch (IllegalAccessException e) { throw new NuxeoException("The video tool is not available.", e); } CommandAvailability ca = Framework.getService(CommandLineExecutorService.class) .getCommandAvailability(commandLine); return ca.isAvailable(); }
private static ExecResult getIdentifyResult(String inputFilePath) throws CommandNotAvailable { CmdParameters params = new CmdParameters(); params.addNamedParameter("inputFilePath", inputFilePath); return execCommand("identifyQuality", params); }
/** * @deprecated Since 7.4. Useless. */ @Deprecated protected static ExecResult execCommand(String commandName, CmdParameters params) throws CommandNotAvailable { CommandLineExecutorService cles = Framework.getService(CommandLineExecutorService.class); return cles.execCommand(commandName, params); }
public static void crop(String inputFilePath, String outputFilePath, int tileWidth, int tileHeight, int offsetX, int offsetY) throws CommandNotAvailable, CommandException { CommandLineExecutorService cles = Framework.getService(CommandLineExecutorService.class); CmdParameters params = cles.getDefaultCmdParameters(); params.addNamedParameter("tileWidth", String.valueOf(tileWidth)); params.addNamedParameter("tileHeight", String.valueOf(tileHeight)); params.addNamedParameter("offsetX", String.valueOf(offsetX)); params.addNamedParameter("offsetY", String.valueOf(offsetY)); params.addNamedParameter("inputFilePath", inputFilePath); params.addNamedParameter("outputFilePath", outputFilePath); ExecResult res = cles.execCommand("crop", params); if (!res.isSuccessful()) { throw res.getError(); } }
/** @since 5.9.5. */ public static void cropAndResize(String inputFilePath, String outputFilePath, int tileWidth, int tileHeight, int offsetX, int offsetY, int targetWidth, int targetHeight, String mapComponents) throws CommandNotAvailable, CommandException { if (mapComponents == null) { mapComponents = DEFAULT_MAP_COMPONENTS; } CommandLineExecutorService cles = Framework.getService(CommandLineExecutorService.class); CmdParameters params = cles.getDefaultCmdParameters(); params.addNamedParameter("tileWidth", String.valueOf(tileWidth)); params.addNamedParameter("tileHeight", String.valueOf(tileHeight)); params.addNamedParameter("offsetX", String.valueOf(offsetX)); params.addNamedParameter("offsetY", String.valueOf(offsetY)); params.addNamedParameter("targetWidth", String.valueOf(targetWidth)); params.addNamedParameter("targetHeight", String.valueOf(targetHeight)); params.addNamedParameter("inputFilePath", inputFilePath); params.addNamedParameter("outputFilePath", outputFilePath); params.addNamedParameter("mapComponents", mapComponents); ExecResult res = cles.execCommand("cropAndResize", params); if (!res.isSuccessful()) { throw res.getError(); } }
public static VideoInfo getVideoInfo(Blob video) { if (video == null || video.getLength() == 0) { return null; } try { ExecResult result; try (CloseableFile cf = video.getCloseableFile("." + FilenameUtils.getExtension(video.getFilename()))) { CommandLineExecutorService cles = Framework.getService(CommandLineExecutorService.class); CmdParameters params = cles.getDefaultCmdParameters(); params.addNamedParameter("inFilePath", cf.getFile().getAbsolutePath()); // read the duration with a first command to adjust the best rate: result = cles.execCommand(FFMPEG_INFO_COMMAND_LINE, params); } if (!result.isSuccessful()) { throw result.getError(); } return VideoInfo.fromFFmpegOutput(result.getOutput()); } catch (CommandNotAvailable | CommandException | IOException e) { throw new NuxeoException(e); } }