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 | 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 | |
|
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 | |
|
134 | |
|
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 | |
} |