Revision 32585 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/Compress.java

View differences:

Compress.java
48 48
public class Compress {
49 49
	static final int BUFFER = 2048;
50 50
	private static final Logger logger = LoggerFactory.getLogger(Compress.class);
51
		
51

  
52 52
	public Compress() {
53 53
		super();		
54 54
	}
......
61 61
		compressPlugins(files, fileNames, os);
62 62
	}
63 63

  
64
	public void compressPlugins(File directory, OutputStream os) throws MakePluginPackageServiceException{
65
		File[] files = directory.listFiles();
66
		List<File> filesArray = new ArrayList<File>();
67
		List<String> fileNamesArray = new ArrayList<String>();
68
		for (int i=0 ; i<files.length ; i++){
69
			filesArray.add(files[i]);
70
			fileNamesArray.add(files[i].getName());
71
		}
72
		compressPlugins(filesArray, fileNamesArray, os);
73
	}
74

  
75

  
64 76
	public void compressPlugins(List<File> files, List<String> fileNames, OutputStream os) throws MakePluginPackageServiceException {
65 77
		try{
66 78
			ZipOutputStream zos = new ZipOutputStream(new BufferedOutputStream(os));
67
					
79

  
68 80
			for (int i=0 ; i<files.size() ; i++){
69 81
				File file = files.get(i);				
70
				
82

  
71 83
				int parentFileLenght = file.getParentFile().toString().length();				
72 84
				
73
				ZipEntry zipEntry = new ZipEntry(fileNames.get(i));				
85
				ZipEntry zipEntry = new ZipEntry(fileNames.get(i));		
74 86
				zos.putNextEntry(zipEntry);								
75
					
87

  
76 88
				ZipOutputStream zosPlugin = new ZipOutputStream(zos);				
77 89
				compressPluginFile(file, parentFileLenght, zosPlugin);				
78 90
				zosPlugin.finish();
79
				
80
				zos.closeEntry();
81
	
82
				zos.close();				
91

  
92
				zos.closeEntry();							
83 93
			}
84 94
			zos.close();
85 95
		} catch (Exception e) {
......
90 100

  
91 101

  
92 102
	private void compressPluginFile(File file, int parenFileLength, ZipOutputStream zosPlugin) throws IOException  {		
103
		String fileName = file.toString().substring(parenFileLength, file.toString().length());
104
		
93 105
		if (file.isDirectory()) {
94
			String[] fileNames = file.list();
95
			if (fileNames != null) {
96
				for (int i=0; i<fileNames.length; i++)  {
97
					compressPluginFile(new File(file, fileNames[i]), parenFileLength, zosPlugin);
106
			//Remove the subversion folders
107
			if (!file.getName().toUpperCase().equals(".SVN")){				
108
				//Adding the files 
109
				String[] fileNames = file.list();
110
				if (fileNames != null) {
111
					for (int i=0; i<fileNames.length; i++)  {
112
						compressPluginFile(new File(file, fileNames[i]), parenFileLength, zosPlugin);
113
					}
98 114
				}
99 115
			}
100 116
		}else{
101 117
			byte[] buf = new byte[1024];
102
			int len;
118
			int len;		
103 119

  
104
			String fileName = file.toString().substring(parenFileLength, file.toString().length());
105
			
106 120
			ZipEntry zipEntry = new ZipEntry(fileName);      
107 121
			zosPlugin.putNextEntry(zipEntry);   
108
			
122

  
109 123
			FileInputStream fin = new FileInputStream(file);
110 124
			BufferedInputStream in = new BufferedInputStream(fin);			    
111 125
			while ((len = in.read(buf)) >= 0) {

Also available in: Unified diff