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 java.io.IOException; import java.io.InputStream; import java.io.OutputStream; /** * Tar Archive Implementation. * * @author Thiago Gutenberg Carvalho da Costa */ public class TarArchive extends AbstractArchive implements Archive { @Override public String getName() { return "TarArchive"; } @Override public String getMimeType() { return "application/x-tar"; } @Override public String getExtension() { return ".tar"; } @Override protected ArchiveEntry createArchiveEntry(String path, long size, byte[] content) { TarArchiveEntry tarEntry = new TarArchiveEntry(path); tarEntry.setSize(size); return tarEntry; } @Override protected ArchiveOutputStream createArchiveOutputStream(OutputStream outputStream) throws IOException { return new TarArchiveOutputStream(outputStream); } @Override protected ArchiveInputStream createArchiveInputStream(InputStream inputStream) throws IOException { return new TarArchiveInputStream(inputStream); } }