Revision 35006 branches/v2_0_0_prep/extensions/org.gvsig.installer/org.gvsig.installer.lib/org.gvsig.installer.lib.impl/src/main/java/org/gvsig/installer/lib/impl/utils/Decompress.java

View differences:

Decompress.java
110 110
        try {
111 111
            option = OPTION_DECOMPRESS;
112 112
            this.outputDirectory = outputDirectory;
113
            decompressPlugin(new ZipInputStream(is));
113
            decompressPlugin(is);
114 114
        } catch (Exception e) {
115 115
            throw new InstallPackageServiceException(
116 116
                "Error reading the plugin", e);
......
166 166
                logger.debug("Extracting all Plugins, plugin: " + entry);
167 167
                if (option == OPTION_INSTALL) {
168 168

  
169
                } else
169
                } else {
170 170
                    if (option == OPTION_DECOMPRESS) {
171
                        decompressPlugin(new ZipInputStream(zipInputStream));
172
                    } else
173
                        if (option == OPTION_READ_INSTALLINFO) {
174
                            readPlugin(new ZipInputStream(zipInputStream),
175
                                entry.getName());
176
                        }
171
                        decompressPlugin(zipInputStream);
172
                    } else if (option == OPTION_READ_INSTALLINFO) {
173
                        readPlugin(zipInputStream, entry.getName());
174
                    }
175
                }
177 176
                zipInputStream.closeEntry();
178 177
            }
179 178
            zipInputStream.close();
......
186 185

  
187 186
    private void decompressFolderOfPluginFromPackage(InputStream is, String name)
188 187
        throws InstallPackageServiceException {
189
        ZipInputStream zipInputStream = new ZipInputStream(is);
190 188

  
191 189
        try {
192 190
            if (option == OPTION_INSTALL) {
193 191

  
194 192
            } else {
195 193
                if (option == OPTION_DECOMPRESS) {
196
                    decompressPlugin(zipInputStream);
194
                    decompressPlugin(is);
197 195
                } else {
198 196
                    if (option == OPTION_READ_INSTALLINFO) {
199
                        readPlugin(zipInputStream, name);
197
                        readPlugin(is, name);
200 198
                    }
201 199
                }
202 200
            }
203
            zipInputStream.close();
204 201

  
205 202
        } catch (Exception e) {
206 203
            throw new InstallPackageServiceException(
......
208 205
        }
209 206
    }
210 207

  
211
    private void readPlugin(ZipInputStream zipInputStream, String zipEntryName)
208
    private void readPlugin(InputStream is, String zipEntryName)
212 209
        throws ZipException, IOException, InstallerInfoFileException {
213 210
        ZipEntry entry = null;
214 211
        int installerInfoNumber = zipEntriesMap.size();
215 212
        String packageInfoName = getPackageInfoFileName();
216 213
        String unixPackageInfoPath = "/".concat(packageInfoName);
217 214
        String windowsPackageInfoPath = "\\".concat(packageInfoName);
218
        while ((entry = zipInputStream.getNextEntry()) != null) {
215
        ZipInputStream zis = new ZipInputStream(is);
216
        while ((entry = zis.getNextEntry()) != null) {
219 217
            logger.debug("Extracting: " + entry.getName());
220 218

  
221 219
            String name = entry.getName();
......
223 221
            // the unix file separator
224 222
            if (name.endsWith(unixPackageInfoPath)
225 223
                || name.endsWith(windowsPackageInfoPath)) {
226
                PackageInfo installerInfo = readInstallInfo(zipInputStream);
224
                PackageInfo installerInfo = readInstallInfo(zis);
227 225
                zipEntriesMap.put(installerInfo, zipEntryName);
228 226
                readedIinstallerInfos.add(installerInfo);
229 227
            }
230
            zipInputStream.closeEntry();
228
            zis.closeEntry();
231 229
        }
232
        // zipInputStream.close();
230
        // Don't close the stream as if it is a zip file contained 
231
        // into another zip file, closing of the child Zip?nputStream
232
        // will close also the parent's.
233
//        zis.close();
233 234

  
234 235
        if (installerInfoNumber == zipEntriesMap.size()) {
235 236
            PackageInfo installerInfo = new DefaultPackageInfo();
......
240 241
        }
241 242
    }
242 243

  
243
    private void decompressPlugin(ZipInputStream zipInputStream)
244
    private void decompressPlugin(InputStream inputStream)
244 245
        throws ZipException, IOException, InstallerInfoFileException {
246
        ZipInputStream zis = null;
245 247
        ZipEntry entry = null;
246 248
        byte data[] = new byte[BUFFER];
247 249
        int count = 0;
......
252 254
        manager.add(taskStatus);
253 255
        long readed = 0;
254 256

  
255
        while ((entry = zipInputStream.getNextEntry()) != null) {
256
            count += entry.getSize();
257
        }
258
        taskStatus.setRangeOfValues(0, count);
257
//        // First read all the contents size
258
//        zis = new ZipInputStream(inputStream);
259
//        while ((entry = zis.getNextEntry()) != null) {
260
//            count += entry.getSize();
261
//        }
262
////        zis.close();
263
//        taskStatus.setRangeOfValues(0, count);
259 264

  
260
        while ((entry = zipInputStream.getNextEntry()) != null) {
265
        // Return the stream to the initial position
266
        zis = new ZipInputStream(inputStream);
267
        while ((entry = zis.getNextEntry()) != null) {
261 268
            String entryName = entry.getName();
262 269
            taskStatus.message(entryName);
263 270

  
......
277 284
            } else {
278 285
                createParentFolder(file);
279 286
                FileOutputStream fos = new FileOutputStream(file);
280
                while ((count = zipInputStream.read(data, 0, BUFFER)) != -1) {
287
                while ((count = zis.read(data, 0, BUFFER)) != -1) {
281 288
                    fos.write(data, 0, count);
282 289
                    readed += count;
283 290
                    taskStatus.setCurValue(readed);
......
286 293
                fos.close();
287 294
            }
288 295
        }
296
        zis.close();
289 297
        taskStatus.remove();
290 298
    }
291 299

  

Also available in: Unified diff