Coverage Report - org.codehaus.plexus.archiver.xz.XZCompressor
 
Classes in this File Line Coverage Branch Coverage Complexity
XZCompressor
73%
11/15
100%
2/2
2.667
 
 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.apache.commons.compress.compressors.xz.XZCompressorOutputStream;
 20  
 import org.codehaus.plexus.archiver.ArchiverException;
 21  
 import org.codehaus.plexus.archiver.util.Compressor;
 22  
 import static org.codehaus.plexus.archiver.util.Streams.bufferedOutputStream;
 23  
 import static org.codehaus.plexus.archiver.util.Streams.fileOutputStream;
 24  
 
 25  
 /**
 26  
  * @author philip.lourandos
 27  
  * @since 3.3
 28  
  */
 29  
 public class XZCompressor extends Compressor
 30  
 {
 31  
 
 32  
     private XZCompressorOutputStream xzOut;
 33  
 
 34  
     public XZCompressor()
 35  7
     {
 36  7
     }
 37  
 
 38  
     @Override
 39  
     public void compress() throws ArchiverException
 40  
     {
 41  
         try
 42  
         {
 43  5
             xzOut = new XZCompressorOutputStream( bufferedOutputStream( fileOutputStream( getDestFile() ) ) );
 44  5
             compress( getSource(), xzOut );
 45  
         }
 46  0
         catch ( IOException ioe )
 47  
         {
 48  0
             throw new ArchiverException( "Problem creating xz " + ioe.getMessage(), ioe );
 49  5
         }
 50  5
     }
 51  
 
 52  
     @Override
 53  
     public void close()
 54  
     {
 55  
         try
 56  
         {
 57  7
             if ( this.xzOut != null )
 58  
             {
 59  5
                 this.xzOut.close();
 60  5
                 xzOut = null;
 61  
             }
 62  
         }
 63  0
         catch ( final IOException e )
 64  
         {
 65  0
             throw new ArchiverException( "Failure closing target.", e );
 66  7
         }
 67  7
     }
 68  
 
 69  
 }