View | Details | Raw Unified | Return to bug 195402 | Differences between
and this patch

Collapse All | Expand All

(-)clientserver/org/eclipse/rse/services/clientserver/archiveutils/ArchiveHandlerManager.java (-3 / +49 lines)
Lines 25-30 Link Here
25
import java.lang.reflect.Constructor;
25
import java.lang.reflect.Constructor;
26
import java.lang.reflect.InvocationTargetException;
26
import java.lang.reflect.InvocationTargetException;
27
import java.util.HashMap;
27
import java.util.HashMap;
28
import java.util.Iterator;
28
29
29
/**
30
/**
30
 * This class manages all the Archive Handlers that correspond to the archive file that the system
31
 * This class manages all the Archive Handlers that correspond to the archive file that the system
Lines 40-45 Link Here
40
	public static final String VIRTUAL_SEPARATOR = "#virtual#/"; //$NON-NLS-1$
41
	public static final String VIRTUAL_SEPARATOR = "#virtual#/"; //$NON-NLS-1$
41
	public static final String VIRTUAL_CANONICAL_SEPARATOR = "#virtual#"; //$NON-NLS-1$
42
	public static final String VIRTUAL_CANONICAL_SEPARATOR = "#virtual#"; //$NON-NLS-1$
42
	public static final String VIRTUAL_FOLDER_SEPARATOR = "/"; //$NON-NLS-1$
43
	public static final String VIRTUAL_FOLDER_SEPARATOR = "/"; //$NON-NLS-1$
44
	public static final String EXTENSION_SEPARATOR = "."; //$NON-NLS-1$
43
	
45
	
44
	//	the singleton instance
46
	//	the singleton instance
45
	protected static ArchiveHandlerManager _instance = new ArchiveHandlerManager(); 
47
	protected static ArchiveHandlerManager _instance = new ArchiveHandlerManager(); 
Lines 116-122 Link Here
116
		}
118
		}
117
		else
119
		else
118
		{
120
		{
119
			if (_handlerTypes.containsKey(getExtension(file)))
121
			if (getRegisteredExtension(file)!=null)
120
			{
122
			{
121
				return true;
123
				return true;
122
			}
124
			}
Lines 136-141 Link Here
136
	 */
138
	 */
137
	public boolean isRegisteredArchive(String filename)
139
	public boolean isRegisteredArchive(String filename)
138
	{
140
	{
141
		return getRegisteredExtension(filename) == null?false:true;
142
		//the code below doesn't support extension like fool.tar.gz,
143
		//changed to compare file name against registered extensions
144
		/*
139
		if (_handlerTypes.containsKey(getExtension(filename)))
145
		if (_handlerTypes.containsKey(getExtension(filename)))
140
		{
146
		{
141
			return true;
147
			return true;
Lines 144-156 Link Here
144
		{
150
		{
145
			return false;
151
			return false;
146
		}
152
		}
153
		*/
147
	}	
154
	}	
155
	
156
	/**
157
	 * check if the file extension is registered archive type. 
158
	 * notice here, the getExtension method does't work for name like fool.tar.gz
159
	 * @param file the file to check
160
	 * @return extension or null
161
	 */
162
	protected String getRegisteredExtension(File file) 
163
	{
164
		String fileName = file.getName();
165
		return getRegisteredExtension(fileName);
166
		
167
	}
168
	/**
169
	 * check if the file extension is registered archive type. 
170
	 * notice here, the getExtension method does't work for name like fool.tar.gz
171
	 * @param fileName the file name to check
172
	 * @return extension or null
173
	 */
174
	protected String getRegisteredExtension(String fileName) 
175
	{
176
		Iterator itor = _handlerTypes.keySet().iterator();
177
		while(itor.hasNext()) 
178
		{
179
			String ext = ((String)itor.next()).toLowerCase();
180
			if (fileName.endsWith(EXTENSION_SEPARATOR + ext))
181
			{
182
				return ext;
183
			} 
184
				
185
		}
186
		return null;
187
	}
