Java tutorial
/*- * #%L * simple-compress * %% * Copyright (C) 2016 Thiago Gutenberg Carvalho da Costa * %% * 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. * #L% */ package br.com.thiaguten.archive; import org.apache.commons.compress.archivers.ArchiveEntry; import org.apache.commons.compress.archivers.ArchiveInputStream; import org.apache.commons.compress.archivers.ArchiveOutputStream; import org.apache.commons.compress.archivers.tar.TarArchiveEntry; import org.apache.commons.compress.archivers.tar.TarArchiveInputStream; import org.apache.commons.compress.archivers.tar.TarArchiveOutputStream; import org.apache.commons.compress.compressors.gzip.GzipCompressorInputStream; import org.apache.commons.compress.compressors.gzip.GzipCompressorOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; /** * Gzip Archive Implementation. * * @author Thiago Gutenberg Carvalho da Costa */ public class GzipArchive extends AbstractArchive implements Archive { @Override public String getName() { return "GzipArchive"; } @Override public String getMimeType() { return "application/gzip"; } @Override public String getExtension() { return ".tgz"; } @Override protected ArchiveEntry createArchiveEntry(String path, long size, byte[] content) { TarArchiveEntry targzEntry = new TarArchiveEntry(path); targzEntry.setSize(size); return targzEntry; } @Override protected ArchiveOutputStream createArchiveOutputStream(OutputStream outputStream) throws IOException { return new TarArchiveOutputStream(new GzipCompressorOutputStream(outputStream)); } @Override protected ArchiveInputStream createArchiveInputStream(InputStream inputStream) throws IOException { return new TarArchiveInputStream(new GzipCompressorInputStream(inputStream)); } }