Revision 43126 trunk/org.gvsig.desktop/org.gvsig.desktop.library/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
37 37
import java.util.ArrayList;
38 38
import java.util.List;
39 39
import java.util.Map;
40
import java.util.Properties;
40 41
import java.util.zip.ZipEntry;
41 42
import java.util.zip.ZipException;
42 43
import java.util.zip.ZipInputStream;
......
45 46
import org.slf4j.LoggerFactory;
46 47
import org.apache.commons.io.FileUtils;
47 48
import org.apache.commons.io.FilenameUtils;
49
import org.apache.commons.io.IOUtils;
48 50
import org.gvsig.installer.lib.api.PackageInfo;
49 51
import org.gvsig.installer.lib.api.execution.InstallPackageServiceException;
50 52
import org.gvsig.installer.lib.impl.DefaultPackageInfo;
51 53
import org.gvsig.installer.lib.impl.info.InstallerInfoFileReader;
52 54
import org.gvsig.installer.lib.spi.InstallerInfoFileException;
53 55
import org.gvsig.installer.lib.spi.InstallerProviderLocator;
54
import org.gvsig.tools.ToolsLocator;
55 56
import org.gvsig.tools.service.ServiceException;
56 57
import org.gvsig.tools.task.SimpleTaskStatus;
57
import org.gvsig.tools.task.TaskStatusManager;
58 58

  
59 59
/**
60 60
 * @author <a href="mailto:jpiera@gvsig.org">Jorge Piera Llodr&aacute;</a>
......
77 77
	private List<PackageInfo> selectedInstallerInfos = null;
78 78
	private Map<PackageInfo, String> zipEntriesMap = null;
79 79
	private List<String> defaultSelectedPackets = null;
80

  
80
        private Properties properties;
81
        private SimpleTaskStatus taskStatus = null;
82
        
81 83
	public Decompress() {
82

  
84
            this.properties = new Properties();
83 85
	}
84

  
86
        
87
	public Decompress(SimpleTaskStatus taskStatus) {
88
            this();
89
            this.taskStatus = taskStatus;
90
        }
91
        
85 92
	public void decompressPlugins(InputStream is, File outputDirectory)
86 93
			throws InstallPackageServiceException {
87 94
		option = OPTION_DECOMPRESS;
......
231 238

  
232 239
					defaultSelectedPackets = defaultPackagesList;
233 240
					out.flush();
234
				} else {
241
                                } else if (entry.getName().equals("packages.properties") ) {
242
                                    int count;
243
                                    byte data[] = new byte[BUFFER];
244
                                    ByteArrayOutputStream out = new ByteArrayOutputStream();
245

  
246
                                    while ((count = zipInputStream.read(data, 0, BUFFER)) != -1) {
247
                                            out.write(data, 0, count);
248
                                    }
249
                                    InputStream in = new ByteArrayInputStream(out.toByteArray());
250
                                    properties.load(in);
251
                                    IOUtils.closeQuietly(in);
252
                                    IOUtils.closeQuietly(out);
253
                                } else {
235 254
//					logger.debug("Extracting all Plugins, plugin: " + name);
236 255
					if (option == OPTION_INSTALL) {
237 256

  
......
318 337
		byte data[] = new byte[BUFFER];
319 338
		int count = 0;
320 339

  
321
		TaskStatusManager manager = ToolsLocator.getTaskStatusManager();
322
		SimpleTaskStatus taskStatus = manager
323
				.createDefaultSimpleTaskStatus("Uncompressing...");
324
		
325
		manager.add(taskStatus);
326 340
		int countRootFolders = 0;
327 341
		String entryName = "(header)";
328 342
		try {
329 343
			long readed = 0;
330
	
331
			// // First read all the contents size
332
			// zis = new ZipInputStream(inputStream);
333
			// while ((entry = zis.getNextEntry()) != null) {
334
			// count += entry.getSize();
335
			// }
336
			// // zis.close();
337
			// taskStatus.setRangeOfValues(0, count);
338
	
339
			// Return the stream to the initial position
344
                        if( taskStatus!=null ) {
345
                            taskStatus.push();
346
                        }
340 347
			zis = new ZipInputStream(inputStream);
341 348
			while ((entry = zis.getNextEntry()) != null) {
342 349
				entryName = FilenameUtils.separatorsToSystem(entry.getName());
343
				taskStatus.message(entryName);
350
                                if( taskStatus!=null ) {
351
                                    taskStatus.message(entryName);
352
                                }
344 353
	
345 354
				File file = new File(outputDirectory, entryName);
346 355
				if (file.exists()) {
......
365 374
					while ((count = zis.read(data, 0, BUFFER)) != -1) {
366 375
						fos.write(data, 0, count);
367 376
						readed += count;
368
						taskStatus.setCurValue(readed);
377
                                                if( taskStatus!=null ) {
378
                                                    taskStatus.setCurValue(readed);
379
                                                }
369 380
					}
370 381
					fos.flush();
371 382
					fos.close();
......
379 390
		} catch(RuntimeException ex) {
380 391
			logger.warn("Problems uncompresing plugin (last entry '"+entryName+"'.",ex);
381 392
			throw ex;
382
			
383
		} finally {
384
		    
385
		    taskStatus.remove();
386
		    
387
		}
388
		
389
        
393
                } finally {
394
                    if( taskStatus!=null ) {
395
                        taskStatus.pop();
396
                    }
397
                }
390 398
	}
391 399

  
392 400
	private void createParentFolder(File file) {
......
435 443
		InstallerInfoFileReader installerInfoFileReader = new InstallerInfoFileReader();
436 444
		installerInfoFileReader.read(installerInfo, new ByteArrayInputStream(
437 445
				out.toByteArray()));
438

  
446
                if( taskStatus!=null ) {                
447
                    taskStatus.message(installerInfo.getName());
448
                }
439 449
		return installerInfo;
440 450
	}
441 451

  
......
447 457
	public List<String> getDefaultSelectedPackages() {
448 458
		return defaultSelectedPackets;
449 459
	}
460
        
461
	public Properties getProperties() {
462
		return properties;
463
	}
450 464
}

Also available in: Unified diff