188
	
148
	/** 
189
	/** 
149
	 * @param file the file whose extension we are computing.
190
	 * @param file the file whose extension we are computing.
150
	 * @return the extension of <code>file</code>. "Extension" is
191
	 * @return the extension of <code>file</code>. "Extension" is
151
	 * defined as any letters in the filename after the last ".". 
192
	 * defined as any letters in the filename after the last ".". 
152
	 * Returns "" if there is no extension.
193
	 * Returns "" if there is no extension.
153
	 */
194
	 */
195
	/*
154
	protected String getExtension(File file)
196
	protected String getExtension(File file)
155
	{
197
	{
156
		String filename = file.getName();
198
		String filename = file.getName();
Lines 158-163 Link Here
158
		if (i == -1) return ""; //$NON-NLS-1$
200
		if (i == -1) return ""; //$NON-NLS-1$
159
		return filename.substring(i+1).toLowerCase();
201
		return filename.substring(i+1).toLowerCase();
160
	}
202
	}
203
	*/
204
	
161
	
205
	
162
	/** 
206
	/** 
163
	 * @param filename the name of the file whose extension we are computing.
207
	 * @param filename the name of the file whose extension we are computing.
Lines 165-176 Link Here
165
	 * defined as any letters in the filename after the last ".". 
209
	 * defined as any letters in the filename after the last ".". 
166
	 * Returns "" if there is no extension.
210
	 * Returns "" if there is no extension.
167
	 */
211
	 */
212
	/*
168
	protected String getExtension(String filename)
213
	protected String getExtension(String filename)
169
	{
214
	{
170
		int i = filename.lastIndexOf("."); //$NON-NLS-1$
215
		int i = filename.lastIndexOf("."); //$NON-NLS-1$
171
		if (i == -1) return ""; //$NON-NLS-1$
216
		if (i == -1) return ""; //$NON-NLS-1$
172
		return filename.substring(i+1).toLowerCase();
217
		return filename.substring(i+1).toLowerCase();
173
	}
218
	}
219
	*/
174
	
220
	
