Coverage Report - org.apache.maven.wagon.LazyFileOutputStream
 
Classes in this File Line Coverage Branch Coverage Complexity
LazyFileOutputStream
61%
19/31
70%
7/10
1,385
 
 1  
 package org.apache.maven.wagon;
 2  
 
 3  
 /*
 4  
  * Licensed to the Apache Software Foundation (ASF) under one
 5  
  * or more contributor license agreements.  See the NOTICE file
 6  
  * distributed with this work for additional information
 7  
  * regarding copyright ownership.  The ASF licenses this file
 8  
  * to you under the Apache License, Version 2.0 (the
 9  
  * "License"); you may not use this file except in compliance
 10  
  * with the License.  You may obtain a copy of the License at
 11  
  *
 12  
  *   http://www.apache.org/licenses/LICENSE-2.0
 13  
  *
 14  
  * Unless required by applicable law or agreed to in writing,
 15  
  * software distributed under the License is distributed on an
 16  
  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 17  
  * KIND, either express or implied.  See the License for the
 18  
  * specific language governing permissions and limitations
 19  
  * under the License.
 20  
  */
 21  
 
 22  
 import java.io.File;
 23  
 import java.io.FileDescriptor;
 24  
 import java.io.FileNotFoundException;
 25  
 import java.io.FileOutputStream;
 26  
 import java.io.IOException;
 27  
 import java.io.OutputStream;
 28  
 import java.nio.channels.FileChannel;
 29  
 
 30  
 
 31  
 /**
 32  
  * Variant of FileOutputStream which creates the file only when first portion
 33  
  * of data is written.
 34  
  *
 35  
  * @author <a href="mailto:mmaczka@interia.pl">Michal Maczka</a>
 36  
  * @version $Id: LazyFileOutputStream.java 668181 2008-06-16 15:05:52Z brett $
 37  
  */
 38  
 public class LazyFileOutputStream
 39  
     extends OutputStream
 40  
 {
 41  
 
 42  
     private File file;
 43  
 
 44  
     private FileOutputStream delegee;
 45  
 
 46  
 
 47  
     public LazyFileOutputStream( String filename )
 48  0
     {
 49  0
         this.file = new File( filename );
 50  0
     }
 51  
 
 52  
     public LazyFileOutputStream( File file )
 53  7
     {
 54  7
         this.file = file;
 55  7
     }
 56  
 
 57  
 
 58  
     public void close()
 59  
         throws IOException
 60  
     {
 61  7
         if ( delegee != null )
 62  
         {
 63  3
             delegee.close();
 64  
         }
 65  7
     }
 66  
 
 67  
 
 68  
     public boolean equals( Object obj )
 69  
     {
 70  0
         return delegee.equals( obj );
 71  
     }
 72  
 
 73  
 
 74  
     public void flush()
 75  
         throws IOException
 76  
     {
 77  3
         if ( delegee != null )
 78  
         {
 79  2
             delegee.flush();
 80  
         }
 81  3
     }
 82  
 
 83  
 
 84  
     public FileChannel getChannel()
 85  
     {
 86  0
         return delegee.getChannel();
 87  
     }
 88  
 
 89  
 
 90  
     public FileDescriptor getFD()
 91  
         throws IOException
 92  
     {
 93  0
         return delegee.getFD();
 94  
     }
 95  
 
 96  
     public int hashCode()
 97  
     {
 98  0
         return delegee.hashCode();
 99  
     }
 100  
 
 101  
 
 102  
     public String toString()
 103  
     {
 104  0
         return delegee.toString();
 105  
     }
 106  
 
 107  
     public void write( byte[] b )
 108  
         throws IOException
 109  
     {
 110  1
         if ( delegee == null )
 111  
         {
 112  1
             initialize();
 113  
         }
 114  
 
 115  1
         delegee.write( b );
 116  1
     }
 117  
 
 118  
     /**
 119  
      * @see java.io.OutputStream#write(byte[], int, int)
 120  
      */
 121  
     public void write( byte[] b, int off, int len )
 122  
         throws IOException
 123  
     {
 124  6
         if ( delegee == null )
 125  
         {
 126  2
             initialize();
 127  
         }
 128  
 
 129  6
         delegee.write( b, off, len );
 130  6
     }
 131  
 
 132  
     /**
 133  
      * @param b
 134  
      * @throws java.io.IOException
 135  
      */
 136  
     public void write( int b )
 137  
         throws IOException
 138  
     {
 139  0
         if ( delegee == null )
 140  
         {
 141  0
             initialize();
 142  
         }
 143  
 
 144  0
         delegee.write( b );
 145  0
     }
 146  
 
 147  
 
 148  
     /**
 149  
      * 
 150  
      */
 151  
     private void initialize()
 152  
         throws FileNotFoundException
 153  
     {
 154  3
         delegee = new FileOutputStream( file );
 155  3
     }
 156  
 }