Source:
public void convertFile(StormTaskTuple stormTaskTuple) throws IOException, MimeTypeException, MCSException, ICSException, RuntimeException { String fileUrl = stormTaskTuple.getFileUrl(); LOGGER.info("The converting process for file " + fileUrl + " started successfully"); String folderPath = null; try { ByteArrayInputStream inputStream = stormTaskTuple.getFileByteDataAsStream(); if (inputStream != null) { String inputMimeType = TaskTupleUtility.getParameterFromTuple(stormTaskTuple, PluginParameterKeys.MIME_TYPE); assert (TIFF_MIME_TYPE.equals(inputMimeType) || JPEG_MIME_TYPE.equals(inputMimeType)); String inputExtension = ExtensionHelper.getExtension(inputMimeType); String tempFileName = UUID.randomUUID().toString(); folderPath = ImageConverterUtil.persistStreamToTemporaryStorage(inputStream, tempFileName, inputExtension); String inputFilePath = ImageConverterUtil.buildFilePath(folderPath, tempFileName, inputExtension); String outputExtension = ExtensionHelper.getExtension(TaskTupleUtility.getParameterFromTuple(stormTaskTuple, PluginParameterKeys.OUTPUT_MIME_TYPE)); String outputFilePath = ImageConverterUtil.buildFilePath(folderPath, tempFileName, outputExtension); if (JPEG_EXTENSION.equals(inputExtension)) { String tempOutputFilePath = ImageConverterUtil.buildFilePath(folderPath, tempFileName, TIFF_EXTENSION); converterContext.convert(inputFilePath, tempOutputFilePath, null); inputFilePath = tempOutputFilePath; } converterContext.setConverter(new KakaduConverterTiffToJP2()); List<String> properties = new ArrayList<>(); properties.add(TaskTupleUtility.getParameterFromTuple(stormTaskTuple, PluginParameterKeys.KAKADU_ARGUEMENTS)); converterContext.convert(inputFilePath, outputFilePath, properties); stormTaskTuple.setFileData(imageConverterUtil.getStream(outputFilePath)); stormTaskTuple.addParameter(PluginParameterKeys.OUTPUT_FILE_NAME, tempFileName + outputExtension); LOGGER.info("The converting process for file " + fileUrl + " completed successfully"); } } finally { if (folderPath != null) FileUtils.deleteDirectory(new java.io.File(folderPath)); } }

Target:
public void convertFile(StormTaskTuple stormTaskTuple) throws IOException, MimeTypeException, MCSException, ICSException, RuntimeException { String fileUrl = stormTaskTuple.getFileUrl(); LOGGER.info("The converting process for file " + fileUrl + " started successfully"); String folderPath = null; try { ByteArrayInputStream inputStream = stormTaskTuple.getFileByteDataAsStream(); if (inputStream != null) { String inputMimeType = TaskTupleUtility.getParameterFromTuple(stormTaskTuple, PluginParameterKeys.MIME_TYPE); if (!(TIFF_MIME_TYPE.equals(inputMimeType) || JPEG_MIME_TYPE.equals(inputMimeType))) throw new AssertionError(); String inputExtension = ExtensionHelper.getExtension(inputMimeType); String tempFileName = UUID.randomUUID().toString(); folderPath = ImageConverterUtil.persistStreamToTemporaryStorage(inputStream, tempFileName, inputExtension); String inputFilePath = ImageConverterUtil.buildFilePath(folderPath, tempFileName, inputExtension); String outputExtension = ExtensionHelper.getExtension(TaskTupleUtility.getParameterFromTuple(stormTaskTuple, PluginParameterKeys.OUTPUT_MIME_TYPE)); String outputFilePath = ImageConverterUtil.buildFilePath(folderPath, tempFileName, outputExtension); if (JPEG_EXTENSION.equals(inputExtension)) { inputFilePath = convertJpgToTiff(folderPath, inputFilePath, tempFileName); } converterContext.setConverter(new KakaduConverterTiffToJP2()); List<String> properties = new ArrayList<>(); properties.add(TaskTupleUtility.getParameterFromTuple(stormTaskTuple, PluginParameterKeys.KAKADU_ARGUEMENTS)); converterContext.convert(inputFilePath, outputFilePath, properties); stormTaskTuple.setFileData(imageConverterUtil.getStream(outputFilePath)); stormTaskTuple.addParameter(PluginParameterKeys.OUTPUT_FILE_NAME, tempFileName + outputExtension); LOGGER.info("The converting process for file " + fileUrl + " completed successfully"); } } finally { if (folderPath != null) FileUtils.deleteDirectory(new File(folderPath)); } }