1   package org.apache.maven.wagon;
2   
3   
4   
5   
6   
7   
8   
9   
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
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  
33  
34  
35  
36  
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      {
49          this.file = new File( filename );
50      }
51  
52      public LazyFileOutputStream( File file )
53      {
54          this.file = file;
55      }
56  
57  
58      public void close()
59          throws IOException
60      {
61          if ( delegee != null )
62          {
63              delegee.close();
64          }
65      }
66  
67  
68      public boolean equals( Object obj )
69      {
70          return delegee.equals( obj );
71      }
72  
73  
74      public void flush()
75          throws IOException
76      {
77          if ( delegee != null )
78          {
79              delegee.flush();
80          }
81      }
82  
83  
84      public FileChannel getChannel()
85      {
86          return delegee.getChannel();
87      }
88  
89  
90      public FileDescriptor getFD()
91          throws IOException
92      {
93          return delegee.getFD();
94      }
95  
96      public int hashCode()
97      {
98          return delegee.hashCode();
99      }
100 
101 
102     public String toString()
103     {
104         return delegee.toString();
105     }
106 
107     public void write( byte[] b )
108         throws IOException
109     {
110         if ( delegee == null )
111         {
112             initialize();
113         }
114 
115         delegee.write( b );
116     }
117 
118     
119 
120 
121     public void write( byte[] b, int off, int len )
122         throws IOException
123     {
124         if ( delegee == null )
125         {
126             initialize();
127         }
128 
129         delegee.write( b, off, len );
130     }
131 
132     
133 
134 
135 
136     public void write( int b )
137         throws IOException
138     {
139         if ( delegee == null )
140         {
141             initialize();
142         }
143 
144         delegee.write( b );
145     }
146 
147 
148     
149 
150 
151     private void initialize()
152         throws FileNotFoundException
153     {
154         delegee = new FileOutputStream( file );
155     }
156 }