Revision 32411 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/execution/Decompress.java

View differences:

Decompress.java
152 152
				logger.debug("Extracting all Plugins, plugin: " + entry);
153 153
				if (option == OPTION_INSTALL){
154 154

  
155
				}else{				
155
				}else if (option == OPTION_DECOMPRESS){				
156 156
					decompressPlugin(new ZipInputStream(zipInputStream), entry.getName());
157
				}else if (option == OPTION_READ_INSTALLINFO){			
158
					readPlugin(new ZipInputStream(zipInputStream), entry.getName());
157 159
				}
158 160
				zipInputStream.closeEntry();
159 161
			}
......
165 167
		} 			
166 168
	}
167 169

  
170
	private void readPlugin(ZipInputStream zipInputStream, String zipEntryName) throws ZipException, IOException, InstallerInfoFileException{
171
		ZipEntry entry = null;
172
		byte data[] = new byte[BUFFER];		
173
		int count;
174
		int installerInfoNumber = zipEntriesMap.size();
175

  
176
		while((entry = zipInputStream.getNextEntry()) != null) {			        
177
			logger.debug("Extracting: " + entry.getName());	
178

  
179
			if (entry.getName().endsWith(File.separator + DefaultInstallerCreationService.INSTALLINFO_FILE_NAME)){
180
				InstallerInfo installerInfo = readInstallInfo(zipInputStream);
181
				zipEntriesMap.put(installerInfo, zipEntryName);			
182
				readedIinstallerInfos.add(installerInfo);					
183
			}
184
			zipInputStream.closeEntry();
185
		}	
186
		
187
		if (installerInfoNumber == zipEntriesMap.size()){
188
			InstallerInfo installerInfo = new DefaultInstallerInfo();
189
			installerInfo.setCode(zipEntryName);
190
			installerInfo.setName(zipEntryName);
191
			zipEntriesMap.put(installerInfo, zipEntryName);
192
			readedIinstallerInfos.add(installerInfo);		
193
		}
194
	}
195

  
196

  
168 197
	private void decompressPlugin(ZipInputStream zipInputStream, String zipEntryName) throws ZipException, IOException, InstallerInfoFileException{
169 198
		ZipEntry entry = null;
170 199
		byte data[] = new byte[BUFFER];		
171 200
		int count;
201
		int installerInfoNumber = 0;
172 202

  
203
		if (zipEntriesMap != null){
204
			installerInfoNumber = zipEntriesMap.size();
205
		}
206

  
173 207
		while((entry = zipInputStream.getNextEntry()) != null) {			        
174 208
			logger.debug("Extracting: " + entry.getName());	
175
			if (option == OPTION_DECOMPRESS){
176
				File file = new File(outputDirectory.getAbsolutePath() + File.separator + entry.getName());
177
				if (file.exists()){
178
					delete(file);
179
				}
180
				if (entry.isDirectory()){
181
					file.mkdir();
182
				}else{
183
					FileOutputStream fos = new FileOutputStream(outputDirectory.getAbsolutePath() + File.separator + entry.getName());
184 209

  
185
					while ((count = zipInputStream.read(data, 0, BUFFER)) != -1) {
186
						fos.write(data, 0, count);
187
					}
188
					fos.flush();		
189
					fos.close();	
210
			File file = new File(outputDirectory.getAbsolutePath() + File.separator + entry.getName());
211
			if (file.exists()){
212
				delete(file);
213
			}
214
			if (entry.isDirectory()){
215
				file.mkdir();
216
			}else{
217
				FileOutputStream fos = new FileOutputStream(outputDirectory.getAbsolutePath() + File.separator + entry.getName());
218

  
219
				while ((count = zipInputStream.read(data, 0, BUFFER)) != -1) {
220
					fos.write(data, 0, count);
190 221
				}
191
			}else if (option == OPTION_READ_INSTALLINFO){
192
				if (entry.getName().endsWith(File.separator + DefaultInstallerCreationService.INSTALLINFO_FILE_NAME)){
193
					InstallerInfo installerInfo = readInstallInfo(zipInputStream);
194
					if (zipEntriesMap != null){
195
						zipEntriesMap.put(installerInfo, zipEntryName);
196
					}
197
					readedIinstallerInfos.add(installerInfo);					
198
				}
199

  
222
				fos.flush();		
223
				fos.close();	
200 224
			}
201 225
			zipInputStream.closeEntry();
202
		}		
226
		}
203 227
	}	
204 228

  
205 229
	public boolean delete(File dir) { 

Also available in: Unified diff