175
	/**
221
	/**
176
	 * Given the absolute path to a virtual object, returns that object
222
	 * Given the absolute path to a virtual object, returns that object
Lines 212-219 Link Here
212
		}
258
		}
213
		else {
259
		else {
214
			// find registered handler based on file's extension
260
			// find registered handler based on file's extension
215
			String ext = getExtension(file);
261
			String ext = getRegisteredExtension(file);
216
			if (!_handlerTypes.containsKey(ext))
262
			if (ext == null)
217
			{
263
			{
218
				//System.out.println("Unknown archive file type: " + ext);
264
				//System.out.println("Unknown archive file type: " + ext);
219
				return null;
265
				return null;
(-)clientserver/org/eclipse/rse/services/clientserver/archiveutils/SystemTarHandler.java (-6 / +19 lines)
Lines 30-35 Link Here
30
import java.io.BufferedReader;
30
import java.io.BufferedReader;
31
import java.io.File;
31
import java.io.File;
32
import java.io.FileInputStream;
32
import java.io.FileInputStream;
33
import java.io.FileNotFoundException;
33
import java.io.FileOutputStream;
34
import java.io.FileOutputStream;
34
import java.io.FilePermission;
35
import java.io.FilePermission;
35
import java.io.IOException;
36
import java.io.IOException;
Lines 1230-1236 Link Here
1230
			
1231
			
1231
					// open a new temp file which will be our destination for the new tar file
1232
					// open a new temp file which will be our destination for the new tar file
1232
					outputTempFile = new File(file.getAbsolutePath() + "temp"); //$NON-NLS-1$
1233
					outputTempFile = new File(file.getAbsolutePath() + "temp"); //$NON-NLS-1$
1233
					outStream = new TarOutputStream(new FileOutputStream(outputTempFile));
1234
					outStream = getTarOutputStream(outputTempFile);
1234
		
1235
		
1235
					// get all the entries in the current tar				  
1236
					// get all the entries in the current tar				  
1236
					VirtualChild[] children = getVirtualChildrenList(archiveOperationMonitor);
1237
					VirtualChild[] children = getVirtualChildrenList(archiveOperationMonitor);
Lines 1670-1676 Link Here
1670
			// open a new temp file which will be our destination for the new tar file
1671
			// open a new temp file which will be our destination for the new tar file
1671
			File outputTempFile = new File(getArchive().getAbsolutePath() + "temp"); //$NON-NLS-1$
1672
			File outputTempFile = new File(getArchive().getAbsolutePath() + "temp"); //$NON-NLS-1$
1672
			
1673
			
1673
			TarOutputStream outStream = new TarOutputStream(new FileOutputStream(outputTempFile));
1674
			TarOutputStream outStream = getTarOutputStream(outputTempFile);
1674
			
1675
			
1675
			// get all the entries
1676
			// get all the entries
1676
			VirtualChild[] children = getVirtualChildrenList(archiveOperationMonitor);
1677
			VirtualChild[] children = getVirtualChildrenList(archiveOperationMonitor);
Lines 1779-1785 Link Here
1779
		
1780
		
1780
				// open a new temp file which will be our destination for the new tar file
1781
				// open a new temp file which will be our destination for the new tar file
1781
				outputTempFile = new File(file.getAbsolutePath() + "temp"); //$NON-NLS-1$
1782
				outputTempFile = new File(file.getAbsolutePath() + "temp"); //$NON-NLS-1$
1782
				TarOutputStream outStream = new TarOutputStream(new FileOutputStream(outputTempFile));
1783
				TarOutputStream outStream = getTarOutputStream(outputTempFile);
1783
			
1784
			
1784
				// get all the entries in the current tar				  
1785
				// get all the entries in the current tar				  
1785
				VirtualChild[] children = getVirtualChildrenList(archiveOperationMonitor);
1786
				VirtualChild[] children = getVirtualChildrenList(archiveOperationMonitor);
Lines 1905-1911 Link Here
1905
			
1906
			
1906
				// open a new temp file which will be our destination for the new tar file
1907
				// open a new temp file which will be our destination for the new tar file
1907
				outputTempFile = new File(file.getAbsolutePath() + "temp"); //$NON-NLS-1$
1908
				outputTempFile = new File(file.getAbsolutePath() + "temp"); //$NON-NLS-1$
1908
				TarOutputStream outStream = new TarOutputStream(new FileOutputStream(outputTempFile));
1909
				TarOutputStream outStream = getTarOutputStream(outputTempFile);
1909
				
1910
				
1910
				// get all the entries
1911
				// get all the entries
1911
				VirtualChild[] children = getVirtualChildrenList(archiveOperationMonitor);
1912
				VirtualChild[] children = getVirtualChildrenList(archiveOperationMonitor);
Lines 2192-2198 Link Here
2192
				
2193
				
2193
				// open a new temp file which will be our destination for the new tar file
2194
				// open a new temp file which will be our destination for the new tar file
2194
				outputTempFile = new File(file.getAbsolutePath() + "temp"); //$NON-NLS-1$
2195
				outputTempFile = new File(file.getAbsolutePath() + "temp"); //$NON-NLS-1$
2195
				outStream = new TarOutputStream(new FileOutputStream(outputTempFile));
2196
				outStream = getTarOutputStream(outputTempFile);
2196
				
2197
				
2197
				// get all the entries
2198
				// get all the entries
2198
				VirtualChild[] children = getVirtualChildrenList(archiveOperationMonitor);
2199
				VirtualChild[] children = getVirtualChildrenList(archiveOperationMonitor);
Lines 2343-2349 Link Here
2343
		try {
2344
		try {
2344
2345
2345
			// create output stream
2346
			// create output stream
2346
			TarOutputStream outStream = new TarOutputStream(new FileOutputStream(file));
2347
			TarOutputStream outStream = getTarOutputStream(file);
2347
			
2348
			
2348
			// close output stream, so we have an empty tar file
2349
			// close output stream, so we have an empty tar file
2349
			outStream.close();
2350
			outStream.close();
Lines 2601-2604 Link Here
2601
			archiveOperationMonitor.setDone(true);
2602
			archiveOperationMonitor.setDone(true);
2602
		}
2603
		}
2603
	}
2604
	}
2605
	
2606
	/**
2607
	 * get the tar output stream from file, 
2608
	 * this method can be override by subclass to return compressed output steam if needed 
2609
	 * @param outputFile the output file to create stream
2610
	 * @return OutputStream the output stream to write 
2611
	 * @throws FileNotFoundException when the output file doesn't exists
2612
	 */
