All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.freefair.gradle.plugins.compress.tasks.CompressorWorkAction Maven / Gradle / Ivy

There is a newer version: 8.11
Show newest version
package io.freefair.gradle.plugins.compress.tasks;

import org.apache.commons.compress.compressors.CompressorOutputStream;
import org.apache.commons.compress.utils.IOUtils;
import org.gradle.workers.WorkAction;

import java.io.*;

@SuppressWarnings("UnstableApiUsage")
public abstract class CompressorWorkAction implements WorkAction

{ @Override public void execute() { File outputFile = getParameters().getTargetFile().getAsFile().get(); File outputDir = outputFile.getParentFile(); if (!outputDir.exists()) { outputDir.mkdirs(); } if (outputDir.exists() || outputDir.mkdirs()) { try ( InputStream in = new FileInputStream(getParameters().getSourceFile().getAsFile().get()); BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(outputFile)); OS compressorStream = createOutputStream(out) ) { IOUtils.copy(in, compressorStream); } catch (IOException e) { throw new RuntimeException(e); } } else { throw new RuntimeException(outputDir + " could not be created"); } } protected abstract OS createOutputStream(BufferedOutputStream outputStream) throws IOException; }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy