|
| 1 | +/* |
| 2 | + * Copyright 2016 Codehaus. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | +package org.codehaus.plexus.archiver.xz; |
| 17 | + |
| 18 | +import java.io.IOException; |
| 19 | +import org.codehaus.plexus.archiver.AbstractArchiver; |
| 20 | +import org.codehaus.plexus.archiver.ArchiveEntry; |
| 21 | +import org.codehaus.plexus.archiver.ArchiverException; |
| 22 | +import org.codehaus.plexus.archiver.ResourceIterator; |
| 23 | + |
| 24 | +/** |
| 25 | + * |
| 26 | + * @author philiplourandos |
| 27 | + */ |
| 28 | +public class XZArchiver extends AbstractArchiver { |
| 29 | + |
| 30 | + private final XZCompressor compressor = new XZCompressor(); |
| 31 | + |
| 32 | + public XZArchiver() |
| 33 | + { |
| 34 | + } |
| 35 | + |
| 36 | + @Override |
| 37 | + protected void execute() throws ArchiverException, IOException |
| 38 | + { |
| 39 | + if ( !checkForced()) |
| 40 | + { |
| 41 | + return; |
| 42 | + } |
| 43 | + |
| 44 | + ResourceIterator iter = getResources(); |
| 45 | + ArchiveEntry entry = iter.next(); |
| 46 | + if ( iter.hasNext() ) |
| 47 | + { |
| 48 | + throw new ArchiverException( "There is more than one file in input." ); |
| 49 | + } |
| 50 | + compressor.setSource( entry.getResource() ); |
| 51 | + compressor.setDestFile( getDestFile() ); |
| 52 | + compressor.compress(); |
| 53 | + } |
| 54 | + |
| 55 | + @Override |
| 56 | + public boolean isSupportingForced() |
| 57 | + { |
| 58 | + return true; |
| 59 | + } |
| 60 | + |
| 61 | + @Override |
| 62 | + protected void close() throws IOException |
| 63 | + { |
| 64 | + compressor.close(); |
| 65 | + } |
| 66 | + |
| 67 | + @Override |
| 68 | + protected String getArchiveType() |
| 69 | + { |
| 70 | + return "xz"; |
| 71 | + } |
| 72 | +} |
0 commit comments