2613
	protected TarOutputStream getTarOutputStream(File outputFile) throws FileNotFoundException {
2614
		TarOutputStream outStream = new TarOutputStream(new FileOutputStream(outputFile));
2615
		return outStream;
2616
	}
2604
}
2617
}
(-)clientserver/org/eclipse/rse/internal/services/clientserver/archiveutils/TarFile.java (-1 / +1 lines)
Lines 195-201 Link Here
195
	 * @return the input stream for the tar file.
195
	 * @return the input stream for the tar file.
196
	 * @throws FileNotFoundException if the file does not exist.
196
	 * @throws FileNotFoundException if the file does not exist.
197
	 */
197
	 */
198
	private InputStream getInputStream() throws FileNotFoundException {
198
	protected InputStream getInputStream() throws FileNotFoundException {
199
		FileInputStream stream = new FileInputStream(file);
199
		FileInputStream stream = new FileInputStream(file);
200
		return stream;
200
		return stream;
201
	}
201
	}
(-)clientserver/org/eclipse/rse/internal/services/clientserver/archiveutils/TgzFile.java (+60 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 Eclipse.org.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 */
8
package org.eclipse.rse.internal.services.clientserver.archiveutils;
9
10
import java.io.File;
11
import java.io.FileNotFoundException;
12
import java.io.IOException;
13
import java.io.InputStream;
14
import java.util.zip.GZIPInputStream;
15
16
/**
17
 * This class is used to read entries from tar.gz file
18
 * It read compressed data from GZIPInputStream
19
 * @author jma
20
 */
21
public class TgzFile extends TarFile {
22
23
	/**
24
	 * Opens a tar.gz file for reading given the specified File object.
25
	 * @param file the tar.gz file to be opened for reading.
26
	 * @throws FileNotFoundException if the file does not exist.
27
	 * @throws IOException if an I/O error occurs.
28
	 */
29
	public TgzFile(File file) throws FileNotFoundException, IOException {
30
		super(file);
31
	}
32
	
33
	/**
34
	 * Opens a tar.gz file for reading given the file name.
35
	 * @param name the name of the tar file to be opened for reading.
36
	 * @throws FileNotFoundException if the file with the given name does not exist.
37
	 * @throws IOException if an I/O error occurs.
38
	 */
39
	public TgzFile(String name) throws FileNotFoundException, IOException {
40
		super(name);
41
	}
42
	
43
	/**
44
	 * Gets the input stream for the tar.gz file.
45
	 * Get file input steam from superclass, wrap it using GZipInputSteam
46
	 * @return the input stream for the tar file.
47
	 * @throws FileNotFoundException if the file does not exist.
48
	 */
49
	protected InputStream getInputStream() throws FileNotFoundException {
50
		InputStream fileInputStream = super.getInputStream();
51
		GZIPInputStream zipInputStream = null;
52
		try{
53
		    zipInputStream = new GZIPInputStream(fileInputStream);
54
		} catch (IOException ioe) {
55
			throw new FileNotFoundException(ioe.getMessage());
56
		}
57
		return zipInputStream;
58
	}
59
60
}
(-)clientserver/org/eclipse/rse/services/clientserver/archiveutils/SystemTgzHandler.java (+48 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008 Eclipse.org.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 */
8
package org.eclipse.rse.services.clientserver.archiveutils;
9
10
import java.io.File;
11
import java.io.IOException;
12
13
import org.eclipse.rse.internal.services.clientserver.archiveutils.TarFile;
14
import org.eclipse.rse.internal.services.clientserver.archiveutils.TgzFile;
15
16
/**
17
 * handler class for .tar.gz and .tgz files
18
 * @author jma
19
 *
20
 */
21
public class SystemTgzHandler extends SystemTarHandler {
22
23
	/**
24
	 * constructor for the tgz handler
25
	 * @param file the .tar.gz or .tgz file
26
	 */
27
	public SystemTgzHandler(File file) throws IOException {
28
	    super(file);
29
	}
30
	
31
	/**
32
	 * Gets a tar.gz file from the underlying file.
33
	 * @return the tar file, or <code>null</code> if the tar file does not exist.
34
	 */
35
	protected TarFile getTarFile() {
36
		
37
		TarFile tarFile = null;
38
		
39
		try {
40
			tarFile = new TgzFile(file);
41
		}
42
		catch (IOException e) {
43
			// TODO: log error
44
		}
45
		
46
		return tarFile;
47
	}
48
}
(-)plugin.xml (+12 lines)
Lines 309-314 Link Here
309
            id="org.eclipse.rse.services.clientserver.archiveutils.systemjarhandler">
309
            id="org.eclipse.rse.services.clientserver.archiveutils.systemjarhandler">
310
      </archivehandler>
310
      </archivehandler>
311
      <archivehandler
311
      <archivehandler
312
            fileNameExtension="tar.gz"
313
            name="SystemTargzHandler"
314
            class="org.eclipse.rse.services.clientserver.archiveutils.SystemTgzHandler"
315
            id="org.eclipse.rse.services.clientserver.archiveutils.systemtargzhandler">
316
      </archivehandler>
317
      <archivehandler
318
            fileNameExtension="tgz"
319
            name="SystemTgzHandler"
320
            class="org.eclipse.rse.services.clientserver.archiveutils.SystemTgzHandler"
321
            id="org.eclipse.rse.services.clientserver.archiveutils.systemtgzhandler">
322
      </archivehandler>
323
      <archivehandler
312
            fileNameExtension="tar"
324
            fileNameExtension="tar"
313
            name="SystemTarHandler"
325
            name="SystemTarHandler"
314
            class="org.eclipse.rse.services.clientserver.archiveutils.SystemTarHandler"
326
            class="org.eclipse.rse.services.clientserver.archiveutils.SystemTarHandler"
(-)miners/org/eclipse/rse/dstore/universal/miners/UniversalFileSystemMiner.java (+2 lines)
Lines 98-103 Link Here
98
		_archiveHandlerManager = ArchiveHandlerManager.getInstance();
98
		_archiveHandlerManager = ArchiveHandlerManager.getInstance();
99
		_archiveHandlerManager.setRegisteredHandler("zip", SystemZipHandler.class); //$NON-NLS-1$
99
		_archiveHandlerManager.setRegisteredHandler("zip", SystemZipHandler.class); //$NON-NLS-1$
100
		_archiveHandlerManager.setRegisteredHandler("jar", SystemJarHandler.class); //$NON-NLS-1$
100
		_archiveHandlerManager.setRegisteredHandler("jar", SystemJarHandler.class); //$NON-NLS-1$
101
		_archiveHandlerManager.setRegisteredHandler("tar.gz", SystemJarHandler.class); //$NON-NLS-1$
102
		_archiveHandlerManager.setRegisteredHandler("tgz", SystemJarHandler.class); //$NON-NLS-1$
101
		_archiveHandlerManager.setRegisteredHandler("tar", SystemTarHandler.class); //$NON-NLS-1$
103
		_archiveHandlerManager.setRegisteredHandler("tar", SystemTarHandler.class); //$NON-NLS-1$
102
	}
104
	}
103
105

Return to bug 195402