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