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 java.io.IOException;
20  import org.codehaus.plexus.archiver.AbstractArchiver;
21  import org.codehaus.plexus.archiver.ArchiveEntry;
22  import org.codehaus.plexus.archiver.ArchiverException;
23  import org.codehaus.plexus.archiver.ResourceIterator;
24  import org.codehaus.plexus.archiver.exceptions.EmptyArchiveException;
25  
26  /**
27   * Snappy archiver.
28   */
29  public class SnappyArchiver
30      extends AbstractArchiver
31  {
32  
33      private SnappyCompressor compressor = new SnappyCompressor();
34  
35      @Override
36      public void execute()
37          throws ArchiverException, IOException
38      {
39          if ( !checkForced() )
40          {
41              return;
42          }
43  
44          ResourceIterator iter = getResources();
45          if ( !iter.hasNext() )
46          {
47              throw new EmptyArchiveException( "archive cannot be empty" );
48          }
49          ArchiveEntry entry = iter.next();
50          if ( iter.hasNext() )
51          {
52              throw new ArchiverException( "There is more than one file in input." );
53          }
54          compressor.setSource( entry.getResource() );
55          compressor.setDestFile( getDestFile() );
56          compressor.compress();
57      }
58  
59      @Override
60      public boolean isSupportingForced()
61      {
62          return true;
63      }
64  
65      @Override
66      protected void close()
67      {
68          compressor.close();
69      }
70  
71      @Override
72      protected String getArchiveType()
73      {
74          return "snappy";
75      }
76  
77  }