diff --git a/common/source/java/ch/systemsx/cisd/common/compression/tiff/AbstractTiffCompressionMethod.java b/common/source/java/ch/systemsx/cisd/common/compression/tiff/AbstractTiffCompressionMethod.java deleted file mode 100644 index 40850d973324cff56b77b3713c1da34cfe56e717..0000000000000000000000000000000000000000 --- a/common/source/java/ch/systemsx/cisd/common/compression/tiff/AbstractTiffCompressionMethod.java +++ /dev/null @@ -1,83 +0,0 @@ -/* - * Copyright 2008 ETH Zuerich, CISD - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package ch.systemsx.cisd.common.compression.tiff; - -import java.io.File; -import java.util.Arrays; -import java.util.List; - -import ch.systemsx.cisd.common.compression.file.InPlaceCompressionMethod; -import ch.systemsx.cisd.common.exception.ConfigurationFailureException; -import ch.systemsx.cisd.common.exception.EnvironmentFailureException; -import ch.systemsx.cisd.common.fileconverter.TiffCompressionStrategy; - -/** - * A compression method for TIFF files using an <code>executable</code> utility with an option to - * specify compression type. - * - * @deprecated Use {@link TiffCompressionStrategy} instead. - * @author Piotr Buczek - */ -@Deprecated -public abstract class AbstractTiffCompressionMethod extends InPlaceCompressionMethod -{ - - abstract protected String getExecutableName(); - - abstract protected File getExecutable(); - - private final String compressionType; - - public AbstractTiffCompressionMethod(String compressionType) - { - assert compressionType != null; - this.compressionType = compressionType; - } - - public String getCompressionType() - { - return compressionType; - } - - public void setCompressionType(String compressionType) - { - - } - - @Override - final protected List<String> getAcceptedExtensions() - { - return Arrays.asList(".tif", ".tiff"); - } - - @Override - public void check() throws EnvironmentFailureException, ConfigurationFailureException - { - if (getExecutable() == null) - { - throw new ConfigurationFailureException("Cannot find executable of the " - + getExecutableName() + " utility."); - } - } - - @Override - public boolean isRemote() - { - return false; - } - -} diff --git a/common/source/java/ch/systemsx/cisd/common/compression/tiff/TiffCompressor.java b/common/source/java/ch/systemsx/cisd/common/compression/tiff/TiffCompressor.java deleted file mode 100644 index 37242443c3382fcdc6f7d962935d72cb51f49f9d..0000000000000000000000000000000000000000 --- a/common/source/java/ch/systemsx/cisd/common/compression/tiff/TiffCompressor.java +++ /dev/null @@ -1,97 +0,0 @@ -/* - * Copyright 2008 ETH Zuerich, CISD - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package ch.systemsx.cisd.common.compression.tiff; - -import java.util.Collection; - -import ch.systemsx.cisd.common.compression.file.Compressor; -import ch.systemsx.cisd.common.compression.file.FailureRecord; -import ch.systemsx.cisd.common.compression.file.ICompressionMethod; -import ch.systemsx.cisd.common.exception.EnvironmentFailureException; -import ch.systemsx.cisd.common.fileconverter.FileConverter; - -/** - * The main class for tiff file compression. - * - * @deprecated Use {@link FileConverter} instead. - * @author Bernd Rinn - */ -@Deprecated -public class TiffCompressor extends Compressor -{ - public static void main(String[] args) - { - if (args.length != 1) - { - System.err.println("Syntax: TiffCompressor <directory>"); - System.exit(1); - } - - String errorMsgOrNull = tryCompress(args[0]); - if (errorMsgOrNull != null) - { - System.err.print(errorMsgOrNull); - } - } - - private static String tryCompress(String path) - { - try - { - return compress(path, 1, TiffConvertCompressionMethod.create(null)); - } catch (InterruptedException ex) - { - return "Compression was interrupted:" + ex.getMessage(); - } catch (EnvironmentFailureException ex) - { - return ex.getMessage(); - } - } - - /** - * Compresses files in directory with given <var>path</var> with given tiff - * <var>compressionMethod</var>. - * - * @param threadsPerProcessor number of threads performing compression per processor (>0) - * @return error message or null if no error occurred - * @throws InterruptedException if compression was interrupted - * @throws EnvironmentFailureException if there is a problem with specified path - */ - public static String compress(String path, int threadsPerProcessor, - ICompressionMethod compressionMethod) throws InterruptedException, - EnvironmentFailureException - { - assert path != null; - assert compressionMethod != null; - assert threadsPerProcessor > 0; - - final StringBuilder errorMsgBuilder = new StringBuilder(); - final Collection<FailureRecord> failed; - failed = start(path, compressionMethod, threadsPerProcessor); - if (failed.size() > 0) - { - errorMsgBuilder.append("The following files could not bee successfully compressed:\n"); - for (FailureRecord r : failed) - { - errorMsgBuilder.append(String.format("%s (%s)\n", r.getFailedFile().getName(), r - .getFailureStatus())); - } - return errorMsgBuilder.toString(); - } - return null; - } -} diff --git a/common/source/java/ch/systemsx/cisd/common/compression/tiff/TiffConvertCompressionMethod.java b/common/source/java/ch/systemsx/cisd/common/compression/tiff/TiffConvertCompressionMethod.java deleted file mode 100644 index 685908053adcd0c7ebaace08d9691a246737cc37..0000000000000000000000000000000000000000 --- a/common/source/java/ch/systemsx/cisd/common/compression/tiff/TiffConvertCompressionMethod.java +++ /dev/null @@ -1,163 +0,0 @@ -/* - * Copyright 2008 ETH Zuerich, CISD - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package ch.systemsx.cisd.common.compression.tiff; - -import java.io.File; -import java.util.Arrays; -import java.util.List; - -import ch.systemsx.cisd.base.utilities.OSUtilities; -import ch.systemsx.cisd.common.Constants; -import ch.systemsx.cisd.common.exception.ConfigurationFailureException; -import ch.systemsx.cisd.common.exception.EnvironmentFailureException; -import ch.systemsx.cisd.common.fileconverter.TiffCompressionStrategy; -import ch.systemsx.cisd.common.logging.LogInitializer; -import ch.systemsx.cisd.common.process.ProcessExecutionHelper; -import ch.systemsx.cisd.common.process.ProcessIOStrategy; -import ch.systemsx.cisd.common.process.ProcessResult; - -/** - * A compression method for TIFF files using the ImageMagick <code>convert</code> utility with - * specified compression type parameter (by default: <code>LZW</code>). - * - * @deprecated Use {@link TiffCompressionStrategy} instead. - * @author Bernd Rinn - */ -@Deprecated -public class TiffConvertCompressionMethod extends AbstractTiffCompressionMethod -{ - - private final static String executableName = "convert"; - - private final static File executable = OSUtilities.findExecutable(executableName); - - private final static String DEFAULT_COMPRESSION_TYPE = "LZW"; - - private static String getImageMagickVersion(String convertExecutableToCheck) - { - final ProcessResult result = - ProcessExecutionHelper.run(Arrays.asList(convertExecutableToCheck, "--version"), - operationLog, machineLog, Constants.MILLIS_TO_WAIT_BEFORE_TIMEOUT, - ProcessIOStrategy.DEFAULT_IO_STRATEGY, true); - result.log(); - final String versionString = extractImageMagickVersion(result.getOutput().get(0)); - return versionString; - } - - private static String extractImageMagickVersion(String imageMagickVersionLine) - { - if (imageMagickVersionLine.startsWith("Version: ImageMagick") == false) - { - return null; - } else - { - final String[] versionStringParts = imageMagickVersionLine.split("\\s+"); - if (versionStringParts.length < 3) - { - return null; - } - return versionStringParts[2]; - } - } - - /** - * @returns compression method using specified compression type - * @param compressionTypeOrNull compression type to use (if <code>null</code> default - * compression type will be used) - */ - public static TiffConvertCompressionMethod create(String compressionTypeOrNull) - { - return compressionTypeOrNull == null ? new TiffConvertCompressionMethod() - : new TiffConvertCompressionMethod(compressionTypeOrNull); - } - - /** Constructs compression method using default compression type. */ - private TiffConvertCompressionMethod() - { - this(DEFAULT_COMPRESSION_TYPE); - } - - /** Constructs compression method using specified <var>compressonType</var>. */ - private TiffConvertCompressionMethod(String compressionType) - { - super(compressionType); - } - - @Override - protected List<String> createCommandLine(File fileToCompress, File inProgressFile) - { - assert executable != null; - assert fileToCompress != null; - assert fileToCompress.isFile(); - assert inProgressFile != null; - assert inProgressFile.exists() == false; - - final List<String> parameters = - Arrays.asList(executable.getAbsolutePath(), fileToCompress.getAbsolutePath(), - "-compress", getCompressionType(), inProgressFile.getAbsolutePath()); - return parameters; - } - - @Override - public void check() throws EnvironmentFailureException, ConfigurationFailureException - { - super.check(); - final String imageMagickVersionOrNull = getImageMagickVersion(executable.getAbsolutePath()); - if (imageMagickVersionOrNull == null) - { - throw new ConfigurationFailureException("Invalid convert utility"); - } - String[] imageMagickVersionParts = imageMagickVersionOrNull.split("\\."); - if (imageMagickVersionParts.length != 3) - { - throw new ConfigurationFailureException("Invalid convert utility"); - } - final int imageMagickMajorVersion = Integer.parseInt(imageMagickVersionParts[0]); - final int imageMagickMinorVersion = Integer.parseInt(imageMagickVersionParts[1]); - if (imageMagickMajorVersion < 6 || imageMagickMinorVersion < 2) - { - throw ConfigurationFailureException.fromTemplate( - "Convert utility is too old (expected: v6.2 or newer, found: v%s)", - imageMagickVersionOrNull); - } - if (machineLog.isInfoEnabled()) - { - machineLog.info(String.format("Using convert executable '%s', ImageMagick version %s", - executable, imageMagickVersionOrNull)); - } - } - - public static void main(String[] args) - { - LogInitializer.init(); - final TiffConvertCompressionMethod compressor = new TiffConvertCompressionMethod(); - compressor.check(); - } - - @Override - protected File getExecutable() - { - return executable; - } - - @Override - protected String getExecutableName() - { - return executableName; - } - -} diff --git a/common/source/java/ch/systemsx/cisd/common/compression/tiff/TiffCpCompressionMethod.java b/common/source/java/ch/systemsx/cisd/common/compression/tiff/TiffCpCompressionMethod.java deleted file mode 100644 index c9ddf4163ec56ddc4888f48f8af99ac817405496..0000000000000000000000000000000000000000 --- a/common/source/java/ch/systemsx/cisd/common/compression/tiff/TiffCpCompressionMethod.java +++ /dev/null @@ -1,101 +0,0 @@ -/* - * Copyright 2008 ETH Zuerich, CISD - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package ch.systemsx.cisd.common.compression.tiff; - -import java.io.File; -import java.util.Arrays; -import java.util.List; - -import ch.systemsx.cisd.base.utilities.OSUtilities; -import ch.systemsx.cisd.common.fileconverter.TiffCompressionStrategy; -import ch.systemsx.cisd.common.logging.LogInitializer; - -/** - * A compression method for TIFF files using the <code>tiffcp</code> utility with specified - * compression type parameter (by default: <code>lzw:2</code>). - * - * @deprecated Use {@link TiffCompressionStrategy} instead. - * @author Piotr Buczek - */ -@Deprecated -public class TiffCpCompressionMethod extends AbstractTiffCompressionMethod -{ - - private final static String executableName = "tiffcp"; - - private final static File executable = OSUtilities.findExecutable(executableName); - - private final static String DEFAULT_COMPRESSION_TYPE = "lzw:2"; - - /** - * @returns compression method using specified compression type - * @param compressionTypeOrNull compression type to use (if <code>null</code> default - * compression type will be used) - */ - public static TiffCpCompressionMethod create(String compressionTypeOrNull) - { - return compressionTypeOrNull == null ? new TiffCpCompressionMethod() - : new TiffCpCompressionMethod(compressionTypeOrNull); - } - - /** Constructs compression method using default compression type. */ - private TiffCpCompressionMethod() - { - this(DEFAULT_COMPRESSION_TYPE); - } - - /** Constructs compression method using specified <var>compressonType</var>. */ - private TiffCpCompressionMethod(String compressionType) - { - super(compressionType); - } - - @Override - protected List<String> createCommandLine(File fileToCompress, File inProgressFile) - { - assert executable != null; - assert fileToCompress != null; - assert fileToCompress.isFile(); - assert inProgressFile != null; - assert inProgressFile.exists() == false; - - final List<String> parameters = - Arrays.asList(executable.getAbsolutePath(), "-c", getCompressionType(), - fileToCompress.getAbsolutePath(), inProgressFile.getAbsolutePath()); - return parameters; - } - - public static void main(String[] args) - { - LogInitializer.init(); - final TiffCpCompressionMethod compressor = new TiffCpCompressionMethod(); - compressor.check(); - } - - @Override - protected File getExecutable() - { - return executable; - } - - @Override - protected String getExecutableName() - { - return executableName; - } - -}