76
76
*/
77
77
public class Expand
78
78
{
79
+
79
80
private File dest ;//req
80
81
81
82
private File source ;// req
@@ -99,63 +100,45 @@ public void execute()
99
100
/**
100
101
* Description of the Method
101
102
*/
102
- protected void expandFile ( File srcF , File dir )
103
+ protected void expandFile ( final File srcF , final File dir )
103
104
throws Exception
104
105
{
105
106
ZipInputStream zis = null ;
106
107
try
107
108
{
108
109
// code from WarExpand
109
110
zis = new ZipInputStream ( new FileInputStream ( srcF ) );
110
- ZipEntry ze = null ;
111
111
112
- while ( ( ze = zis .getNextEntry () ) != null )
112
+ for ( ZipEntry ze = zis .getNextEntry (); ze != null ; ze = zis . getNextEntry () )
113
113
{
114
- extractFile ( srcF ,
115
- dir , zis ,
116
- ze .getName (),
117
- new Date ( ze .getTime () ),
118
- ze .isDirectory () );
114
+ extractFile ( srcF , dir , zis , ze .getName (), new Date ( ze .getTime () ), ze .isDirectory () );
119
115
}
120
116
121
117
//log("expand complete", Project.MSG_VERBOSE);
118
+ zis .close ();
119
+ zis = null ;
122
120
}
123
121
catch ( IOException ioe )
124
122
{
125
- throw new Exception ("Error while expanding " + srcF .getPath (), ioe );
123
+ throw new Exception ( "Error while expanding " + srcF .getPath (), ioe );
126
124
}
127
125
finally
128
126
{
129
- if ( zis != null )
130
- {
131
- try
132
- {
133
- zis .close ();
134
- }
135
- catch ( IOException e )
136
- {
137
- }
138
- }
127
+ IOUtil .close ( zis );
139
128
}
140
129
}
141
130
142
131
/**
143
132
* Description of the Method
144
133
*/
145
- protected void extractFile ( File srcF ,
146
- File dir ,
147
- InputStream compressedInputStream ,
148
- String entryName ,
149
- Date entryDate ,
150
- boolean isDirectory )
134
+ protected void extractFile ( File srcF , File dir , InputStream compressedInputStream , String entryName ,
135
+ Date entryDate , boolean isDirectory )
151
136
throws Exception
152
137
{
153
138
File f = FileUtils .resolveFile ( dir , entryName );
154
139
try
155
140
{
156
- if ( !overwrite && f .exists ()
157
- &&
158
- f .lastModified () >= entryDate .getTime () )
141
+ if ( !overwrite && f .exists () && f .lastModified () >= entryDate .getTime () )
159
142
{
160
143
return ;
161
144
}
@@ -170,34 +153,22 @@ protected void extractFile( File srcF,
170
153
}
171
154
else
172
155
{
173
- byte [] buffer = new byte [1024 ];
174
- int length = 0 ;
156
+ byte [] buffer = new byte [ 65536 ];
175
157
FileOutputStream fos = null ;
176
158
try
177
159
{
178
160
fos = new FileOutputStream ( f );
179
161
180
- while ( ( length =
181
- compressedInputStream .read ( buffer ) ) >= 0 )
182
- {
183
- fos .write ( buffer , 0 , length );
184
- }
162
+ for ( int length = compressedInputStream .read ( buffer );
163
+ length >= 0 ;
164
+ fos .write ( buffer , 0 , length ), length = compressedInputStream .read ( buffer ) );
185
165
186
166
fos .close ();
187
167
fos = null ;
188
168
}
189
169
finally
190
170
{
191
- if ( fos != null )
192
- {
193
- try
194
- {
195
- fos .close ();
196
- }
197
- catch ( IOException e )
198
- {
199
- }
200
- }
171
+ IOUtil .close ( fos );
201
172
}
202
173
}
203
174
@@ -239,4 +210,5 @@ public void setOverwrite( boolean b )
239
210
{
240
211
overwrite = b ;
241
212
}
213
+
242
214
}
0 commit comments