From 7ba4eede2a9a3fee6990d7fff4370ec89c475a44 Mon Sep 17 00:00:00 2001 From: Martin Oberhuber < martin.oberhuber@windriver.com> Date: Fri, 28 Mar 2008 13:08:44 +0000 Subject: [PATCH] [cleanup] add API "since" tags --- rse/plugins/org.eclipse.rse.services/.project | 6 + .../archiveutils/ArchiveHandlerManager.java | 159 ++- .../archiveutils/ISystemArchiveHandler.java | 500 ++++--- .../archiveutils/SystemTarHandler.java | 1263 +++++++++-------- .../archiveutils/SystemTgzHandler.java | 1 - .../archiveutils/SystemZipHandler.java | 874 ++++++------ .../archiveutils/TarOutputStream.java | 46 +- .../ISystemProcessRemoteConstants.java | 30 +- .../rse/services/files/IFileService.java | 462 +++--- .../services/search/IHostSearchConstants.java | 4 +- 10 files changed, 1855 insertions(+), 1490 deletions(-) rename rse/plugins/org.eclipse.rse.services/clientserver/org/eclipse/rse/{internal => }/services/clientserver/archiveutils/TarOutputStream.java (92%) diff --git a/rse/plugins/org.eclipse.rse.services/.project b/rse/plugins/org.eclipse.rse.services/.project index fe86041f3a4..a1aed60f30b 100644 --- a/rse/plugins/org.eclipse.rse.services/.project +++ b/rse/plugins/org.eclipse.rse.services/.project @@ -20,9 +20,15 @@ + + org.eclipse.pde.api.tools.apiAnalysisBuilder + + + org.eclipse.pde.PluginNature org.eclipse.jdt.core.javanature + org.eclipse.pde.api.tools.apiAnalysisNature diff --git a/rse/plugins/org.eclipse.rse.services/clientserver/org/eclipse/rse/services/clientserver/archiveutils/ArchiveHandlerManager.java b/rse/plugins/org.eclipse.rse.services/clientserver/org/eclipse/rse/services/clientserver/archiveutils/ArchiveHandlerManager.java index 8ebcb962d24..4fb16b9337c 100644 --- a/rse/plugins/org.eclipse.rse.services/clientserver/org/eclipse/rse/services/clientserver/archiveutils/ArchiveHandlerManager.java +++ b/rse/plugins/org.eclipse.rse.services/clientserver/org/eclipse/rse/services/clientserver/archiveutils/ArchiveHandlerManager.java @@ -7,8 +7,8 @@ * * Initial Contributors: * The following IBM employees contributed to the Remote System Explorer - * component that contains this file: David McKnight, Kushal Munir, - * Michael Berger, David Dykstal, Phil Coulthard, Don Yantzi, Eric Simpson, + * component that contains this file: David McKnight, Kushal Munir, + * Michael Berger, David Dykstal, Phil Coulthard, Don Yantzi, Eric Simpson, * Emily Bruner, Mazen Faraj, Adrian Storisteanu, Li Ding, and Kent Hawley. * * Contributors: @@ -35,23 +35,38 @@ import java.util.Iterator; * to use statements of the form "ArchiveHandlerManager.getInstance().method". * @author mjberger */ -public class ArchiveHandlerManager +public class ArchiveHandlerManager { - // The string that separates the virtual part of an absolute path from the real part + /** + * The string that separates the virtual part of an absolute path from the + * real part. + */ public static final String VIRTUAL_SEPARATOR = "#virtual#/"; //$NON-NLS-1$ public static final String VIRTUAL_CANONICAL_SEPARATOR = "#virtual#"; //$NON-NLS-1$ + /** + * Folder separator used in virtual paths inside the archive, i.e. after the + * VIRTUAL_SEPARATOR. + * + * @since org.eclipse.rse.services 3.0 + */ public static final String VIRTUAL_FOLDER_SEPARATOR = "/"; //$NON-NLS-1$ + /** + * Character used to separate file extension from file name. This is used in + * order to recognize file patterns that should be treated as archives. + * + * @since org.eclipse.rse.services 3.0 + */ public static final String EXTENSION_SEPARATOR = "."; //$NON-NLS-1$ - + // the singleton instance - protected static ArchiveHandlerManager _instance = new ArchiveHandlerManager(); + protected static ArchiveHandlerManager _instance = new ArchiveHandlerManager(); // a mapping from Files to ISystemArchiveHandlers protected HashMap _handlers; - + // a mapping from Strings (file extensions) to Classes (the type of handler to use) protected HashMap _handlerTypes; - + /** * @return The singleton instance of this class. */ @@ -59,7 +74,7 @@ public class ArchiveHandlerManager { return _instance; } - + public ArchiveHandlerManager() { _handlers = new HashMap(); @@ -72,18 +87,18 @@ public class ArchiveHandlerManager * @param virtualpath The parent virtual object whose children this method is to return. To * get the top level virtualchildren in the archive, set virtualpath to "" or null. * @return An array of VirtualChild objects representing the children of the virtual object - * in file referred to by virtualpath. If no class implementing + * in file referred to by virtualpath. If no class implementing * ISystemArchiveHandler can be found that corresponds to file, then this method returns null. * If the virtual object has no children, this method also returns null. * @throws IOException if there was a problem getting the registered handler for the * file. This usually means the archive is corrupted. - */ + */ public VirtualChild[] getContents(File file, String virtualpath) throws IOException { if (virtualpath == null) virtualpath = ""; //$NON-NLS-1$ ISystemArchiveHandler handler = getRegisteredHandler(file); - if (handler == null || !handler.exists()) throw new IOException(); - return handler.getVirtualChildren(virtualpath, null); + if (handler == null || !handler.exists()) throw new IOException(); + return handler.getVirtualChildren(virtualpath, null); } /** @@ -92,18 +107,18 @@ public class ArchiveHandlerManager * @param virtualpath The parent virtual object whose children this method is to return. To * get the top level virtualchildren in the archive, set virtualpath to "" or null. * @return An array of VirtualChild objects representing the children of the virtual object - * in file referred to by virtualpath that are themselves folders. - * If no class implementing ISystemArchiveHandler can be found that corresponds to file, then + * in file referred to by virtualpath that are themselves folders. + * If no class implementing ISystemArchiveHandler can be found that corresponds to file, then * this method returns null. If the virtual object has no children, this method also returns null. - */ + */ public VirtualChild[] getFolderContents(File file, String virtualpath) { if (virtualpath == null) virtualpath = ""; //$NON-NLS-1$ ISystemArchiveHandler handler = getRegisteredHandler(file); if (handler == null) return null; - return handler.getVirtualChildFolders(virtualpath, null); + return handler.getVirtualChildFolders(virtualpath, null); } - + /** * Tests whether a file is an known type of archive. * @param file the file to test. @@ -127,9 +142,9 @@ public class ArchiveHandlerManager return false; } } - + } - + /** * Tests whether a file is an known type of archive, based on the file name. * @param filename the name of the file to test. @@ -139,47 +154,47 @@ public class ArchiveHandlerManager public boolean isRegisteredArchive(String filename) { return getRegisteredExtension(filename) == null?false:true; - } - + } + /** - * check if the file extension is registered archive type. + * Check if the file extension is registered archive type. * notice here, the getExtension method does't work for name like fool.tar.gz * @param file the file to check * @return registered extension or null - * @since 3.0 + * @since org.eclipse.rse.services 3.0 */ - protected String getRegisteredExtension(File file) + protected String getRegisteredExtension(File file) { String fileName = file.getName(); return getRegisteredExtension(fileName); } - + /** - * check if the file extension is registered archive type. + * check if the file extension is registered archive type. * @param fileName the file name to check * @return registered extension or null - * @since 3.0 + * @since org.eclipse.rse.services 3.0 */ - protected String getRegisteredExtension(String fileName) + protected String getRegisteredExtension(String fileName) { fileName = fileName.toLowerCase(); Iterator itor = _handlerTypes.keySet().iterator(); - while(itor.hasNext()) + while(itor.hasNext()) { String ext = ((String)itor.next()).toLowerCase(); if (fileName.endsWith(EXTENSION_SEPARATOR + ext)) { return ext; - } - + } + } return null; } - - /** + + /** * @param file the file whose extension we are computing. * @return the extension of file. "Extension" is - * defined as any letters in the filename after the last ".". + * defined as any letters in the filename after the last ".". * Returns "" if there is no extension. * @deprecated Use {@link #getRegisteredExtension(File)} instead */ @@ -190,12 +205,12 @@ public class ArchiveHandlerManager if (i == -1) return ""; //$NON-NLS-1$ return filename.substring(i+1).toLowerCase(); } - - - /** + + + /** * @param filename the name of the file whose extension we are computing. * @return the extension of filename. "Extension" is - * defined as any letters in the filename after the last ".". + * defined as any letters in the filename after the last ".". * Returns "" if there is no extension. * * @deprecated Use {@link #getRegisteredExtension(String)} instead */ @@ -205,7 +220,7 @@ public class ArchiveHandlerManager if (i == -1) return ""; //$NON-NLS-1$ return filename.substring(i+1).toLowerCase(); } - + /** * Given the absolute path to a virtual object, returns that object * as a VirtualChild. @@ -231,7 +246,7 @@ public class ArchiveHandlerManager * Returns the registered handler for the File file. If * no handler exists for that file yet, create it. If the extension of * file is not registered, then returns null. - */ + */ public ISystemArchiveHandler getRegisteredHandler(File file) { ISystemArchiveHandler handler = null; @@ -239,10 +254,10 @@ public class ArchiveHandlerManager { handler = (ISystemArchiveHandler) _handlers.get(file); } - + if (handler != null && handler.exists()) { - return handler; + return handler; } else { // find registered handler based on file's extension @@ -303,9 +318,9 @@ public class ArchiveHandlerManager /** * Registers an extension and a handler type. * @param ext The extension to register with the ArchiveHandlerManager - * @param handlerType The class of handler to register with ext. + * @param handlerType The class of handler to register with ext. * Note that any class passed in must implement ISystemArchiveHandler. - * @return Whether or not the registration was successful. + * @return Whether or not the registration was successful. */ public boolean setRegisteredHandler(String ext, Class handlerType) { @@ -317,7 +332,7 @@ public class ArchiveHandlerManager } if (handlerImplementsISystemArchiveHandler(handlerType)) { - if (_handlerTypes.containsKey(ext)) _handlerTypes.remove(ext); + if (_handlerTypes.containsKey(ext)) _handlerTypes.remove(ext); _handlerTypes.put(ext, handlerType); return true; } @@ -350,7 +365,7 @@ public class ArchiveHandlerManager } return ok; } - + /** * Returns whether or not handlerType or one of its superclasses implements ISystemArchiveHandler. */ @@ -362,22 +377,22 @@ public class ArchiveHandlerManager { if (interfaces[i].getName().equals(ISystemArchiveHandler.class.getName())) okay = true; } - if (!okay) + if (!okay) { Class superclass = handlerType.getSuperclass(); if (superclass.getName().equals(Object.class.getName())) return false; return handlerImplementsISystemArchiveHandler(superclass); } - else return true; + else return true; } - + /** * Removes the handler associated with file, freeing the file * to be used by other processes. */ public void disposeOfRegisteredHandlerFor(File file) { - _handlers.remove(file); + _handlers.remove(file); } /** @@ -390,7 +405,7 @@ public class ArchiveHandlerManager { return path.indexOf(VIRTUAL_CANONICAL_SEPARATOR) != -1; } - + /** * Converts the virtual path given by fullVirtualName * to the standard virtual form ('/' as separator, no leading or trailing '/'s) @@ -400,7 +415,7 @@ public class ArchiveHandlerManager public static String cleanUpVirtualPath(String fullVirtualName) { int j = fullVirtualName.indexOf(VIRTUAL_CANONICAL_SEPARATOR); - if (j == -1) + if (j == -1) { //fullVirtualName does not contains VIRTUAL_CANONICAL_SEPARATOR //fullVirtualName could be the virtual path only, instead of the full path. @@ -410,7 +425,7 @@ public class ArchiveHandlerManager //":". So for those two cases, we could just return the fullVirtualName if (fullVirtualName.indexOf(":") != -1 || fullVirtualName.trim().startsWith("\\")) //$NON-NLS-1$ //$NON-NLS-2$ { - return fullVirtualName; + return fullVirtualName; } } String realPart = ""; //$NON-NLS-1$ @@ -445,7 +460,7 @@ public class ArchiveHandlerManager newPath = newPath.substring(0,i) + newPath.substring(i+1); i = newPath.indexOf("//"); //$NON-NLS-1$ } - + // get rid of any leading or trailing slashes if (j != -1 && newPath.startsWith("/")) newPath = newPath.substring(1); //$NON-NLS-1$ if (newPath.endsWith("/")) newPath = newPath.substring(0, newPath.length() - 1); //$NON-NLS-1$ @@ -454,21 +469,21 @@ public class ArchiveHandlerManager /** * Disposes of all registered handlers. - */ + */ public void dispose() { _handlers.clear(); } - + public boolean createEmptyArchive(File newFile) { - if (!isRegisteredArchive(newFile.getName())) + if (!isRegisteredArchive(newFile.getName())) { System.out.println("Could not create new archive."); //$NON-NLS-1$ System.out.println(newFile + " is not a registered type of archive."); //$NON-NLS-1$ return false; } - + if (newFile.exists()) { if (!newFile.isFile()) @@ -484,9 +499,9 @@ public class ArchiveHandlerManager return false; } } - + try - { + { if (!newFile.createNewFile()) { System.out.println("Could not create new archive."); //$NON-NLS-1$ @@ -500,11 +515,11 @@ public class ArchiveHandlerManager System.out.println(e.getMessage()); return false; } - + ISystemArchiveHandler handler = getRegisteredHandler(newFile); return handler.create(); } - + /** * Returns the extensions for archive types that have been registered * with the ArchiveHandlerManager. @@ -519,14 +534,14 @@ public class ArchiveHandlerManager } return extensions; } - + public String getComment(File archive) { ISystemArchiveHandler handler = getRegisteredHandler(archive); if (handler == null || !handler.exists()) return ""; //$NON-NLS-1$ - return handler.getArchiveComment(); + return handler.getArchiveComment(); } - + public long getExpandedSize(File archive) { ISystemArchiveHandler handler = getRegisteredHandler(archive); @@ -539,7 +554,7 @@ public class ArchiveHandlerManager } return total; } - + /** * Returns the classification for the entry in a archive with the given virtual path. * @param file the archive file. @@ -547,20 +562,20 @@ public class ArchiveHandlerManager * @return the classification for the virtual file. */ public String getClassification(File file, String virtualPath) { - + // if archive file is null, or if it does not exist, or if the virtual path // is null, then return null for the classification if (file == null || !file.exists()) { return null; } - + // get archive handler ISystemArchiveHandler handler = getRegisteredHandler(file); - + if (handler == null || !handler.exists()) { - return null; + return null; } - + return handler.getClassification(virtualPath); } } diff --git a/rse/plugins/org.eclipse.rse.services/clientserver/org/eclipse/rse/services/clientserver/archiveutils/ISystemArchiveHandler.java b/rse/plugins/org.eclipse.rse.services/clientserver/org/eclipse/rse/services/clientserver/archiveutils/ISystemArchiveHandler.java index e15af30c598..cd0567b3ed7 100644 --- a/rse/plugins/org.eclipse.rse.services/clientserver/org/eclipse/rse/services/clientserver/archiveutils/ISystemArchiveHandler.java +++ b/rse/plugins/org.eclipse.rse.services/clientserver/org/eclipse/rse/services/clientserver/archiveutils/ISystemArchiveHandler.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2003, 2007 IBM Corporation and others. + * Copyright (c) 2003, 2008 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -7,13 +7,13 @@ * * Initial Contributors: * The following IBM employees contributed to the Remote System Explorer - * component that contains this file: David McKnight, Kushal Munir, - * Michael Berger, David Dykstal, Phil Coulthard, Don Yantzi, Eric Simpson, + * component that contains this file: David McKnight, Kushal Munir, + * Michael Berger, David Dykstal, Phil Coulthard, Don Yantzi, Eric Simpson, * Emily Bruner, Mazen Faraj, Adrian Storisteanu, Li Ding, and Kent Hawley. * * Contributors: - * {Name} (company) - description of contribution. - * Xuan Chen (IBM) - [160775] [api] rename (at least within a zip) blocks UI thread + * Xuan Chen (IBM) - [160775][api][breaking] rename (at least within a zip) blocks UI thread + * Martin Oberhuber (Wind River) - [cleanup] add API "since" tags to Archive Handler Javadoc *******************************************************************************/ package org.eclipse.rse.services.clientserver.archiveutils; @@ -28,205 +28,279 @@ import org.eclipse.rse.services.clientserver.search.SystemSearchStringMatcher; /** + * An interface that allows implementing classes to create their own handlers + * for various types of archive files, ie: zip, jar, tar, rpm. + * * @author mjberger - * An interface that allows implementing classes to create their own - * Handlers for various types of Archive files, ie: zip, jar, tar, rpm */ -public interface ISystemArchiveHandler +public interface ISystemArchiveHandler { - /** * Turns the archive that this handler represents into a new, empty archive. * (The archive could not exist before, in which case this would be a true * creation). - * @return Whether or not the blank archive was successfuly created. + * + * @return Whether or not the blank archive was successfully created. */ public boolean create(); - + /** - * @return an array containing all the entries in the archive file - * in a flat format, where the entries' filenames are prepended by - * the path to the entry within the virtual file system. If there - * are no entries in the file, returns an array of size 0. + * Return a flat list of entries in an archive. + * * @param archiveOperationMonitor the operation progress monitor + * @return an array containing all the entries in the archive file in a flat + * format, where the entries' filenames are prepended by the path to + * the entry within the virtual file system. If there are no entries + * in the file, returns an array of size 0. + * + * @since org.eclipse.rse.services 3.0 */ public VirtualChild[] getVirtualChildrenList(ISystemOperationMonitor archiveOperationMonitor); /** - * @return an array containing all the entries in the archive file - * in a flat format, whose full paths begin with the String parent. - * Returns an array of length 0 if there are no such entries. + * Return a flat list of entries in an archive, whose full paths begin with + * the given parent prefix. + * * @param parent full path of the parent * @param archiveOperationMonitor the operation progress monitor + * @return an array containing all the entries in the archive file in a flat + * format, whose full paths begin with the String + * parent. Returns an array of length 0 if there are + * no such entries. + * + * @since org.eclipse.rse.services 3.0 */ public VirtualChild[] getVirtualChildrenList(String parent, ISystemOperationMonitor archiveOperationMonitor); - + /** - * @return an array containing the virtual children of the virtual - * directory named fullVirtualName. If fullVirtualName is "", - * returns the top level in the virtual file system tree. If there are no - * values to return, returns null. + * Return the children of a specified node in an archive. + * * @param fullVirtualName full virtual path of the parent * @param archiveOperationMonitor the operation progress monitor + * @return an array containing the virtual children of the virtual directory + * named fullVirtualName. If + * fullVirtualName is "", returns the top level in + * the virtual file system tree. If there are no values to return, + * returns null. + * + * @since org.eclipse.rse.services 3.0 */ public VirtualChild[] getVirtualChildren(String fullVirtualName, ISystemOperationMonitor archiveOperationMonitor); /** - * @return an array containing the virtual children of the virtual - * directory named fullVirtualName that are themselves directories. - * If fullVirtualName is "", - * returns the top level of directories in the virtual file system tree. - * If there are no values to return, returns null. + * Return those children of a specified node in an archive, which are + * folders. + * * @param fullVirtualName full virtual path of the parent * @param archiveOperationMonitor the operation progress monitor + * @return an array containing the virtual children of the virtual directory + * named fullVirtualName that are themselves + * directories. If fullVirtualName is "", returns the + * top level of directories in the virtual file system tree. If + * there are no values to return, returns null. + * + * @since org.eclipse.rse.services 3.0 */ public VirtualChild[] getVirtualChildFolders(String fullVirtualName, ISystemOperationMonitor archiveOperationMonitor); - + /** - * @return the virtual File or Folder referred to by fullVirtualName. - * This method never returns null. In cases where the VirtualChild does not - * physically exist in the archive, this method returns a new VirtualChild object - * whose exists() method returns false. + * Return an archive node specified by a given virtual path. + * * @param fullVirtualName full virtual path of the object to retrieve * @param archiveOperationMonitor the operation progress monitor + * @return the virtual File or Folder referred to by + * fullVirtualName. This method never returns null. + * In cases where the VirtualChild does not physically exist in the + * archive, this method returns a new VirtualChild object whose + * exists() method returns false. + * + * @since org.eclipse.rse.services 3.0 */ public VirtualChild getVirtualFile(String fullVirtualName, ISystemOperationMonitor archiveOperationMonitor); /** - * @return Whether or not the virtual file or folder named fullVirtualName - * exists in the archive (physically). - * @param fullVirtualName full virtual path of the object + * Check whether a given virtual node exists in an archive. + * + * @param fullVirtualName full virtual path of the object * @param archiveOperationMonitor the operation progress monitor + * @return Whether or not the virtual file or folder named + * fullVirtualName exists in the archive + * (physically). + * + * @since org.eclipse.rse.services 3.0 */ public boolean exists(String fullVirtualName, ISystemOperationMonitor archiveOperationMonitor); /** + * Check if the archive handler implementation associated with this class + * exists. + * * @return Whether or not the handler exists. Usually false if the archive - * is corrupted or unreadable. + * is corrupted or unreadable. */ public boolean exists(); - + /** + * Return the archive that this handler deals with. + * * @return the archive that this handler deals with */ public File getArchive(); - - /** - * @return the current timestamp (last modified) for the entry in the archive named - * fullVirtualName + + /** + * Return the timestamp for an archive node. + * + * @param fullVirtualName virtual path specifying the node to check + * @return the current timestamp (last modified) for the archive entry named + * fullVirtualName */ public long getTimeStampFor(String fullVirtualName); - + /** - * @return the current size (uncompressed) for the entry in the archive named - * fullVirtualName + * Return the size for an archive node. + * + * @param fullVirtualName virtual path specifying the node to check + * @return the current size (uncompressed) for the entry in the archive + * named fullVirtualName */ public long getSizeFor(String fullVirtualName); - + /** - * Extracts the virtual file named fullVirtualName from the archive, - * placing the results in destination. - * @param fullVirtualName The full path and name of the virtual file in the archive. + * Extracts the virtual file named fullVirtualName from the + * archive, placing the results in destination. + * + * @param fullVirtualName The full path and name of the virtual file in the + * archive. * @param destination The destination file for the extracted virtual file. * @param archiveOperationMonitor the operation progress monitor - * @return true iff the extraction is successful + * @return true if the extraction is successful, + * false otherwise + * @since org.eclipse.rse.services 3.0 */ public boolean extractVirtualFile(String fullVirtualName, File destination, ISystemOperationMonitor archiveOperationMonitor); - + /** - * Extracts the virtual file named fullVirtualName from the archive, - * placing the results in destination. Extracts to the native encoding, but assumes - * that the source was archived using sourceEncoding if isText is true. - * @param fullVirtualName The full path and name of the virtual file in the archive. + * Extracts the virtual file named fullVirtualName from the + * archive, placing the results in destination. Extracts to + * the native encoding, but assumes that the source was archived using + * sourceEncoding if isText is true. + * + * @param fullVirtualName The full path and name of the virtual file in the + * archive. * @param destination The destination file for the extracted virtual file. * @param sourceEncoding The encoding of the file in the archive. * @param isText Whether or not the virtual file is a text file. * @param archiveOperationMonitor the operation progress monitor - * @return true iff the extraction is successful + * @return true if the extraction is successful, + * false otherwise + * @since org.eclipse.rse.services 3.0 */ public boolean extractVirtualFile(String fullVirtualName, File destination, String sourceEncoding, boolean isText, ISystemOperationMonitor archiveOperationMonitor); /** - * Extracts the directory dir (and its children) from - * the archive and places the results in the directory destinationParent. + * Extracts the directory dir (and its children) from the + * archive and places the results in the directory + * destinationParent. + * * @param dir The full name of the virtual directory to extract * @param destinationParent A handle to the directory in which the extracted - * directory will be placed as a subdirectory. + * directory will be placed as a subdirectory. * @param archiveOperationMonitor the operation progress monitor - * @return true iff the extraction is successful + * @return true if the extraction is successful, + * false otherwise + * @since org.eclipse.rse.services 3.0 */ public boolean extractVirtualDirectory(String dir, File destinationParent, ISystemOperationMonitor archiveOperationMonitor); - + /** - * Extracts the directory dir (and its children) from - * the archive and places the results in the directory destinationParent. - * Extracts to the native encoding (if isText), but assumes - * that the source was archived using sourceEncoding. + * Extracts the directory dir (and its children) from the + * archive and places the results in the directory + * destinationParent. Extracts to the native encoding (if + * isText), but assumes that the source was archived using + * sourceEncoding. + * * @param dir The full name of the virtual directory to extract * @param destinationParent A handle to the directory in which the extracted - * directory will be placed as a subdirectory. + * directory will be placed as a subdirectory. * @param sourceEncoding The encoding of the files in the archive. * @param isText Whether or not the files in the directory are text files * @param archiveOperationMonitor the operation progress monitor - * @return true iff the extraction is successful + * @return true if the extraction is successful, + * false otherwise + * @since org.eclipse.rse.services 3.0 */ public boolean extractVirtualDirectory(String dir, File destinationParent, String sourceEncoding, boolean isText, ISystemOperationMonitor archiveOperationMonitor); /** - * Extracts the directory dir (and its children) from - * the archive and places the results in the directory destinationParent. - * The results will be named destination.getName() rather than dir's name. + * Extracts the directory dir (and its children) from the + * archive and places the results in the directory + * destinationParent. The results will be named + * destination.getName() rather than dir's name. + * * @param dir The full name of the virtual directory to extract * @param destinationParent A handle to the directory in which the extracted - * directory will be placed as a subdirectory. - * @param destination A handle to the directory that will be created. Whatever - * contents are in that directory will be replaced with what is extracted from - * the archive. + * directory will be placed as a subdirectory. + * @param destination A handle to the directory that will be created. + * Whatever contents are in that directory will be replaced with + * what is extracted from the archive. * @param archiveOperationMonitor the operation progress monitor - * @return true iff the extraction is successful + * @return true if the extraction is successful, + * false otherwise + * @since org.eclipse.rse.services 3.0 */ public boolean extractVirtualDirectory(String dir, File destinationParent, File destination, ISystemOperationMonitor archiveOperationMonitor); /** - * Extracts the directory dir (and its children) from - * the archive and places the results in the directory destinationParent. - * The results will be named destination.getName() rather than dir's name. - * Extracts to the native encoding (if isText), but assumes - * that the source was archived using sourceEncoding. + * Extracts the directory dir (and its children) from the + * archive and places the results in the directory + * destinationParent. The results will be named + * destination.getName() rather than dir's name. Extracts to + * the native encoding (if isText), but assumes that the + * source was archived using sourceEncoding. + * * @param dir The full name of the virtual directory to extract * @param destinationParent A handle to the directory in which the extracted - * directory will be placed as a subdirectory. - * @param destination A handle to the directory that will be created. Whatever - * contents are in that directory will be replaced with what is extracted from - * the archive. + * directory will be placed as a subdirectory. + * @param destination A handle to the directory that will be created. + * Whatever contents are in that directory will be replaced with + * what is extracted from the archive. * @param sourceEncoding The encoding of the files in the archive. - * @param isText Whether or not the files to be extracted in the directory are all text files + * @param isText Whether or not the files to be extracted in the directory + * are all text files * @param archiveOperationMonitor the operation progress monitor - * @return true iff the extraction is successful + * @return true if the extraction is successful, + * false otherwise + * @since org.eclipse.rse.services 3.0 */ public boolean extractVirtualDirectory(String dir, File destinationParent, File destination, String sourceEncoding, boolean isText, ISystemOperationMonitor archiveOperationMonitor); /** * Compresses the file file and adds it to the archive, * placing it in the virtual directory virtualPath. Pass the - * name as the parameter name. If the virtual path does not exist - * in the archive, create it. If file is a directory, copy it and - * its contents into the archive, maintaining the tree structure. + * name as the parameter name. If the virtual path does not + * exist in the archive, create it. If file is a directory, + * copy it and its contents into the archive, maintaining the tree + * structure. + * * @param file the file to be added to the archive * @param virtualPath the destination of the file * @param name the name of the result virtual file * @param archiveOperationMonitor the operation progress monitor - * @return true if and only if the add was successful - */ + * @return true if the addition is successful, + * false otherwise + * @since org.eclipse.rse.services 3.0 + */ public boolean add(File file, String virtualPath, String name, ISystemOperationMonitor archiveOperationMonitor); /** * Compresses the file file and adds it to the archive, - * saving it in the encoding specified by encoding if the isText is true. - * placing it in the virtual directory virtualPath. Pass the - * name as the parameter name. If the virtual path does not exist - * in the archive, create it. If file is a directory, copy it and - * its contents into the archive, maintaining the tree structure. + * saving it in the encoding specified by encoding if the + * isText is true. placing it in the virtual directory + * virtualPath. Pass the name as the parameter + * name. If the virtual path does not exist in the archive, + * create it. If file is a directory, copy it and its + * contents into the archive, maintaining the tree structure. + * * @param file the file to be added to the archive * @param virtualPath the destination of the file * @param name the name of the result virtual file @@ -234,16 +308,20 @@ public interface ISystemArchiveHandler * @param targetEncoding the encoding of the result file * @param isText is the file a text file * @param archiveOperationMonitor the operation progress monitor - * @return true if and only if the add was successful - */ + * @return true if the addition is successful, + * false otherwise + * @since org.eclipse.rse.services 3.0 + */ public boolean add(File file, String virtualPath, String name, String sourceEncoding, String targetEncoding, boolean isText, ISystemOperationMonitor archiveOperationMonitor); - + /** - * Compresses the bytes in the InputStream stream and adds them as an entry to the archive, - * saving them in the encoding specified by encoding if isText is true, and - * placing it in the virtual directory virtualPath. Pass the - * name as the parameter name. If the virtual path does not exist - * in the archive, create it. + * Compresses the bytes in the InputStream stream and adds + * them as an entry to the archive, saving them in the encoding specified by + * encoding if isText is true, and placing it + * in the virtual directory virtualPath. Pass the name as + * the parameter name. If the virtual path does not exist in + * the archive, create it. + * * @param stream the InputStream to be added as an entry to the archive * @param virtualPath the destination of the stream * @param name the name of the result virtual file @@ -251,17 +329,21 @@ public interface ISystemArchiveHandler * @param targetEncoding the encoding of the result file * @param isText is the file a text file * @param archiveOperationMonitor the operation progress monitor - * @return true if and only if the add was successful - */ + * @return true if the addition is successful, + * false otherwise + * @since org.eclipse.rse.services 3.0 + */ public boolean add(InputStream stream, String virtualPath, String name, String sourceEncoding, String targetEncoding, boolean isText, ISystemOperationMonitor archiveOperationMonitor); - + /** * Compresses the file file and adds it to the archive, - * saving it in the encoding specified by encoding if the isText is true. - * placing it in the virtual directory virtualPath. Pass the - * name as the parameter name. If the virtual path does not exist - * in the archive, create it. If file is a directory, copy it and - * its contents into the archive, maintaining the tree structure. + * saving it in the encoding specified by encoding if the + * isText is true. placing it in the virtual directory + * virtualPath. Pass the name as the parameter + * name. If the virtual path does not exist in the archive, + * create it. If file is a directory, copy it and its + * contents into the archive, maintaining the tree structure. + * * @param file the file to be added to the archive * @param virtualPath the destination of the file * @param name the name of the result virtual file @@ -269,31 +351,40 @@ public interface ISystemArchiveHandler * @param targetEncoding the encoding of the result file * @param typeRegistery file transfer mode (binary or text) of this file * @param archiveOperationMonitor the operation progress monitor - * @return true if and only if the add was successful - */ + * @return true if the addition is successful, + * false otherwise + * @since org.eclipse.rse.services 3.0 + */ public boolean add(File file, String virtualPath, String name, String sourceEncoding, String targetEncoding, ISystemFileTypes typeRegistery, ISystemOperationMonitor archiveOperationMonitor); - + /** - * A generalization of the add method. - * Compresses the array of files files and adds each of them to the archive, placing them - * in the virtual directory virtualPath. Pass the names of the files - * as the parameter names, where files[i] has the name names[i]. - * If the virtual path does not exist in the archive, create it. + * A generalization of the add method. Compresses the array of files + * files and adds each of them to the archive, placing them + * in the virtual directory virtualPath. Pass the names of + * the files as the parameter names, where + * files[i] has the name names[i]. If the + * virtual path does not exist in the archive, create it. + * * @param files the list of files to be added to the archive * @param virtualPath the destination of the file * @param names the names of the result virtual files * @param archiveOperationMonitor the operation progress monitor - * @return true if and only if the add was successful + * @return true if the addition is successful, + * false otherwise + * @since org.eclipse.rse.services 3.0 */ public boolean add(File[] files, String virtualPath, String[] names, ISystemOperationMonitor archiveOperationMonitor); /** - * A generalization of the add method. - * Compresses the array of files files and adds each of them to the archive, placing them - * in the virtual directory virtualPath. Save the i'th file in the i'th encoding (if isText[i] is true) - * specified by encodings. Pass the names of the files - * as the parameter names, where files[i] has the name names[i]. - * If the virtual path does not exist in the archive, create it. + * A generalization of the add method. Compresses the array of files + * files and adds each of them to the archive, placing them + * in the virtual directory virtualPath. Save the i'th file + * in the i'th encoding (if isText[i] is true) specified by + * encodings. Pass the names of the files as the parameter + * names, where files[i] has the name + * names[i]. If the virtual path does not exist in the + * archive, create it. + * * @param files the list of files to be added to the archive * @param virtualPath the destination of the files * @param names the names of the result virtual files @@ -301,28 +392,34 @@ public interface ISystemArchiveHandler * @param targetEncodings the encoding of the result files * @param isText file transfer mode (binary or text) of the files * @param archiveOperationMonitor the operation progress monitor - * @return true if and only if the add was successful + * @return true if the addition is successful, + * false otherwise + * @since org.eclipse.rse.services 3.0 */ public boolean add(File[] files, String virtualPath, String[] names, String[] sourceEncodings, String[] targetEncodings, boolean[] isText, ISystemOperationMonitor archiveOperationMonitor); - + /** - * Compress the file file and replace the virtual file + * Compress the file file and replace the virtual file * referred to by fullVirtualName with the compressed file. * Pass the name of the file as the parameter name. + * * @param fullVirtualName the path of the file to be replaced * @param file the file to be added to the archive * @param name the name of the file * @param archiveOperationMonitor the operation progress monitor - * @return true if and only if the replace was successful + * @return true if the replacement is successful, + * false otherwise + * @since org.eclipse.rse.services 3.0 */ public boolean replace(String fullVirtualName, File file, String name, ISystemOperationMonitor archiveOperationMonitor); /** - * Compress the InputStream stream and replace the virtual file - * referred to by fullVirtualName with the compressed stream. - * Pass the name of the new entry as the parameter name, the - * encoding of the entry as encoding and whether or not the entry - * isText or not. + * Compress the InputStream stream and replace the virtual + * file referred to by fullVirtualName with the compressed + * stream. Pass the name of the new entry as the parameter name, + * the encoding of the entry as encoding and whether or not + * the entry isText or not. + * * @param fullVirtualName the path of the file to be replaced * @param stream the InputStream to be added as an entry to the archive * @param name the name of the result virtual file @@ -330,124 +427,163 @@ public interface ISystemArchiveHandler * @param targetEncoding the encoding of the result file * @param isText is the file a text file * @param archiveOperationMonitor the operation progress monitor - * @return true if and only if the replace was successful + * @return true if the replacement is successful, + * false otherwise + * @since org.eclipse.rse.services 3.0 */ public boolean replace(String fullVirtualName, InputStream stream, String name, String sourceEncoding, String targetEncoding, boolean isText, ISystemOperationMonitor archiveOperationMonitor); - + /** - * Deletes the entry fullVirtualName from the archive, and returns - * whether or not the deletion was successful. + * Deletes the entry fullVirtualName from the archive, and + * returns whether or not the deletion was successful. + * * @param fullVirtualName the path of the file to be deleted * @param archiveOperationMonitor the operation progress monitor - * @return true if and only if the replace was successful + * @return true if the deletion is successful, + * false otherwise + * @since org.eclipse.rse.services 3.0 */ public boolean delete(String fullVirtualName, ISystemOperationMonitor archiveOperationMonitor); - + /** * Renames the entry fullVirtualName to the new name * newName while still leaving the entry in the same virtual * directory. Returns true if and only if the rename was successful. + * * @param fullVirtualName the path of the file to be renamed * @param archiveOperationMonitor the operation progress monitor - * @return true if and only if the replace was successful + * @return true if the rename is successful, + * false otherwise + * @since org.eclipse.rse.services 3.0 */ public boolean rename(String fullVirtualName, String newName, ISystemOperationMonitor archiveOperationMonitor); - + /** - * Moves the entry fullVirtualName to the location - * specified by destinationVirtualPath, while leaving the entry with - * the same name as before. + * Moves the entry fullVirtualName to the location specified + * by destinationVirtualPath, while leaving the entry with + * the same name as before. + * * @param fullVirtualName the path of the file to be renamed * @param destinationVirtualPath the destination of the file to move to * @param archiveOperationMonitor the operation progress monitor - * @return true if and only if the replace was successful - */ + * @return true if the move is successful, false + * otherwise + * @since org.eclipse.rse.services 3.0 + */ public boolean move(String fullVirtualName, String destinationVirtualPath, ISystemOperationMonitor archiveOperationMonitor); - + /** * Replaces the full name and path of the entry fullVirtualName * with the new full name and path newFullVirtualName. + * * @param fullVirtualName the path of the file to be renamed * @param newFullVirtualName the full path of the virtual file name * @param archiveOperationMonitor the operation progress monitor - * @return true if and only if the replace was successful + * @return true if the rename is successful, + * false otherwise + * @since org.eclipse.rse.services 3.0 */ public boolean fullRename(String fullVirtualName, String newFullVirtualName, ISystemOperationMonitor archiveOperationMonitor); /** - * Extracts and returns the specified list of virtual files from the archive. + * Extracts and returns the specified list of virtual files from the + * archive. + * * @param fullNames The list of files to return * @param archiveOperationMonitor the operation progress monitor - * @return An array of handles to the extracted files. If fullNames has length 0 - * then this method returns an array of length 0. + * @return An array of handles to the extracted files. If fullNames has + * length 0 then this method returns an array of length 0. + * @since org.eclipse.rse.services 3.0 */ public File[] getFiles(String[] fullNames, ISystemOperationMonitor archiveOperationMonitor); - + /** - * Creates a new, empty folder in the archive. If parent folders do not exist either, creates them. - * @param fullVirtualName The full name and path of the new folder within the virtual file system. + * Creates a new, empty folder in the archive. If parent folders do not + * exist either, creates them. + * + * @param fullVirtualName The full name and path of the new folder within + * the virtual file system. * @param archiveOperationMonitor the operation progress monitor - * @return Whether or not the creation was successful. + * @return true if the create operation is successful, + * false otherwise + * @since org.eclipse.rse.services 3.0 */ public boolean createFolder(String fullVirtualName, ISystemOperationMonitor archiveOperationMonitor); - + /** - * Creates a new, empty file in the archive. If parent folders do not exist either, creates them. - * @param fullVirtualName The full name and path of the new file within the virtual file system. + * Creates a new, empty file in the archive. If parent folders do not exist + * either, creates them. + * + * @param fullVirtualName The full name and path of the new file within the + * virtual file system. * @param archiveOperationMonitor the operation progress monitor - * @return Whether or not the creation was successful. + * @return true if the create operation is successful, + * false otherwise + * @since org.eclipse.rse.services 3.0 */ public boolean createFile(String fullVirtualName, ISystemOperationMonitor archiveOperationMonitor); - + /** - * Gets the archive-type specific standard name for the VirtualChild - * vc. For example, for Zips, if vc is a directory, then - * the standard name must end with a "/". + * Get the archive-type specific standard name for the VirtualChild + * vc. For example, for Zip archives, if vc is a directory, + * then the standard name must end with a "/". + * + * @param vc the archive node to use + * @return the standard name for the node */ public String getStandardName(VirtualChild vc); /** - * Searches for text within a virtual file in this archive. - * A good implementation will not actually extract the file to disk. + * Search for text within a virtual file in this archive. A good + * implementation will not actually extract the file to disk. + * * @param fullVirtualName the virtual file to search. * @param matcher the pattern matcher to use. * @param archiveOperationMonitor the operation progress monitor - * @return an array of match objects corresponding to lines where matches were found. - * Returns an empty array if there are no results. - */ + * @return an array of match objects corresponding to lines where matches + * were found. Returns an empty array if there are no results. + * @since org.eclipse.rse.services 3.0 + */ public SystemSearchLineMatch[] search(String fullVirtualName, SystemSearchStringMatcher matcher, ISystemOperationMonitor archiveOperationMonitor); /** - * Gets the user-defined comment for a specific entry in the archive. + * Get the user-defined comment for a specific entry in the archive. + * * @param fullVirtualName The entry who's comment is desired * @return the comment as a String or "" if there is none */ public String getCommentFor(String fullVirtualName); - + /** - * Gets the amount of space taken up by a specific entry in the archive - * when it is in compressed form. Compare with getSizeFor(String) which gets - * the size of the entry after it is decompressed. + * Get the amount of space taken up by a specific entry in the archive when + * it is in compressed form. Compare with getSizeFor(String) which gets the + * size of the entry after it is decompressed. + * * @param fullVirtualName The entry who's compressed size is desired - * @return the compressed size of the specified entry, or 0 if the entry is not - * found. If the archive is not a compression type (ie. tar), return the same as getSizeFor(String). + * @return the compressed size of the specified entry, or 0 if the entry is + * not found. If the archive is not a compression type (ie. tar), + * return the same as getSizeFor(String). */ public long getCompressedSizeFor(String fullVirtualName); - + /** - * Gets the method used to compress a specific entry in the archive. + * Get the method used to compress a specific entry in the archive. + * * @param fullVirtualName The entry who's compression method is desired * @return The compression method of the specified entry, or "" if none. */ public String getCompressionMethodFor(String fullVirtualName); /** + * Get the comment associated with an archive. + * * @return The comment associated with this archive, or "" if there is none. */ public String getArchiveComment(); - + /** - * Returns the classification for the entry with the given path. + * Get the classification for the entry with the given path. + * * @param fullVirtualName the virtual name. * @return the classification. */ diff --git a/rse/plugins/org.eclipse.rse.services/clientserver/org/eclipse/rse/services/clientserver/archiveutils/SystemTarHandler.java b/rse/plugins/org.eclipse.rse.services/clientserver/org/eclipse/rse/services/clientserver/archiveutils/SystemTarHandler.java index 4923eab80a1..5214016d665 100644 --- a/rse/plugins/org.eclipse.rse.services/clientserver/org/eclipse/rse/services/clientserver/archiveutils/SystemTarHandler.java +++ b/rse/plugins/org.eclipse.rse.services/clientserver/org/eclipse/rse/services/clientserver/archiveutils/SystemTarHandler.java @@ -7,8 +7,8 @@ * * Initial Contributors: * The following IBM employees contributed to the Remote System Explorer - * component that contains this file: David McKnight, Kushal Munir, - * Michael Berger, David Dykstal, Phil Coulthard, Don Yantzi, Eric Simpson, + * component that contains this file: David McKnight, Kushal Munir, + * Michael Berger, David Dykstal, Phil Coulthard, Don Yantzi, Eric Simpson, * Emily Bruner, Mazen Faraj, Adrian Storisteanu, Li Ding, and Kent Hawley. * * Contributors: @@ -42,11 +42,11 @@ import java.util.Enumeration; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; +import java.util.List; import java.util.Vector; import org.eclipse.rse.internal.services.clientserver.archiveutils.ITarConstants; import org.eclipse.rse.internal.services.clientserver.archiveutils.SystemArchiveUtil; -import org.eclipse.rse.internal.services.clientserver.archiveutils.TarOutputStream; import org.eclipse.rse.services.clientserver.ISystemFileTypes; import org.eclipse.rse.services.clientserver.ISystemOperationMonitor; import org.eclipse.rse.services.clientserver.SystemReentrantMutex; @@ -65,15 +65,15 @@ public class SystemTarHandler implements ISystemArchiveHandler { protected long modTimeDuringCache; protected VirtualFileSystem vfs; protected SystemReentrantMutex _mutex; - + /** * This class represents a virtual file system. A virtual file system is simply a data structure that * helps manage the contents of an archive file. It provides services that a handler can use. */ private class VirtualFileSystem { - + private VirtualFileNode rootNode; - + /** * Constructor for the virtual file system. * @param root the root entry. @@ -81,7 +81,7 @@ public class SystemTarHandler implements ISystemArchiveHandler { public VirtualFileSystem(VirtualChild root) { this.rootNode = new VirtualFileNode(root); } - + /** * Adds the entry to the tree according to its full path. Creates the parents * of the entry if they don't exist. @@ -91,7 +91,7 @@ public class SystemTarHandler implements ISystemArchiveHandler { public void addEntry(VirtualChild entry) { addEntry(entry, true); } - + /** * Adds the entry to the tree according to its full path. Creates the parents * of the entry if they don't exist. @@ -100,41 +100,41 @@ public class SystemTarHandler implements ISystemArchiveHandler { * already exists in the tree. */ public void addEntry(VirtualChild entry, boolean replace) { - + String path = entry.fullName; - + VirtualFileNode parentNode = rootNode; - + int idx = path.indexOf("/"); //$NON-NLS-1$ String name = path; - + String segPath = ""; //$NON-NLS-1$ - + // ensure each segment exists or is created if it does not exist while (idx > 0) { name = path.substring(0, idx); path = path.substring(idx+1); - + segPath = segPath + name + "/"; //$NON-NLS-1$ - + boolean exists = parentNode.childExists(name); - + // only create new parent if it does not already exist if (!exists) { VirtualChild child = new VirtualChild(SystemTarHandler.this, segPath); child.isDirectory = true; parentNode.addChild(name, new VirtualFileNode(child), true); } - + // the new parent is the child (which may have been created) parentNode = parentNode.getChild(name); - + idx = path.indexOf("/"); //$NON-NLS-1$ } - + parentNode.addChild(path, new VirtualFileNode(entry), replace); } - + /** * Removes the entry from the tree. * @param entry the entry to be removed from the tree. @@ -144,7 +144,7 @@ public class SystemTarHandler implements ISystemArchiveHandler { public VirtualChild removeEntry(VirtualChild entry) { return removeEntry(entry.fullName); } - + /** * Removes the entry with the given path from the tree. * @param path path of the entry to be removed from the tree. @@ -157,33 +157,33 @@ public class SystemTarHandler implements ISystemArchiveHandler { if (path.charAt(path.length()-1) == '/') { path = path.substring(0, path.length()-1); } - + // get the parent node VirtualFileNode parent = getParentNode(path); - + // get the name of the entry String name = null; - + int idx = path.lastIndexOf('/'); - + if (idx == -1) { name = path; } else { - name = path.substring(idx+1); + name = path.substring(idx+1); } - + // remove the entry from the parent VirtualFileNode removedChild = parent.removeChild(name); - + if (removedChild == null) { return null; } else { return removedChild.getEntry(); - } + } } - + /** * Gets an entry from the given path. * @param path the path of the entry. @@ -191,7 +191,7 @@ public class SystemTarHandler implements ISystemArchiveHandler { */ public VirtualChild getEntry(String path) { VirtualFileNode node = getNode(path); - + if (node == null) { return null; } @@ -199,7 +199,7 @@ public class SystemTarHandler implements ISystemArchiveHandler { return node.getEntry(); } } - + /** * Returns an array of children of the given entry. * @param entry the parent entry. @@ -209,7 +209,7 @@ public class SystemTarHandler implements ISystemArchiveHandler { public VirtualChild[] getChildren(VirtualChild entry) { return getChildren(entry.fullName); } - + /** * Returns an array of children folders of the given entry. * @param entry the parent entry. @@ -227,21 +227,21 @@ public class SystemTarHandler implements ISystemArchiveHandler { */ public VirtualChild[] getChildren(String path) { VirtualFileNode node = getNode(path); - + if (node == null) { return new VirtualChild[0]; } - + VirtualFileNode[] childNodes = node.getChildren(); VirtualChild[] children = new VirtualChild[childNodes.length]; - + for (int i = 0; i < children.length; i++) { children[i] = childNodes[i].getEntry(); } - + return children; } - + /** * Returns an array of children folders of the entry with the given path. * @param path of the parent entry, or "" to indicate the root entry. @@ -251,14 +251,14 @@ public class SystemTarHandler implements ISystemArchiveHandler { VirtualFileNode node = getNode(path); VirtualFileNode[] childNodes = node.getChildrenFolders(); VirtualChild[] children = new VirtualChild[childNodes.length]; - + for (int i = 0; i < children.length; i++) { children[i] = childNodes[i].getEntry(); } - + return children; } - + /** * Gets the parent entry. * @param entry the entry whose parent we want. @@ -266,7 +266,7 @@ public class SystemTarHandler implements ISystemArchiveHandler { */ public VirtualChild getParent(VirtualChild entry) { VirtualFileNode node = getParentNode(entry.fullName); - + if (node == null) { return null; } @@ -274,7 +274,7 @@ public class SystemTarHandler implements ISystemArchiveHandler { return node.getEntry(); } } - + /** * Returns the parent node for the entry with the given path. * @param path the path of the entry whose parent we want. @@ -282,14 +282,14 @@ public class SystemTarHandler implements ISystemArchiveHandler { * node doesn't exist. */ private VirtualFileNode getParentNode(String path) { - + // strip out trailing separator if (path.charAt(path.length()-1) == '/') { path = path.substring(0, path.length()-1); } - + int idx = path.lastIndexOf('/'); - + if (idx == -1) { return rootNode; } @@ -297,43 +297,43 @@ public class SystemTarHandler implements ISystemArchiveHandler { return getNode(path.substring(0, idx)); } } - + /** * Returns the node representing the entry with the given path. * @param path the path of the entry, or "" to indicate the root node. * @return the node at the given path, or null if no such node exists. */ private VirtualFileNode getNode(String path) { - + if (path.equals("")) { //$NON-NLS-1$ return rootNode; } - + // strip out trailing separator if (path.charAt(path.length()-1) == '/') { path = path.substring(0, path.length()-1); } - + int idx = 0; int jdx = 0; VirtualFileNode tempNode = rootNode; boolean done = false; - - while (true) { + + while (true) { jdx = path.indexOf('/', idx); - + if (jdx == -1) { jdx = path.length(); done = true; } - + String tempName = path.substring(idx, jdx); tempNode = tempNode.getChild(tempName); - + if (tempNode == null) { return null; } - + if (!done) { idx = jdx + 1; } @@ -341,24 +341,24 @@ public class SystemTarHandler implements ISystemArchiveHandler { break; } } - + return tempNode; } } - + /** * This class represents a node in the tree. */ private class VirtualFileNode { - + private static final int MODE_ALL = 1; private static final int MODE_FILES_ONLY = 2; private static final int MODE_FOLDERS_ONLY = 3; - + private VirtualChild entry; private HashMap map; private boolean isDir; - + /** * Constructor for the virtual file node. * @param entry the entry that this node represents. @@ -368,7 +368,7 @@ public class SystemTarHandler implements ISystemArchiveHandler { this.isDir = entry.isDirectory; this.map = new HashMap(); } - + /** * Returns the entry represented by this node. * @return the entry represented by this node. @@ -376,7 +376,7 @@ public class SystemTarHandler implements ISystemArchiveHandler { public VirtualChild getEntry() { return entry; } - + /** * Returns whether the node represents a directory or a file. * @return true if the node represents a directory, false otherwise; @@ -384,7 +384,7 @@ public class SystemTarHandler implements ISystemArchiveHandler { public boolean isDir() { return isDir; } - + /** * Adds a child if this node is a directory. * @param childName the name with which to identify the child. @@ -395,49 +395,49 @@ public class SystemTarHandler implements ISystemArchiveHandler { * to the new child. */ public void addChild(String childName, VirtualFileNode child, boolean replace) { - + if (isDir) { - + // if replace is true, replace an existing node (if any) with this one - // note that is a + // note that is a if (replace) { - + // get the existing child VirtualFileNode oldChild = getChild(childName); - + // if there is an existing child which is a directory, and we want to replace it // with a directory if (oldChild != null && oldChild.isDir() && child.isDir()) { Iterator iter = oldChild.getChildrenNames(); - + while (iter.hasNext()) { String name = (String)(iter.next()); VirtualFileNode grandChild = oldChild.getChild(name); child.addChild(name, grandChild, true); } } - + map.put(childName, child); } // otherwise first check if it already exists, and only add if it doesn't else { boolean exists = childExists(childName); - + if (!exists) { map.put(childName, child); } } } } - + /** * Removes the child with the given name only if the node is a directory. * @param childName the name of the child. * @return the child that was removed, or null if a child with - * the given name wasn't found or this node isn't a directory. + * the given name wasn't found or this node isn't a directory. */ public VirtualFileNode removeChild(String childName) { - + if (isDir) { return (VirtualFileNode)map.remove(childName); } @@ -445,7 +445,7 @@ public class SystemTarHandler implements ISystemArchiveHandler { return null; } } - + /** * Gets the child with the given name. * @param childName the name of the child. @@ -453,7 +453,7 @@ public class SystemTarHandler implements ISystemArchiveHandler { * the given name wasn't found or this node isn't a directory. */ public VirtualFileNode getChild(String childName) { - + if (isDir) { return (VirtualFileNode)map.get(childName); } @@ -461,7 +461,7 @@ public class SystemTarHandler implements ISystemArchiveHandler { return null; } } - + /** * Returns an array of children. * @return an array of children, or an empty array if none exists, or if the node is not a directory. @@ -469,7 +469,7 @@ public class SystemTarHandler implements ISystemArchiveHandler { public VirtualFileNode[] getChildren() { return getChildren(MODE_ALL); } - + /** * Returns an array of children that are folders. * @return an array of children, or an empty array if none exists, or if the node is not a directory. @@ -477,16 +477,16 @@ public class SystemTarHandler implements ISystemArchiveHandler { public VirtualFileNode[] getChildrenFolders() { return getChildren(MODE_FOLDERS_ONLY); } - + /** * Returns an array of children. * @param mode the mode. One of MODE_ALL, MODE_FILES_ONLY and MODE_FOLDERS_ONLY. * @return an array of children, or an empty array if none exists, or if the node is not a directory. */ public VirtualFileNode[] getChildren(int mode) { - + if (isDir) { - + // if we want all children (i.e. files and folders), then this // is probably quicker than getting each value and casting if (mode == MODE_ALL) { @@ -499,11 +499,11 @@ public class SystemTarHandler implements ISystemArchiveHandler { else { Vector v = new Vector(); Iterator iter = map.values().iterator(); - + while (iter.hasNext()) { VirtualFileNode node = (VirtualFileNode)iter.next(); boolean isDir = node.isDir(); - + if (mode == MODE_FILES_ONLY && !isDir) { v.add(node); } @@ -511,7 +511,7 @@ public class SystemTarHandler implements ISystemArchiveHandler { v.add(node); } } - + VirtualFileNode[] children = new VirtualFileNode[v.size()]; v.toArray(children); return children; @@ -521,15 +521,15 @@ public class SystemTarHandler implements ISystemArchiveHandler { return new VirtualFileNode[0]; } } - + /** - * Returns whether the child with the given name exists. + * Returns whether the child with the given name exists. * @param childName the name of the child. * @return true if the child exists, falseotherwise. * Returns false if this node isn't a directory. */ public boolean childExists(String childName) { - + if (isDir) { return map.containsKey(childName); } @@ -537,14 +537,14 @@ public class SystemTarHandler implements ISystemArchiveHandler { return false; } } - + /** * Returns an iterator of the names of all the children of this node. * @return a iterator of all the names of the children, or null if the node * is not a directory. */ public Iterator getChildrenNames() { - + if (isDir) { return map.keySet().iterator(); } @@ -565,38 +565,38 @@ public class SystemTarHandler implements ISystemArchiveHandler { modTimeDuringCache = file.lastModified(); _mutex = new SystemReentrantMutex(); } - + /** * Initializes the handler from the given file and does caching. * @param file the file to handle - * @throws IOException in case of error during initialization - * (can be thrown by overriding methods) + * @throws IOException in case of error during initialization + * (can be thrown by overriding methods) */ protected void init(File file) throws IOException { this.file = file; } - + /** * Reads the contents of the tar file, and caches the entries. */ protected void createCache() { - + TarFile tarFile = getTarFile(); - + Enumeration entries = tarFile.entries(); - + VirtualChild root = new VirtualChild(this); root.isDirectory = true; - + vfs = new VirtualFileSystem(root); - + while (entries.hasMoreElements()) { TarEntry entry = (TarEntry)entries.nextElement(); VirtualChild child = getVirtualChild(entry); vfs.addEntry(child); } } - + /** * Update the virtual file system tree. * If newOldName HashMap is input, use the old name in the HashMap @@ -620,9 +620,9 @@ public class SystemTarHandler implements ISystemArchiveHandler { { searchName = entryName; } - + child = vfs.getEntry(searchName); - + if (null == child) { child = getVirtualChild(entry); @@ -632,29 +632,29 @@ public class SystemTarHandler implements ISystemArchiveHandler { vfs.removeEntry(searchName); child = updateVirtualChild(entry, child); } - + vfs.addEntry(child); } } - + /** * Gets a tar file from the underlying file. * @return the tar file, or null if the tar file does not exist. */ protected TarFile getTarFile() { - + TarFile tarFile = null; - + try { tarFile = new TarFile(file); } catch (IOException e) { // TODO: log error } - + return tarFile; } - + /** * Updates the cache if the tar file has changed since the last time * we cached. Will not change the cache if the tar file hasn't been @@ -664,7 +664,7 @@ public class SystemTarHandler implements ISystemArchiveHandler { protected void updateCache() throws IOException { File newFile = new File(file.getAbsolutePath()); long modTime = newFile.lastModified(); - + // if the modified time of the file is not the same as the modified time before last // cache, then recreate cache if (modTime != modTimeDuringCache) { @@ -675,158 +675,164 @@ public class SystemTarHandler implements ISystemArchiveHandler { } } - /** - * @see org.eclipse.rse.services.clientserver.archiveutils.ISystemArchiveHandler#getVirtualChildrenList(ISystemOperationMonitor archiveOperationMonitor) + /* + * (non-Javadoc) + * @see org.eclipse.rse.services.clientserver.archiveutils.ISystemArchiveHandler#getVirtualChildrenList(org.eclipse.rse.services.clientserver.ISystemOperationMonitor) */ public VirtualChild[] getVirtualChildrenList(ISystemOperationMonitor archiveOperationMonitor) { - + // this method does not read from cache Vector v = new Vector(); - + TarFile tarFile = getTarFile(); Enumeration entries = tarFile.entries(); - + while (entries.hasMoreElements()) { TarEntry entry = (TarEntry)entries.nextElement(); VirtualChild child = new VirtualChild(this, entry.getName()); child.isDirectory = entry.isDirectory(); v.add(child); } - + int numOfChildren = v.size(); - + VirtualChild[] children = new VirtualChild[numOfChildren]; - + for (int i = 0; i < numOfChildren; i++) { children[i] = (VirtualChild)v.get(i); } - + return children; } - /** - * @see org.eclipse.rse.services.clientserver.archiveutils.ISystemArchiveHandler#getVirtualChildrenList(java.lang.String, ISystemOperationMonitor) + /* + * (non-Javadoc) + * @see org.eclipse.rse.services.clientserver.archiveutils.ISystemArchiveHandler#getVirtualChildrenList(java.lang.String, org.eclipse.rse.services.clientserver.ISystemOperationMonitor) */ public VirtualChild[] getVirtualChildrenList(String parent, ISystemOperationMonitor archiveOperationMonitor) { parent = ArchiveHandlerManager.cleanUpVirtualPath(parent); - + // this method does not read from cache Vector v = new Vector(); - + TarFile tarFile = getTarFile(); Enumeration entries = tarFile.entries(); - + while (entries.hasMoreElements()) { TarEntry entry = (TarEntry)entries.nextElement(); - + // only add those entries that have names that begin with the parent name // also check that the entry name isn't just the parent name + '/' (i.e. still the same // as the parent) String entryName = entry.getName(); String parentNameEndWithSlash = parent + "/"; //$NON-NLS-1$ - if (entryName.startsWith(parentNameEndWithSlash) && !entryName.equals(parentNameEndWithSlash)) { + if (entryName.startsWith(parentNameEndWithSlash) && !entryName.equals(parentNameEndWithSlash)) { VirtualChild child = new VirtualChild(this, entryName); child.isDirectory = entry.isDirectory(); v.add(child); } } - + int numOfChildren = v.size(); - + VirtualChild[] children = new VirtualChild[numOfChildren]; - + for (int i = 0; i < numOfChildren; i++) { children[i] = (VirtualChild)v.get(i); } - + return children; } - /** - * @see org.eclipse.rse.services.clientserver.archiveutils.ISystemArchiveHandler#getVirtualChildren(java.lang.String, ISystemOperationMonitor) + /* + * (non-Javadoc) + * @see org.eclipse.rse.services.clientserver.archiveutils.ISystemArchiveHandler#getVirtualChildren(java.lang.String, org.eclipse.rse.services.clientserver.ISystemOperationMonitor) */ public VirtualChild[] getVirtualChildren(String fullVirtualName, ISystemOperationMonitor archiveOperationMonitor) { - + try { updateCache(); } catch (IOException e) { // TODO: log error - return new VirtualChild[0]; + return new VirtualChild[0]; } - + fullVirtualName = ArchiveHandlerManager.cleanUpVirtualPath(fullVirtualName); return vfs.getChildren(fullVirtualName); } - /** - * @see org.eclipse.rse.services.clientserver.archiveutils.ISystemArchiveHandler#getVirtualChildFolders(java.lang.String, ISystemOperationMonitor) + /* + * (non-Javadoc) + * @see org.eclipse.rse.services.clientserver.archiveutils.ISystemArchiveHandler#getVirtualChildFolders(java.lang.String, org.eclipse.rse.services.clientserver.ISystemOperationMonitor) */ public VirtualChild[] getVirtualChildFolders(String fullVirtualName, ISystemOperationMonitor archiveOperationMonitor) { - + try { updateCache(); } catch (IOException e) { // TODO: log error - return new VirtualChild[0]; + return new VirtualChild[0]; } - + fullVirtualName = ArchiveHandlerManager.cleanUpVirtualPath(fullVirtualName); return vfs.getChildrenFolders(fullVirtualName); } - /** - * @see org.eclipse.rse.services.clientserver.archiveutils.ISystemArchiveHandler#getVirtualFile(java.lang.String, ISystemOperationMonitor) + /* + * (non-Javadoc) + * @see org.eclipse.rse.services.clientserver.archiveutils.ISystemArchiveHandler#getVirtualFile(java.lang.String, org.eclipse.rse.services.clientserver.ISystemOperationMonitor) */ public VirtualChild getVirtualFile(String fullVirtualName, ISystemOperationMonitor archiveOperationMonitor) { - + fullVirtualName = ArchiveHandlerManager.cleanUpVirtualPath(fullVirtualName); - + if (fullVirtualName == null || fullVirtualName.equals("")) { //$NON-NLS-1$ return new VirtualChild(this); } - + try { updateCache(); } catch (IOException e) { // TODO: log error - return new VirtualChild(this, fullVirtualName); + return new VirtualChild(this, fullVirtualName); } - + VirtualChild entry = vfs.getEntry(fullVirtualName); - + // if entry is null, then create a new virtual child object // for which exists will return false if (entry == null) { entry = new VirtualChild(this, fullVirtualName); } - + return entry; } - /** - * @see org.eclipse.rse.services.clientserver.archiveutils.ISystemArchiveHandler#exists(java.lang.String, ISystemOperationMonitor) + /* + * (non-Javadoc) + * @see org.eclipse.rse.services.clientserver.archiveutils.ISystemArchiveHandler#exists(java.lang.String, org.eclipse.rse.services.clientserver.ISystemOperationMonitor) */ public boolean exists(String fullVirtualName, ISystemOperationMonitor archiveOperationMonitor) { - + fullVirtualName = ArchiveHandlerManager.cleanUpVirtualPath(fullVirtualName); - + if (fullVirtualName == null || fullVirtualName.equals("")) { //$NON-NLS-1$ return false; } - + try { updateCache(); } catch (IOException e) { // TODO: log error - return false; + return false; } - + VirtualChild child = vfs.getEntry(fullVirtualName); - + if (child != null) { return true; } @@ -842,15 +848,16 @@ public class SystemTarHandler implements ISystemArchiveHandler { return file; } - /** + /* + * (non-Javadoc) * @see org.eclipse.rse.services.clientserver.archiveutils.ISystemArchiveHandler#getTimeStampFor(java.lang.String) */ public long getTimeStampFor(String fullVirtualName) { fullVirtualName = ArchiveHandlerManager.cleanUpVirtualPath(fullVirtualName); - + // get the entry with that name TarEntry entry = getTarFile().getEntry(fullVirtualName); - + // if the entry exists, return its last modified time if (entry != null) { return entry.getModificationTime(); @@ -862,12 +869,13 @@ public class SystemTarHandler implements ISystemArchiveHandler { } } - /** + /* + * (non-Javadoc) * @see org.eclipse.rse.services.clientserver.archiveutils.ISystemArchiveHandler#getSizeFor(java.lang.String) */ public long getSizeFor(String fullVirtualName) { fullVirtualName = ArchiveHandlerManager.cleanUpVirtualPath(fullVirtualName); - + // get the entry with that name TarEntry entry = getTarFile().getEntry(fullVirtualName); @@ -888,7 +896,7 @@ public class SystemTarHandler implements ISystemArchiveHandler { public boolean extractVirtualFile(String fullVirtualName, File destination, ISystemOperationMonitor archiveOperationMonitor) { fullVirtualName = ArchiveHandlerManager.cleanUpVirtualPath(fullVirtualName); TarEntry entry = null; - + InputStream inStream = null; OutputStream outStream = null; int mutexLockStatus = SystemReentrantMutex.LOCK_STATUS_NOLOCK; @@ -899,25 +907,25 @@ public class SystemTarHandler implements ISystemArchiveHandler { { entry = getTarFile().getEntry(fullVirtualName); updateCache(); - + // if the entry is a directory, simply create the destination and set the last modified time to // the entry's last modified time if (entry.isDirectory()) { - - // if destination exists, then delete it + + // if destination exists, then delete it if (destination.exists()) { destination.delete(); } - + // create destination directory, and set the last modified time to // the entry's last modified time destination.mkdirs(); destination.setLastModified(entry.getModificationTime()); return true; } - + inStream = getTarFile().getInputStream(entry); - + if (inStream == null) { destination.setLastModified(entry.getModificationTime()); return false; // TODO: return true or false? @@ -925,20 +933,20 @@ public class SystemTarHandler implements ISystemArchiveHandler { //Need to make sure destination file exists. if (!destination.exists()) { - File parentFile = destination.getParentFile(); - if (!parentFile.exists()) - parentFile.mkdirs(); - destination.createNewFile(); + File parentFile = destination.getParentFile(); + if (!parentFile.exists()) + parentFile.mkdirs(); + destination.createNewFile(); } - + outStream = new FileOutputStream(destination); - + byte[] buf = new byte[ITarConstants.BLOCK_SIZE]; int numRead = inStream.read(buf); - + while (numRead > 0) { outStream.write(buf, 0, numRead); - numRead = inStream.read(buf); + numRead = inStream.read(buf); } } } @@ -946,22 +954,22 @@ public class SystemTarHandler implements ISystemArchiveHandler { // TODO: log error } finally { - + try { - + if (outStream != null) { outStream.close(); } - + if (inStream != null) { inStream.close(); } - - + + // finished creating and writing to the file, so now set the last modified time // to the entry's last modified time if (entry != null) - { + { destination.setLastModified(entry.getModificationTime()); } } @@ -969,7 +977,7 @@ public class SystemTarHandler implements ISystemArchiveHandler { e.printStackTrace(); } releaseMutex(mutexLockStatus); - + } return true; } @@ -980,15 +988,16 @@ public class SystemTarHandler implements ISystemArchiveHandler { public boolean extractVirtualDirectory(String fullVirtualName, File destinationParent, ISystemOperationMonitor archiveOperationMonitor) { return extractVirtualDirectory(fullVirtualName, destinationParent, (File) null, archiveOperationMonitor); } - - /** - * @see org.eclipse.rse.services.clientserver.archiveutils.ISystemArchiveHandler#extractVirtualDirectory(java.lang.String, java.io.File, java.io.File, ISystemOperationMonitor) + + /* + * (non-Javadoc) + * @see org.eclipse.rse.services.clientserver.archiveutils.ISystemArchiveHandler#extractVirtualDirectory(java.lang.String, java.io.File, java.io.File, org.eclipse.rse.services.clientserver.ISystemOperationMonitor) */ public boolean extractVirtualDirectory(String fullVirtualName, File destinationParent, File destination, ISystemOperationMonitor archiveOperationMonitor) { - + // if the destination directory doesn't exist, create it if (!destinationParent.exists()) { - + if (!destinationParent.mkdirs()) { // TODO: log error return false; // quit if we fail to create the destination directory @@ -998,48 +1007,48 @@ public class SystemTarHandler implements ISystemArchiveHandler { else if (!destinationParent.isDirectory()) { return false; } - + fullVirtualName = ArchiveHandlerManager.cleanUpVirtualPath(fullVirtualName); - - + + int mutexLockStatus = SystemReentrantMutex.LOCK_STATUS_NOLOCK; try { mutexLockStatus = _mutex.waitForLock(archiveOperationMonitor, Long.MAX_VALUE); if (SystemReentrantMutex.LOCK_STATUS_NOLOCK != mutexLockStatus) { - + updateCache(); - + VirtualChild dir = vfs.getEntry(fullVirtualName); - + if (dir == null || !dir.isDirectory) { return false; } - + if (destination == null) { - + if (fullVirtualName.equals("")) { //$NON-NLS-1$ destination = destinationParent; } else { destination = new File(destinationParent, dir.name); - } + } } - + File topDir = destination; String topDirPath = topDir.getAbsolutePath(); - + // TODO: why are we checking that destination and destination parent are not equal? if (!destination.equals(destinationParent)) { - + if (destination.isFile() && destination.exists()) { SystemArchiveUtil.delete(destination); } - + destination.mkdirs(); } - + // if the directory does not exist, try to create it if (!topDir.exists() && !topDir.mkdirs()) { // TODO: log error @@ -1052,10 +1061,10 @@ public class SystemTarHandler implements ISystemArchiveHandler { return returnCode; } } - + // get the children of this directory VirtualChild[] children = vfs.getChildren(fullVirtualName); - + for (int i = 0; i < children.length; i++) { VirtualChild tempChild = children[i]; String childPath = topDirPath; @@ -1064,11 +1073,11 @@ public class SystemTarHandler implements ISystemArchiveHandler { childPath = topDirPath + File.separator + tempChild.name; } File childFile = new File(childPath); - + boolean returnCode = false; // if the child is a directory, then we need to extract it and its children if (tempChild.isDirectory) { - + // and now extract its children returnCode = extractVirtualDirectory(tempChild.fullName, childFile, (File) null, archiveOperationMonitor); } @@ -1086,7 +1095,7 @@ public class SystemTarHandler implements ISystemArchiveHandler { catch (IOException e) { e.printStackTrace(); - return false; + return false; } finally { @@ -1095,12 +1104,13 @@ public class SystemTarHandler implements ISystemArchiveHandler { return true; } - /** - * @see org.eclipse.rse.services.clientserver.archiveutils.ISystemArchiveHandler#add(java.io.File, java.lang.String, java.lang.String, ISystemOperationMonitor) + /* + * (non-Javadoc) + * @see org.eclipse.rse.services.clientserver.archiveutils.ISystemArchiveHandler#add(java.io.File, java.lang.String, java.lang.String, org.eclipse.rse.services.clientserver.ISystemOperationMonitor) */ public boolean add(File file, String virtualPath, String name, ISystemOperationMonitor archiveOperationMonitor ) { virtualPath = ArchiveHandlerManager.cleanUpVirtualPath(virtualPath); - + int mutexLockStatus = SystemReentrantMutex.LOCK_STATUS_NOLOCK; try { @@ -1108,11 +1118,11 @@ public class SystemTarHandler implements ISystemArchiveHandler { if (SystemReentrantMutex.LOCK_STATUS_NOLOCK != mutexLockStatus) { if (!file.isDirectory()) { - + // if it exists, call replace String fullVirtualName = getFullVirtualName(virtualPath, name); - if (exists(fullVirtualName, archiveOperationMonitor)) { - boolean returnCode = replace(fullVirtualName, file, name, archiveOperationMonitor); + if (exists(fullVirtualName, archiveOperationMonitor)) { + boolean returnCode = replace(fullVirtualName, file, name, archiveOperationMonitor); setArchiveOperationMonitorStatusDone(archiveOperationMonitor); return returnCode; } @@ -1138,19 +1148,19 @@ public class SystemTarHandler implements ISystemArchiveHandler { sources[i] = (File)children.get(i); newNames[i] = sources[i].getAbsolutePath().substring(charsToTrim); newNames[i] = newNames[i].replace('\\','/'); - + if (sources[i].isDirectory() && !newNames[i].endsWith("/")) { //$NON-NLS-1$ newNames[i] = newNames[i] + "/"; //$NON-NLS-1$ } } - + sources[numOfChildren] = file; newNames[numOfChildren] = name; - + if (!newNames[numOfChildren].endsWith("/")) { //$NON-NLS-1$ newNames[numOfChildren] = newNames[numOfChildren] + "/"; //$NON-NLS-1$ } - + boolean returnCode = add(sources, virtualPath, newNames, archiveOperationMonitor); setArchiveOperationMonitorStatusDone(archiveOperationMonitor); return returnCode; @@ -1159,7 +1169,7 @@ public class SystemTarHandler implements ISystemArchiveHandler { } catch (Exception e) { - e.printStackTrace(); + e.printStackTrace(); } finally { @@ -1168,127 +1178,128 @@ public class SystemTarHandler implements ISystemArchiveHandler { setArchiveOperationMonitorStatusDone(archiveOperationMonitor); return false; } - + /** - * Helper method. . . populates found with a - * collapsed list of all nodes in the subtree - * of the file system rooted at parent. + * Helper method. Populates given List found with a collapsed + * list of all nodes in the subtree of the file system rooted at + * parent. */ - public void listAllFiles(File parent, Vector found) { - + public void listAllFiles(File parent, List found) { + File[] children = parent.listFiles(); - + for (int i = 0; i < children.length; i++) { - + if (children[i].isDirectory()) { listAllFiles(children[i], found); } - + found.add(children[i]); } } - /** - * @see org.eclipse.rse.services.clientserver.archiveutils.ISystemArchiveHandler#add(java.io.File[], java.lang.String, java.lang.String[], ISystemOperationMonitor) + /* + * (non-Javadoc) + * @see org.eclipse.rse.services.clientserver.archiveutils.ISystemArchiveHandler#add(java.io.File[], java.lang.String, java.lang.String[], org.eclipse.rse.services.clientserver.ISystemOperationMonitor) */ public boolean add(File[] files, String virtualPath, String[] names, ISystemOperationMonitor archiveOperationMonitor) { - + int mutexLockStatus = SystemReentrantMutex.LOCK_STATUS_NOLOCK; File outputTempFile = null; TarOutputStream outStream = null; - + try { mutexLockStatus = _mutex.waitForLock(archiveOperationMonitor, Long.MAX_VALUE); if (SystemReentrantMutex.LOCK_STATUS_NOLOCK != mutexLockStatus) { - + updateCache(); - + virtualPath = ArchiveHandlerManager.cleanUpVirtualPath(virtualPath); - + int numFiles = files.length; - - for (int i = 0; i < numFiles; i++) { - + + for (int i = 0; i < numFiles; i++) { + if (!files[i].exists() || !files[i].canRead()) { setArchiveOperationMonitorStatusDone(archiveOperationMonitor); return false; } - + // if the entry already exists, then we should do a replace // TODO (KM): should we simply replace and return? // I think we should check each entry and replace or create for each one String fullVirtualName = getFullVirtualName(virtualPath, names[i]); - if (exists(fullVirtualName, archiveOperationMonitor)) { - + if (exists(fullVirtualName, archiveOperationMonitor)) { + boolean returnCode = replace(fullVirtualName, files[i], names[i], archiveOperationMonitor); setArchiveOperationMonitorStatusDone(archiveOperationMonitor); return returnCode; } } - - // open a new temp file which will be our destination for the new tar file - outputTempFile = new File(file.getAbsolutePath() + "temp"); //$NON-NLS-1$ - outStream = getTarOutputStream(outputTempFile); - - // get all the entries in the current tar - VirtualChild[] children = getVirtualChildrenList(archiveOperationMonitor); - - // if it is an empty temp file, no need to recreate it - if (children.length != 0) { - boolean isCanceled = createTar(children, outStream, (HashSet)null, archiveOperationMonitor); - if (isCanceled) - { - outStream.close(); - if (outputTempFile != null) - { - outputTempFile.delete(); - } - return false; - - } - } - VirtualChild[] newEntriesAdded = new VirtualChild[numFiles]; - // for each new file to add - for (int i = 0; i < numFiles; i++) { - - if (archiveOperationMonitor != null && archiveOperationMonitor.isCanceled()) - { - outStream.close(); - if (outputTempFile != null) - { - outputTempFile.delete(); - } - return false; - } - String childVirtualPath = virtualPath + "/" + names[i]; //$NON-NLS-1$ - - TarEntry newEntry = createTarEntry(files[i], childVirtualPath); - - // append the additional entry to the tar file - appendFile(files[i], newEntry, outStream); - - // add the new entry to the cache, so that the cache is updated - VirtualChild temp = getVirtualChild(newEntry); - newEntriesAdded[i] = temp; - } - - - // close output stream - outStream.close(); - - // replace the current tar file with the new one, and do not update cache since - // we just did - replaceFile(outputTempFile, false); - - //Also need to add the new entries into VFS - for (int i = 0; i < numFiles; i++) + + // open a new temp file which will be our destination for the new tar file + outputTempFile = new File(file.getAbsolutePath() + "temp"); //$NON-NLS-1$ + outStream = getTarOutputStream(outputTempFile); + + // get all the entries in the current tar + VirtualChild[] children = getVirtualChildrenList(archiveOperationMonitor); + + // if it is an empty temp file, no need to recreate it + if (children.length != 0) { + boolean isCanceled = createTar(children, outStream, (HashSet)null, archiveOperationMonitor); + if (isCanceled) { - vfs.addEntry(newEntriesAdded[i]); + outStream.close(); + if (outputTempFile != null) + { + outputTempFile.delete(); + } + return false; + } + } + VirtualChild[] newEntriesAdded = new VirtualChild[numFiles]; + // for each new file to add + for (int i = 0; i < numFiles; i++) { + + if (archiveOperationMonitor != null && archiveOperationMonitor.isCanceled()) + { + outStream.close(); + if (outputTempFile != null) + { + outputTempFile.delete(); + } + return false; + } + String childVirtualPath = virtualPath + "/" + names[i]; //$NON-NLS-1$ + + TarEntry newEntry = createTarEntry(files[i], childVirtualPath); + + // append the additional entry to the tar file + appendFile(files[i], newEntry, outStream); + + // add the new entry to the cache, so that the cache is updated + VirtualChild temp = getVirtualChild(newEntry); + newEntriesAdded[i] = temp; + } + + + // close output stream + outStream.close(); + + // replace the current tar file with the new one, and do not update cache since + // we just did + replaceFile(outputTempFile, false); + + //Also need to add the new entries into VFS + for (int i = 0; i < numFiles; i++) + { + vfs.addEntry(newEntriesAdded[i]); + } } - + } catch (IOException e) { e.printStackTrace(); @@ -1318,82 +1329,87 @@ public class SystemTarHandler implements ISystemArchiveHandler { setArchiveOperationMonitorStatusDone(archiveOperationMonitor); return true; } - + /** - * Create a tar file from the given virtual child objects, using the given output stream and omitting - * the children in the given set. - * @param children an array of virtual children from which to create a tar file. + * Create a tar file from the given virtual child objects, using the given + * output stream and omitting the children in the given set. + * + * @param children an array of virtual children from which to create a tar + * file. * @param outStream the tar output stream to use. - * @param omitChildren the set of names for children that should be omitted from the given array of virtual children. + * @param omitChildren the set of names for children that should be omitted + * from the given array of virtual children. * @param archiveOperationMonitor the operation progress monitor + * @return true if the operation has been canceled, false otherwise * @throws IOException if an I/O exception occurs. + * @since org.eclipse.rse.services 3.0 */ protected boolean createTar(VirtualChild[] children, TarOutputStream outStream, HashSet omitChildren, ISystemOperationMonitor archiveOperationMonitor) throws IOException { - + // TODO: if all children are to be deleted, we leave the tar file with a dummy entry if (omitChildren != null && children.length == omitChildren.size()) { return false; } - + TarFile tarFile = getTarFile(); - + // go through each child for (int i = 0; i < children.length; i++) { - + if (archiveOperationMonitor != null && archiveOperationMonitor.isCanceled()) { //the operation has been canceled return true; } - // if entry name is in the omit set, then do not include it + // if entry name is in the omit set, then do not include it if (omitChildren != null && omitChildren.contains(children[i].fullName)) { continue; } - + // if child is a directory, then just add an entry for it // there is no data if (children[i].isDirectory) { - + // include a '/' at the end, since it is a directory TarEntry nextEntry = tarFile.getEntry(children[i].fullName + "/"); //$NON-NLS-1$ - + // put the entry outStream.putNextEntry(nextEntry); - + // close the entry outStream.closeEntry(); } // otherwise child is a file, so add an entry for it // and then add data (i.e. file contents). else { - + TarEntry nextEntry = tarFile.getEntry(children[i].fullName); - + // get the input stream for the file contents InputStream inStream = tarFile.getInputStream(nextEntry); - + // put the entry outStream.putNextEntry(nextEntry); - + // write data byte[] buf = new byte[ITarConstants.BLOCK_SIZE]; int numRead = inStream.read(buf); - + while (numRead > 0) { outStream.write(buf, 0, numRead); - numRead = inStream.read(buf); + numRead = inStream.read(buf); } - + // close input stream inStream.close(); - + // close entry, but do not close the output stream outStream.closeEntry(); } } return false; } - + /** * Appends a file to a tar output stream, using the given entry that represents the file. * @param file the file to be appended to the tar output stream. @@ -1402,31 +1418,31 @@ public class SystemTarHandler implements ISystemArchiveHandler { * @throws IOException if an I/O error occurs. */ protected void appendFile(File file, TarEntry entry, TarOutputStream outStream) throws IOException { - + // put the next entry in the output stream outStream.putNextEntry(entry); - + // now write data if it is a file // there is no data for folders if (!file.isDirectory()) { BufferedInputStream inStream = new BufferedInputStream(new FileInputStream(file)); - + byte[] buf = new byte[ITarConstants.BLOCK_SIZE]; int numRead = inStream.read(buf); while (numRead > 0) { outStream.write(buf, 0, numRead); - numRead = inStream.read(buf); + numRead = inStream.read(buf); } - + // close the input stream inStream.close(); } - + // close the entry outStream.closeEntry(); } - + /** * Creates a tar entry for a file with the given virtual path. The entry * will contain the size and last modified time of the file. The entry's @@ -1436,26 +1452,26 @@ public class SystemTarHandler implements ISystemArchiveHandler { * @return the tar entry representing the given file. */ protected TarEntry createTarEntry(File file, String virtualPath) { - + String fullName = virtualPath; - + // if directory, end with a '/' if (file.isDirectory()) { - + if (!fullName.endsWith("/")) { //$NON-NLS-1$ - fullName = fullName + "/"; //$NON-NLS-1$ + fullName = fullName + "/"; //$NON-NLS-1$ } } - + // strip out leading '/' // TODO (KM): Why? if (fullName.startsWith("/")) { //$NON-NLS-1$ - fullName = fullName.substring(1); + fullName = fullName.substring(1); } - + // create a new entry and set its size and last modified time TarEntry entry = new TarEntry(fullName); - + // set the size if the file is not a directory if (!file.isDirectory()) { long size = file.length(); @@ -1464,58 +1480,58 @@ public class SystemTarHandler implements ISystemArchiveHandler { else { entry.setSize(0); } - + // set modified time long lastModified = file.lastModified(); entry.setModificationTime(lastModified); - + // set the user name String userName = System.getProperty("user.name"); //$NON-NLS-1$ - + if (userName != null) { entry.setUserName(userName); } - + // set user permissions boolean canRead = file.canRead(); boolean canWrite = file.canWrite(); - + // getting execute permission is a bit tricky // need to go through security manager boolean canExecute = false; - + // first get the system security manager SecurityManager sm = System.getSecurityManager(); - + // if there is no security manager then create a new one if (sm == null) { sm = new SecurityManager(); } - + try { - + // if security manager successfully created, check permission - // create a file permission to check execute - FilePermission permission = new FilePermission(file.getAbsolutePath(), "execute"); //$NON-NLS-1$ - - // this call will throw a SecurityException if permission does not exist - sm.checkPermission(permission); - canExecute = true; - + // create a file permission to check execute + FilePermission permission = new FilePermission(file.getAbsolutePath(), "execute"); //$NON-NLS-1$ + + // this call will throw a SecurityException if permission does not exist + sm.checkPermission(permission); + canExecute = true; + } catch(SecurityException e) { canExecute = false; } - + entry.setUserMode(canRead, canWrite, canExecute); - + // calculate checksum entry.calculateChecksum(); - + return entry; } - + /** * Changes a tar entry according to the file information and given path. The given path * will be the new name of the entry. The size and last modified fields will be changed @@ -1526,30 +1542,30 @@ public class SystemTarHandler implements ISystemArchiveHandler { * @return the changed entry. */ protected TarEntry changeTarEntry(TarEntry entry, File file, String virtualPath) { - + // TODO (KM): This does not update the permissions in the entry according to the // file permissions on disk. Need to look at how to retrieve permissions for owner, group // and other, and then have to set these in the entry accordingly. - + String fullName = virtualPath; - + // if directory, end with a '/' if (file.isDirectory()) { - + if (!fullName.endsWith("/")) { //$NON-NLS-1$ - fullName = fullName + "/"; //$NON-NLS-1$ + fullName = fullName + "/"; //$NON-NLS-1$ } } // strip out leading '/' - // TODO (KM): Why? + // TODO (KM): Why? if (fullName.startsWith("/")) { //$NON-NLS-1$ - fullName = fullName.substring(1); + fullName = fullName.substring(1); } - + // change entry name entry.setName(fullName); - + // update size field in entry if (!file.isDirectory()) { long size = file.length(); @@ -1558,17 +1574,17 @@ public class SystemTarHandler implements ISystemArchiveHandler { else { entry.setSize(0); } - + // update last modified field in entry long lastModified = file.lastModified(); entry.setModificationTime(lastModified); - + // calculate checksum entry.calculateChecksum(); - + return entry; } - + /** * Returns a virtual child given a tar entry. * @param entry a tar entry. @@ -1582,9 +1598,9 @@ public class SystemTarHandler implements ISystemArchiveHandler { child.setCompressionMethod(""); //$NON-NLS-1$; child.setSize(entry.getSize()); child.setTimeStamp(entry.getModificationTime()); - return child; + return child; } - + /** * update a virtual child given a tar entry. * @param entry a tar entry. @@ -1598,54 +1614,54 @@ public class SystemTarHandler implements ISystemArchiveHandler { child.setCompressionMethod(""); //$NON-NLS-1$; child.setSize(entry.getSize()); child.setTimeStamp(entry.getModificationTime()); - return child; + return child; } - + /** * Replaces the old tar file managed by the handler with the given file, and optionally update * the cache. * @param newFile the new tar file. * @param updateCache true to update the cache, false otherwise. * Only specify false if the cache has already been updated to reflect the - * contents of this new file. + * contents of this new file. * @throws IOException if an I/O problem occurs. */ protected void replaceFile(File newFile, boolean updateCache) throws IOException { String name = file.getAbsolutePath(); - + // create a temp file (in case something goes wrong) File tempFile = new File(name + ".old"); //$NON-NLS-1$ - + // rename current file to tempFile file.renameTo(tempFile); - + // rename the new file to the file this handler manages newFile.renameTo(file); - + // reinitialize init(file); - + // if we do not want to update the cache, we set the last modified time during cache to // the modified time of the file, so when we call updateCache, it'll do nothing if (!updateCache) { modTimeDuringCache = file.lastModified(); } - + // update cache if necessary updateCache(); - + // delete the temporary file tempFile.delete(); } - - + + /* * (non-Javadoc) * @see org.eclipse.rse.services.clientserver.archiveutils.ISystemArchiveHandler#replace(java.lang.String, java.io.File, java.lang.String, org.eclipse.rse.services.clientserver.ISystemOperationMonitor) */ public boolean replace(String fullVirtualName, File file, String name, ISystemOperationMonitor archiveOperationMonitor) { - + // update our cache before accessing cache try { updateCache(); @@ -1654,34 +1670,34 @@ public class SystemTarHandler implements ISystemArchiveHandler { // TODO: log error return false; } - + if (!file.exists() && !file.canRead()) { return false; } - + fullVirtualName = ArchiveHandlerManager.cleanUpVirtualPath(fullVirtualName); - + // if the virtual file does not exist, we actually want to add if (!exists(fullVirtualName, archiveOperationMonitor)) { return add(file, fullVirtualName, name, archiveOperationMonitor); } - + try { - + // open a new temp file which will be our destination for the new tar file File outputTempFile = new File(getArchive().getAbsolutePath() + "temp"); //$NON-NLS-1$ - + TarOutputStream outStream = getTarOutputStream(outputTempFile); - + // get all the entries VirtualChild[] children = getVirtualChildrenList(archiveOperationMonitor); - + // create a set of omissions HashSet omissions = new HashSet(); - + // add the virtual file to be replaced omissions.add(fullVirtualName); - + boolean isCanceled = createTar(children, outStream, omissions, archiveOperationMonitor); if (isCanceled) { @@ -1691,14 +1707,14 @@ public class SystemTarHandler implements ISystemArchiveHandler { outputTempFile.delete(); } return false; - + } - + // now append the new file to the tar String parentVirtualPath = null; int i = fullVirtualName.lastIndexOf("/"); //$NON-NLS-1$ - + // if the virtual name has no '/', then we will replace it with the // new name if (i == -1) { @@ -1708,33 +1724,33 @@ public class SystemTarHandler implements ISystemArchiveHandler { else { parentVirtualPath = fullVirtualName.substring(0, i); } - + String virtualPath = parentVirtualPath + "/" + name; //$NON-NLS-1$ - + // get the existing entry for the file TarFile tarFile = getTarFile(); TarEntry entry = tarFile.getEntry(fullVirtualName); - + // update the entry with the file information entry = changeTarEntry(entry, file, virtualPath); - + // now append this entry to the output stream appendFile(file, entry, outStream); - + // remove old entry from cache //vfs.removeEntry(vfs.getEntry(fullVirtualName)); - + // add the new entry to cache VirtualChild temp = updateVirtualChild(entry, vfs.getEntry(fullVirtualName)); //vfs.addEntry(temp); - + // close output stream outStream.close(); - + // replace the current tar file with the new one, and do not update cache since // we just did replaceFile(outputTempFile, false); - + return true; } catch (IOException e) { @@ -1743,19 +1759,28 @@ public class SystemTarHandler implements ISystemArchiveHandler { } } - /** - * @see org.eclipse.rse.services.clientserver.archiveutils.ISystemArchiveHandler#delete(java.lang.String, ISystemOperationMonitor) + /* + * (non-Javadoc) + * @see org.eclipse.rse.services.clientserver.archiveutils.ISystemArchiveHandler#delete(java.lang.String, org.eclipse.rse.services.clientserver.ISystemOperationMonitor) */ - public boolean delete(String fullVirtualName, ISystemOperationMonitor archiveOperationMonitor) + public boolean delete(String fullVirtualName, ISystemOperationMonitor archiveOperationMonitor) { boolean returnCode = doDelete(fullVirtualName, archiveOperationMonitor); setArchiveOperationMonitorStatusDone(archiveOperationMonitor); return returnCode; } - - + + + /** + * Delete a virtual object. + * + * @param fullVirtualName virtual path identifying the object + * @param archiveOperationMonitor the operation progress monitor + * @return true if successful, false otherwise + * @since org.eclipse.rse.services 3.0 + */ protected boolean doDelete(String fullVirtualName, ISystemOperationMonitor archiveOperationMonitor) { - + File outputTempFile = null; int mutexLockStatus = SystemReentrantMutex.LOCK_STATUS_NOLOCK; try @@ -1767,36 +1792,36 @@ public class SystemTarHandler implements ISystemArchiveHandler { fullVirtualName = ArchiveHandlerManager.cleanUpVirtualPath(fullVirtualName); VirtualChild child = getVirtualFile(fullVirtualName, archiveOperationMonitor); VirtualChild[] omitArray = new VirtualChild[0]; - + // child does not exist, so quit if (!child.exists()) { return false; } - + // child is a directory, so get its children since we need to delete them as well if (child.isDirectory) { omitArray = getVirtualChildrenList(fullVirtualName, archiveOperationMonitor); } - + // open a new temp file which will be our destination for the new tar file outputTempFile = new File(file.getAbsolutePath() + "temp"); //$NON-NLS-1$ TarOutputStream outStream = getTarOutputStream(outputTempFile); - - // get all the entries in the current tar + + // get all the entries in the current tar VirtualChild[] children = getVirtualChildrenList(archiveOperationMonitor); - + // create a set to hold omissions HashSet omissions = new HashSet(); - + // add the child to it omissions.add(child.fullName); - + // now go through array of children to be deleted // this will be of length 0 if the child is not a directory for (int i = 0; i < omitArray.length; i++) { omissions.add(omitArray[i].fullName); } - + boolean isCanceled = createTar(children, outStream, omissions, archiveOperationMonitor); if (isCanceled) { @@ -1806,20 +1831,20 @@ public class SystemTarHandler implements ISystemArchiveHandler { outputTempFile.delete(); } return false; - + } - + // delete the child from the cache (this will also delete its children if it // is a directory) vfs.removeEntry(child); - + // close output stream outStream.close(); - + // replace the current tar file with the new one, and do not update cache since // we just did - replaceFile(outputTempFile, false); - + replaceFile(outputTempFile, false); + return true; } } @@ -1833,25 +1858,26 @@ public class SystemTarHandler implements ISystemArchiveHandler { { releaseMutex(mutexLockStatus); } - return false; + return false; } - /** - * @see org.eclipse.rse.services.clientserver.archiveutils.ISystemArchiveHandler#rename(java.lang.String, java.lang.String, ISystemOperationMonitor) + /* + * (non-Javadoc) + * @see org.eclipse.rse.services.clientserver.archiveutils.ISystemArchiveHandler#rename(java.lang.String, java.lang.String, org.eclipse.rse.services.clientserver.ISystemOperationMonitor) */ public boolean rename(String fullVirtualName, String newName, ISystemOperationMonitor archiveOperationMonitor) { fullVirtualName = ArchiveHandlerManager.cleanUpVirtualPath(fullVirtualName); int i = fullVirtualName.lastIndexOf("/"); //$NON-NLS-1$ - + boolean resultCode = false; - + // if the original does not have any separator, simply rename it. - if (i == -1) + if (i == -1) { resultCode = fullRename(fullVirtualName, newName, archiveOperationMonitor); } // otherwise, get the parent path and append the new name to it. - else + else { String fullNewName = fullVirtualName.substring(0, i+1) + newName; resultCode = fullRename(fullVirtualName, fullNewName, archiveOperationMonitor); @@ -1860,15 +1886,16 @@ public class SystemTarHandler implements ISystemArchiveHandler { return resultCode; } - /** - * @see org.eclipse.rse.services.clientserver.archiveutils.ISystemArchiveHandler#move(java.lang.String, java.lang.String, ISystemOperationMonitor) + /* + * (non-Javadoc) + * @see org.eclipse.rse.services.clientserver.archiveutils.ISystemArchiveHandler#move(java.lang.String, java.lang.String, org.eclipse.rse.services.clientserver.ISystemOperationMonitor) */ public boolean move(String fullVirtualName, String destinationVirtualPath, ISystemOperationMonitor archiveOperationMonitor) { fullVirtualName = ArchiveHandlerManager.cleanUpVirtualPath(fullVirtualName); destinationVirtualPath = ArchiveHandlerManager.cleanUpVirtualPath(destinationVirtualPath); - + int i = fullVirtualName.lastIndexOf("/"); //$NON-NLS-1$ - + // if the original does not have any separator, simply append it to the destination path. if (i == -1) { return fullRename(fullVirtualName, destinationVirtualPath + "/" + fullVirtualName, archiveOperationMonitor); //$NON-NLS-1$ @@ -1885,33 +1912,33 @@ public class SystemTarHandler implements ISystemArchiveHandler { * @see org.eclipse.rse.services.clientserver.archiveutils.ISystemArchiveHandler#fullRename(java.lang.String, java.lang.String, org.eclipse.rse.services.clientserver.ISystemOperationMonitor) */ public boolean fullRename(String fullVirtualName, String newFullVirtualName, ISystemOperationMonitor archiveOperationMonitor) { - + int mutexLockStatus = SystemReentrantMutex.LOCK_STATUS_NOLOCK; File outputTempFile = null; // update our cache before accessing cache - try - { + try + { mutexLockStatus = _mutex.waitForLock(archiveOperationMonitor, Long.MAX_VALUE); if (SystemReentrantMutex.LOCK_STATUS_NOLOCK != mutexLockStatus) { - + fullVirtualName = ArchiveHandlerManager.cleanUpVirtualPath(fullVirtualName); newFullVirtualName = ArchiveHandlerManager.cleanUpVirtualPath(newFullVirtualName); VirtualChild child = getVirtualFile(fullVirtualName, archiveOperationMonitor); - + // if the virtual file to be renamed does not exist, then quit if (!child.exists()) { return false; } - - + + // open a new temp file which will be our destination for the new tar file outputTempFile = new File(file.getAbsolutePath() + "temp"); //$NON-NLS-1$ TarOutputStream outStream = getTarOutputStream(outputTempFile); - + // get all the entries VirtualChild[] children = getVirtualChildrenList(archiveOperationMonitor); - + // the rename list // a hashmap containing old name, new name associations for each // child that has to be renamed @@ -1919,31 +1946,31 @@ public class SystemTarHandler implements ISystemArchiveHandler { // a hashmap containing new name, old name associations for each // child that has to be renamed HashMap newOldNames = new HashMap(); - + // if the entry to rename is a directory, we need to rename all // its children entries if (child.isDirectory) { - + // add the entry itself to the rename list // include '/' in both the old name and the new name since it is a directory oldNewNames.put(fullVirtualName + "/", newFullVirtualName + "/"); //$NON-NLS-1$ //$NON-NLS-2$ newOldNames.put(newFullVirtualName + "/", fullVirtualName + "/"); //$NON-NLS-1$ //$NON-NLS-2$ - + // get all the children of the entry to be renamed VirtualChild[] childrenArray = getVirtualChildrenList(fullVirtualName, archiveOperationMonitor); - + // now we need to get the relative path of each child with respect to the virtual name // and append the relative path to the new virtual name for (int i = 0; i < childrenArray.length; i++) { - + int j = fullVirtualName.length(); - + // get the relative path with respect to the virtual name String suffix = childrenArray[i].fullName.substring(j); - + // add the relative path to the new virtual name String newName = newFullVirtualName + suffix; - + // if a child is a directory, ensure that '/'s are added both for the old name // and the new name if (childrenArray[i].isDirectory) { @@ -1961,7 +1988,7 @@ public class SystemTarHandler implements ISystemArchiveHandler { oldNewNames.put(fullVirtualName, newFullVirtualName); newOldNames.put(newFullVirtualName, fullVirtualName); } - + // create tar with renamed entries boolean isCanceled = createTar(children, outStream, oldNewNames, archiveOperationMonitor); if (isCanceled) @@ -1972,23 +1999,23 @@ public class SystemTarHandler implements ISystemArchiveHandler { outputTempFile.delete(); } return false; - + } - + if (true == isCanceled) { return false; } // close the output stream outStream.close(); - + // replace the current tar file with the new one, and force an update of the cache. // TODO: we force a fresh update of the cache because it is seemingly complicated // to do the delta upgrade of the cache. But investigate this, since it will // probably be more efficient replaceFile(outputTempFile, true); updateTree(newOldNames); - + return true; } else @@ -2007,95 +2034,101 @@ public class SystemTarHandler implements ISystemArchiveHandler { releaseMutex(mutexLockStatus); } } - + /** - * Creates a tar file from the given virtual child objects, using the given output stream and renaming entries - * according to hash map entries. - * @param children an array of virtual children from which to create a tar file. + * Creates a tar file from the given virtual child objects, using the given + * output stream and renaming entries according to hash map entries. + * + * @param children an array of virtual children from which to create a tar + * file. * @param outStream the tar output stream to use. - * @param renameMap a map containing associations between old names and new names. Old names are the keys - * in the map, and the values are the new names. + * @param renameMap a map containing associations between old names and new + * names. Old names are the keys in the map, and the values are + * the new names. + * @param archiveOperationMonitor the operation progress monitor + * @return true if the operation has been canceled, false otherwise. * @throws IOException if an I/O exception occurs. + * @since org.eclipse.rse.services 3.0 */ protected boolean createTar(VirtualChild[] children, TarOutputStream outStream, HashMap renameMap, ISystemOperationMonitor archiveOperationMonitor) throws IOException { - + TarFile tarFile = getTarFile(); - + // go through each child for (int i = 0; i < children.length; i++) { - + if (archiveOperationMonitor != null && archiveOperationMonitor.isCanceled()) { //the operation has been canceled return true; } - + VirtualChild child = children[i]; String oldPath = child.getArchiveStandardName(); String newPath = oldPath; boolean needToRename = false; - + // if entry is to be renamed, get the new path if (renameMap.containsKey(oldPath)) { newPath = (String)(renameMap.get(oldPath)); child.renameTo(newPath); needToRename = true; } - + TarEntry nextEntry = tarFile.getEntry(oldPath); - + // if child is a directory, then just add an entry for it // there is no data if (children[i].isDirectory) { - + // if we need to rename the entry, then do so now if (needToRename) { nextEntry = changeTarEntryName(nextEntry, newPath); } - + // put the entry outStream.putNextEntry(nextEntry); - + // close the entry outStream.closeEntry(); } // otherwise child is a file, so add an entry for it // and then add data (i.e. file contents). else { - + // get the input stream for the file contents InputStream inStream = tarFile.getInputStream(nextEntry); - + // if we need to rename the entry, then do so now // this must be done after we have obtained the input stream // since tarFile.getInputStream() depends on the entry name if (needToRename) { nextEntry = changeTarEntryName(nextEntry, newPath); } - + // put the entry outStream.putNextEntry(nextEntry); - + // write data byte[] buf = new byte[ITarConstants.BLOCK_SIZE]; int numRead = inStream.read(buf); - + while (numRead > 0) { outStream.write(buf, 0, numRead); - numRead = inStream.read(buf); + numRead = inStream.read(buf); } - + // close input stream inStream.close(); - + // close entry, but do not close the output stream outStream.closeEntry(); } } - + return false; } - + /** * Changes the name of a tar entry. Also calculates the new checksum for the entry. * @param entry the entry for which the name has to be changed. @@ -2103,37 +2136,38 @@ public class SystemTarHandler implements ISystemArchiveHandler { * @return the changed entry. */ protected TarEntry changeTarEntryName(TarEntry entry, String newName) { - + // change entry path entry.setName(newName); - + // calculate checksum entry.calculateChecksum(); - + return entry; } - - /** - * @see org.eclipse.rse.services.clientserver.archiveutils.ISystemArchiveHandler#getFiles(java.lang.String[], ISystemOperationMonitor) + + /* + * (non-Javadoc) + * @see org.eclipse.rse.services.clientserver.archiveutils.ISystemArchiveHandler#getFiles(java.lang.String[], org.eclipse.rse.services.clientserver.ISystemOperationMonitor) */ public File[] getFiles(String[] fullNames, ISystemOperationMonitor archiveOperationMonitor) { File[] files = new File[fullNames.length]; - + for (int i = 0; i < fullNames.length; i++) { String name; String fullName = fullNames[i]; fullName = ArchiveHandlerManager.cleanUpVirtualPath(fullName); int j = fullName.lastIndexOf("/"); //$NON-NLS-1$ - + if (j == -1) { name = fullName; } else { name = fullName.substring(j+1); } - - try { + + try { files[i] = File.createTempFile(name, "virtual"); //$NON-NLS-1$ files[i].deleteOnExit(); extractVirtualFile(fullNames[i], files[i], archiveOperationMonitor); @@ -2143,12 +2177,13 @@ public class SystemTarHandler implements ISystemArchiveHandler { return null; } } - + return files; } - /** - * @see org.eclipse.rse.services.clientserver.archiveutils.ISystemArchiveHandler#createFolder(java.lang.String, ISystemOperationMonitor) + /* + * (non-Javadoc) + * @see org.eclipse.rse.services.clientserver.archiveutils.ISystemArchiveHandler#createFolder(java.lang.String, org.eclipse.rse.services.clientserver.ISystemOperationMonitor) */ public boolean createFolder(String fullVirtualName, ISystemOperationMonitor archiveOperationMonitor) { fullVirtualName = ArchiveHandlerManager.cleanUpVirtualPath(fullVirtualName); @@ -2158,8 +2193,9 @@ public class SystemTarHandler implements ISystemArchiveHandler { return returnCode; } - /** - * @see org.eclipse.rse.services.clientserver.archiveutils.ISystemArchiveHandler#createFile(java.lang.String, ISystemOperationMonitor) + /* + * (non-Javadoc) + * @see org.eclipse.rse.services.clientserver.archiveutils.ISystemArchiveHandler#createFile(java.lang.String, org.eclipse.rse.services.clientserver.ISystemOperationMonitor) */ public boolean createFile(String fullVirtualName, ISystemOperationMonitor archiveOperationMonitor) { fullVirtualName = ArchiveHandlerManager.cleanUpVirtualPath(fullVirtualName); @@ -2167,15 +2203,19 @@ public class SystemTarHandler implements ISystemArchiveHandler { setArchiveOperationMonitorStatusDone(archiveOperationMonitor); return returnCode; } - + /** - * Creates a virtual object that does not already exist in the virtual file system. - * Creates an empty file in the tar file. + * Creates a virtual object that does not already exist in the virtual file + * system. Creates an empty file in the tar file. + * * @param name the name of the virtual object. - * @return true if the object was created successfully, false otherwise. + * @param archiveOperationMonitor the operation progress monitor + * @return true if the object was created successfully, + * false otherwise. + * @since org.eclipse.rse.services 3.0 */ protected boolean createVirtualObject(String name, ISystemOperationMonitor archiveOperationMonitor) { - + File outputTempFile = null; TarOutputStream outStream = null; int mutexLockStatus = SystemReentrantMutex.LOCK_STATUS_NOLOCK; @@ -2185,20 +2225,20 @@ public class SystemTarHandler implements ISystemArchiveHandler { if (SystemReentrantMutex.LOCK_STATUS_NOLOCK != mutexLockStatus) { updateCache(); - - + + // if the object already exists, return false if (exists(name, archiveOperationMonitor)) { return false; } - + // open a new temp file which will be our destination for the new tar file outputTempFile = new File(file.getAbsolutePath() + "temp"); //$NON-NLS-1$ outStream = getTarOutputStream(outputTempFile); - + // get all the entries VirtualChild[] children = getVirtualChildrenList(archiveOperationMonitor); - + // if it is an empty temp file, no need to recreate it if (children.length != 0) { boolean isCanceled = createTar(children, outStream, (HashSet)null, archiveOperationMonitor); @@ -2210,24 +2250,24 @@ public class SystemTarHandler implements ISystemArchiveHandler { outputTempFile.delete(); } return false; - + } } - + // append an empty file to the tar file TarEntry newEntry = appendEmptyFile(outStream, name); - + // add to cache VirtualChild temp = getVirtualChild(newEntry); vfs.addEntry(temp); - + // close the output stream outStream.close(); - + // replace the current tar file with the new one, but do not update the cache // since we have already updated to the cache replaceFile(outputTempFile, false); - + return true; } } @@ -2257,7 +2297,7 @@ public class SystemTarHandler implements ISystemArchiveHandler { } return false; } - + /** * Creates a new tar entry and appends it to the tar output stream with the given name. * @param outStream the tar output stream. @@ -2266,93 +2306,95 @@ public class SystemTarHandler implements ISystemArchiveHandler { * @throws IOException if an I/O error occurs. */ protected TarEntry appendEmptyFile(TarOutputStream outStream, String name) throws IOException { - + // create a new entry with size 0 and the last modified time as the current time TarEntry newEntry = new TarEntry(name); newEntry.setSize(0); newEntry.setModificationTime(System.currentTimeMillis()); - + // set the user name String userName = System.getProperty("user.name"); //$NON-NLS-1$ - + if (userName != null) { newEntry.setUserName(userName); } - + // set user permissions boolean canRead = file.canRead(); boolean canWrite = file.canWrite(); - + // getting execute permission is a bit tricky // need to go through security manager boolean canExecute = false; - + // first get the system security manager SecurityManager sm = System.getSecurityManager(); - + // if there is no security manager then create a new one if (sm == null) { sm = new SecurityManager(); } - + try { - + // if security manager successfully created, check permission - - // create a file permission to check execute - FilePermission permission = new FilePermission(file.getAbsolutePath(), "execute"); //$NON-NLS-1$ - - // this call will throw a SecurityException if permission does not exist - sm.checkPermission(permission); - canExecute = true; - + + // create a file permission to check execute + FilePermission permission = new FilePermission(file.getAbsolutePath(), "execute"); //$NON-NLS-1$ + + // this call will throw a SecurityException if permission does not exist + sm.checkPermission(permission); + canExecute = true; + } catch(SecurityException e) { canExecute = false; } - + newEntry.setUserMode(canRead, canWrite, canExecute); - + // calculate checksum newEntry.calculateChecksum(); - + // put the entry outStream.putNextEntry(newEntry); - + // close the entry outStream.closeEntry(); - - return newEntry; + + return newEntry; } - /** + /* + * (non-Javadoc) * @see org.eclipse.rse.services.clientserver.archiveutils.ISystemArchiveHandler#getStandardName(org.eclipse.rse.services.clientserver.archiveutils.VirtualChild) */ public String getStandardName(VirtualChild vc) { - + if (vc.isDirectory) { return vc.fullName + "/"; //$NON-NLS-1$ } - + return vc.fullName; } - - /** + + /* + * (non-Javadoc) * @see org.eclipse.rse.services.clientserver.archiveutils.ISystemArchiveHandler#create() */ public boolean create() { - + try { // create output stream TarOutputStream outStream = getTarOutputStream(file); - + // close output stream, so we have an empty tar file outStream.close(); - + // recreate cache createCache(); - + // set cache time modTimeDuringCache = file.lastModified(); } @@ -2362,39 +2404,39 @@ public class SystemTarHandler implements ISystemArchiveHandler { return true; } - + public SystemSearchLineMatch[] search(String fullVirtualName, SystemSearchStringMatcher matcher, ISystemOperationMonitor archiveOperationMonitor) { // if the search string is empty or if it is "*", then return no matches // since it is a file search if (matcher.isSearchStringEmpty() || matcher.isSearchStringAsterisk()) { return new SystemSearchLineMatch[0]; } - + fullVirtualName = ArchiveHandlerManager.cleanUpVirtualPath(fullVirtualName); - + VirtualChild vc = getVirtualFile(fullVirtualName, archiveOperationMonitor); - + if (!vc.exists() || vc.isDirectory) { return new SystemSearchLineMatch[0]; } - + TarFile tarFile = getTarFile(); TarEntry entry = tarFile.getEntry(fullVirtualName); InputStream is = null; - + try { is = tarFile.getInputStream(entry); - + if (is == null) { return new SystemSearchLineMatch[0]; } - + InputStreamReader isr = new InputStreamReader(is); BufferedReader bufReader = new BufferedReader(isr); - + SystemSearchStringMatchLocator locator = new SystemSearchStringMatchLocator(bufReader, matcher); SystemSearchLineMatch[] matches = locator.locateMatches(); - + if (matches == null) { return new SystemSearchLineMatch[0]; } @@ -2407,15 +2449,20 @@ public class SystemTarHandler implements ISystemArchiveHandler { return new SystemSearchLineMatch[0]; } } - + + /* + * (non-Javadoc) + * @see org.eclipse.rse.services.clientserver.archiveutils.ISystemArchiveHandler#exists() + */ public boolean exists() { return true; } + /* (non-Javadoc) * @see org.eclipse.rse.services.clientserver.archiveutils.ISystemArchiveHandler#getCommentFor(java.lang.String) */ - public String getCommentFor(String fullVirtualName) + public String getCommentFor(String fullVirtualName) { return ""; //$NON-NLS-1$ } @@ -2423,7 +2470,7 @@ public class SystemTarHandler implements ISystemArchiveHandler { /* (non-Javadoc) * @see org.eclipse.rse.services.clientserver.archiveutils.ISystemArchiveHandler#getCompressedSizeFor(java.lang.String) */ - public long getCompressedSizeFor(String fullVirtualName) + public long getCompressedSizeFor(String fullVirtualName) { return getSizeFor(fullVirtualName); } @@ -2431,41 +2478,43 @@ public class SystemTarHandler implements ISystemArchiveHandler { /* (non-Javadoc) * @see org.eclipse.rse.services.clientserver.archiveutils.ISystemArchiveHandler#getCompressionMethodFor(java.lang.String) */ - public String getCompressionMethodFor(String fullVirtualName) + public String getCompressionMethodFor(String fullVirtualName) { return ""; //$NON-NLS-1$ } - - + + /* (non-Javadoc) * @see org.eclipse.rse.services.clientserver.archiveutils.ISystemArchiveHandler#getArchiveComment() */ - public String getArchiveComment() + public String getArchiveComment() { return ""; //$NON-NLS-1$ } /** * Compresses the file file and adds it to the archive, - * saving it in the encoding specified by encoding if - * saving in text mode. - * Places the file in the virtual directory virtualPath. Pass the - * name as the parameter name. If the virtual path does not exist - * in the archive, create it. If file is a directory, copy it and - * its contents into the archive, maintaining the tree structure. + * saving it in the encoding specified by encoding if saving + * in text mode. Places the file in the virtual directory + * virtualPath. Pass the name as the parameter + * name. If the virtual path does not exist in the archive, + * create it. If file is a directory, copy it and its + * contents into the archive, maintaining the tree structure. + * * @param file the file to be added to the archive * @param virtualPath the destination of the file * @param name the name of the result virtual file * @param encoding the file encoding to use - * @param registry the file type to use (text or binary) + * @param registry the file type to use (text or binary) * @param archiveOperationMonitor the operation progress monitor * @return true if and only if the add was successful - */ + * @since org.eclipse.rse.services 3.0 + */ public boolean add(File file, String virtualPath, String name, String encoding, ISystemFileTypes registry, ISystemOperationMonitor archiveOperationMonitor) { return add(file, virtualPath, name, archiveOperationMonitor); } - + /* (non-Javadoc) * @see org.eclipse.rse.services.clientserver.archiveutils.ISystemArchiveHandler#add(java.io.File, java.lang.String, java.lang.String, java.lang.String, java.lang.String, boolean) */ @@ -2473,6 +2522,7 @@ public class SystemTarHandler implements ISystemArchiveHandler { String sourceEncoding, String targetEncoding, boolean isText, ISystemOperationMonitor archiveOperationMonitor) { return add(file, virtualPath, name, archiveOperationMonitor); } + /* (non-Javadoc) * @see org.eclipse.rse.services.clientserver.archiveutils.ISystemArchiveHandler#add(java.io.File[], java.lang.String, java.lang.String[], java.lang.String[], java.lang.String[], boolean[]) */ @@ -2480,6 +2530,7 @@ public class SystemTarHandler implements ISystemArchiveHandler { String[] sourceEncodings, String[] targetEncodings, boolean[] isTexts, ISystemOperationMonitor archiveOperationMonitor) { return add(files, virtualPath, names, archiveOperationMonitor); } + /* (non-Javadoc) * @see org.eclipse.rse.services.clientserver.archiveutils.ISystemArchiveHandler#extractVirtualDirectory(java.lang.String, java.io.File, java.io.File, java.lang.String, boolean) */ @@ -2487,6 +2538,7 @@ public class SystemTarHandler implements ISystemArchiveHandler { File destination, String sourceEncoding, boolean isText, ISystemOperationMonitor archiveOperationMonitor) { return extractVirtualDirectory(dir, destinationParent, destination, archiveOperationMonitor); } + /* (non-Javadoc) * @see org.eclipse.rse.services.clientserver.archiveutils.ISystemArchiveHandler#extractVirtualDirectory(java.lang.String, java.io.File, java.lang.String, boolean) */ @@ -2494,6 +2546,7 @@ public class SystemTarHandler implements ISystemArchiveHandler { String sourceEncoding, boolean isText, ISystemOperationMonitor archiveOperationMonitor) { return extractVirtualDirectory(dir, destinationParent, archiveOperationMonitor); } + /* (non-Javadoc) * @see org.eclipse.rse.services.clientserver.archiveutils.ISystemArchiveHandler#extractVirtualFile(java.lang.String, java.io.File, java.lang.String, boolean) */ @@ -2501,62 +2554,63 @@ public class SystemTarHandler implements ISystemArchiveHandler { String sourceEncoding, boolean isText, ISystemOperationMonitor archiveOperationMonitor) { return extractVirtualFile(fullVirtualName, destination, archiveOperationMonitor); } - - /** + + /* + * (non-Javadoc) * @see org.eclipse.rse.services.clientserver.archiveutils.ISystemArchiveHandler#getClassification(java.lang.String) */ public String getClassification(String fullVirtualName) { fullVirtualName = ArchiveHandlerManager.cleanUpVirtualPath(fullVirtualName); - + // default type String type = "file"; //$NON-NLS-1$ - + // if it's not a class file, we do not classify it if (!fullVirtualName.endsWith(".class")) { //$NON-NLS-1$ return type; } - + // get the entry with that name TarEntry entry = getTarFile().getEntry(fullVirtualName); - + // get the input stream for the entry InputStream stream = null; - + // class file parser BasicClassFileParser parser = null; - + boolean isExecutable = false; - + try { stream = getTarFile().getInputStream(entry); - + // use class file parser to parse the class file parser = new BasicClassFileParser(stream); parser.parse(); - + // query if it is executable, i.e. whether it has main method isExecutable = parser.isExecutable(); } catch (IOException e) { // TODO: log it - + // we assume not executable isExecutable = false; } - + // if it is executable, then also get qualified class name if (isExecutable && parser != null) { type = "executable(java"; //$NON-NLS-1$ - + String qualifiedClassName = parser.getQualifiedClassName(); - + if (qualifiedClassName != null) { - type = type + ":" + qualifiedClassName; //$NON-NLS-1$ + type = type + ":" + qualifiedClassName; //$NON-NLS-1$ } - + type = type + ")"; //$NON-NLS-1$ } - + return type; } @@ -2573,7 +2627,7 @@ public class SystemTarHandler implements ISystemArchiveHandler { // TODO Auto-generated method stub return false; } - + /** * Construct the full virtual name of a virtual file from its virtual path and name. * @param virtualPath the virtual path of this virtual file @@ -2593,7 +2647,7 @@ public class SystemTarHandler implements ISystemArchiveHandler { } return fullVirtualName; } - + private void releaseMutex(int mutexLockStatus) { //We only release the mutex if we aquired it, not borrowed it. @@ -2602,7 +2656,7 @@ public class SystemTarHandler implements ISystemArchiveHandler { _mutex.release(); } } - + private void setArchiveOperationMonitorStatusDone(ISystemOperationMonitor archiveOperationMonitor) { //We only set the status of the archive operation montor to done if it is not been canceled. @@ -2611,14 +2665,15 @@ public class SystemTarHandler implements ISystemArchiveHandler { archiveOperationMonitor.setDone(true); } } - + /** - * Get the tar output stream for a given file. - * This method can be overridden by subclass to return compressed output steam if needed. + * Get the tar output stream for a given file. This method can be overridden + * by subclass to return compressed output steam if needed. + * * @param outputFile the output file to create stream - * @return OutputStream the output stream to write - * @throws FileNotFoundException when the output file doesn't exists - * @since 3.0 + * @return OutputStream the output stream to write + * @throws FileNotFoundException when the output file doesn't exist + * @since org.eclipse.rse.services 3.0 */ protected TarOutputStream getTarOutputStream(File outputFile) throws FileNotFoundException { TarOutputStream outStream = new TarOutputStream(new FileOutputStream(outputFile)); diff --git a/rse/plugins/org.eclipse.rse.services/clientserver/org/eclipse/rse/services/clientserver/archiveutils/SystemTgzHandler.java b/rse/plugins/org.eclipse.rse.services/clientserver/org/eclipse/rse/services/clientserver/archiveutils/SystemTgzHandler.java index 87152c534d7..318edf4bb43 100644 --- a/rse/plugins/org.eclipse.rse.services/clientserver/org/eclipse/rse/services/clientserver/archiveutils/SystemTgzHandler.java +++ b/rse/plugins/org.eclipse.rse.services/clientserver/org/eclipse/rse/services/clientserver/archiveutils/SystemTgzHandler.java @@ -16,7 +16,6 @@ import java.io.FileOutputStream; import java.io.IOException; import java.util.zip.GZIPOutputStream; -import org.eclipse.rse.internal.services.clientserver.archiveutils.TarOutputStream; import org.eclipse.rse.internal.services.clientserver.archiveutils.TgzFile; /** diff --git a/rse/plugins/org.eclipse.rse.services/clientserver/org/eclipse/rse/services/clientserver/archiveutils/SystemZipHandler.java b/rse/plugins/org.eclipse.rse.services/clientserver/org/eclipse/rse/services/clientserver/archiveutils/SystemZipHandler.java index 39262cf8c1a..6627792e1e0 100644 --- a/rse/plugins/org.eclipse.rse.services/clientserver/org/eclipse/rse/services/clientserver/archiveutils/SystemZipHandler.java +++ b/rse/plugins/org.eclipse.rse.services/clientserver/org/eclipse/rse/services/clientserver/archiveutils/SystemZipHandler.java @@ -7,21 +7,22 @@ * * Initial Contributors: * The following IBM employees contributed to the Remote System Explorer - * component that contains this file: David McKnight, Kushal Munir, - * Michael Berger, David Dykstal, Phil Coulthard, Don Yantzi, Eric Simpson, + * component that contains this file: David McKnight, Kushal Munir, + * Michael Berger, David Dykstal, Phil Coulthard, Don Yantzi, Eric Simpson, * Emily Bruner, Mazen Faraj, Adrian Storisteanu, Li Ding, and Kent Hawley. * * Contributors: * {Name} (company) - description of contribution. - * Xuan Chen (IBM) - [192741] [Archives] Move a folder from within an Archive doesn't work if > 1 level deep - * Xuan Chen (IBM) - [194293] [Local][Archives] Saving file second time in an Archive Errors - * Xuan Chen (IBM) - [181784] [archivehandlers] zipped text files have unexpected contents - * Xuan Chen (IBM) - [160775] [api] rename (at least within a zip) blocks UI thread - * Xuan Chen (IBM) - [209828] Need to move the Create operation to a job. - * Xuan Chen (IBM) - [191370] [dstore] Supertransfer zip not deleted when cancelling copy - * Xuan Chen (IBM) - [214251] [archive] "Last Modified Time" changed for all virtual files/folders if rename/paste/delete of one virtual file. - * Xuan Chen (IBM) - [214786] [regression][archive]rename a virtual directory does not work properly - * Xuan Chen (IBM) - [191370] [dstore] Supertransfer zip not deleted when cancelling copy + * Xuan Chen (IBM) - [192741] [Archives] Move a folder from within an Archive doesn't work if > 1 level deep + * Xuan Chen (IBM) - [194293] [Local][Archives] Saving file second time in an Archive Errors + * Xuan Chen (IBM) - [181784] [Archives] zipped text files have unexpected contents + * Xuan Chen (IBM) - [160775] [api] rename (at least within a zip) blocks UI thread + * Xuan Chen (IBM) - [209828] Need to move the Create operation to a job. + * Xuan Chen (IBM) - [191370] [dstore] Supertransfer zip not deleted when canceling copy + * Xuan Chen (IBM) - [214251] [archive] "Last Modified Time" changed for all virtual files/folders if rename/paste/delete of one virtual file. + * Xuan Chen (IBM) - [214786] [regression][archive]rename a virtual directory does not work properly + * Xuan Chen (IBM) - [191370] [dstore] Supertransfer zip not deleted when canceling copy + * Martin Oberhuber (Wind River) - [cleanup] Add API "since" tags *******************************************************************************/ package org.eclipse.rse.services.clientserver.archiveutils; @@ -56,10 +57,10 @@ import org.eclipse.rse.services.clientserver.search.SystemSearchStringMatcher; /** - * @author mjberger * Implements an ISystemArchiveHandler for ZIP files. + * @author mjberger */ -public class SystemZipHandler implements ISystemArchiveHandler +public class SystemZipHandler implements ISystemArchiveHandler { protected ZipFile _zipfile; // The underlying zipfile associated with this handler. @@ -72,15 +73,15 @@ public class SystemZipHandler implements ISystemArchiveHandler // in the virtual file system. The root directory has the key "". Associated with each key, is a value, and that value // is itself another HashMap, representing the contents of that directory. In the "inner" HashMap, each key is // a String giving the name of an object in the directory, and each associated value is a - // VirtualChild representing that object itself. + // VirtualChild representing that object itself. // // Note that if the object is a directory, then - // the value representing it in the inner HashMap is still a VirtualChild, not another + // the value representing it in the inner HashMap is still a VirtualChild, not another // HashMap. There are only two levels of HashMaps in the virtual file system. If the // object is a directory, then the VirtualChild object representing it will have // isDirectory == true. We can then find the contents of this directory, by going - // back out to the outer HashMap, and retrieving the inner HashMap associated - // with our directory's name. + // back out to the outer HashMap, and retrieving the inner HashMap associated + // with our directory's name. // // This file system is designed for quick retrieval of virtual objects. // Retrieving a single object whose full path is known can be done @@ -100,12 +101,13 @@ public class SystemZipHandler implements ISystemArchiveHandler // is the number of entries in the zipfile, and h is the maximum height of an entry in // the virtual file system. //-------------------------------------------------------------------------------------------------------------------- - + protected File _file; // The underlying file associated with this handler. protected long _vfsLastModified; // The timestamp of the file that the virtual file system reflects. protected boolean _exists; // Whether or not the zipfile "exists" (in order to exist, must be uncorrupted too) + /** @since org.eclipse.rse.services 3.0 */ protected SystemReentrantMutex _mutex; - + /** * Creates a new SystemZipHandler and associates it with file. * @param file The file that this handler will wrapper. @@ -115,9 +117,9 @@ public class SystemZipHandler implements ISystemArchiveHandler { _file = file; _vfsLastModified = _file.lastModified(); - if (openZipFile()) + if (openZipFile()) { - buildTree(); + buildTree(); closeZipFile(); _exists = true; } @@ -127,11 +129,10 @@ public class SystemZipHandler implements ISystemArchiveHandler } _mutex = new SystemReentrantMutex(); } - + /** * Builds the virtual file system tree out of the entries in * the zipfile. - * */ protected void buildTree() { @@ -143,10 +144,10 @@ public class SystemZipHandler implements ISystemArchiveHandler fillBranch(next); } } - + /** - * Update the virtual file system tree after rename operation - * + * Update the virtual file system tree after rename operation. + * @since org.eclipse.rse.services 3.0 */ protected void updateTreeAfterRename(HashMap newOldName, VirtualChild[] renameList) { @@ -161,7 +162,7 @@ public class SystemZipHandler implements ISystemArchiveHandler } fillBranchAfterRename(next, oldName); } - + //also make sure all the directory affected by rename, we need to remove those hashmap from the //virtual file system. if (renameList == null) @@ -179,7 +180,7 @@ public class SystemZipHandler implements ISystemArchiveHandler } } } - + } /** @@ -193,19 +194,19 @@ public class SystemZipHandler implements ISystemArchiveHandler { if (next.getName().equals("/")) return; // dummy entry //$NON-NLS-1$ VirtualChild nextChild = null; - + //We need to search this entry in the virtual file system tree. //If oldName is passed in, we use the old name. //otherwise, we use the entry name. String pathNameToSearchInVFS = null; String nameToSearchInVFS = null; - + SystemUniversalZipEntry nextEntry = new SystemUniversalZipEntry(next); - - + + pathNameToSearchInVFS = nextEntry.getFullPath(); nameToSearchInVFS = nextEntry.getName(); - + //try to find the virtual child from the memory tree if (_virtualFS.containsKey(pathNameToSearchInVFS)) { @@ -215,25 +216,25 @@ public class SystemZipHandler implements ISystemArchiveHandler nextChild = (VirtualChild)itsDirectory.get(nameToSearchInVFS); } } - + if (null == nextChild) { nextChild = new VirtualChild(this, nextEntry.getFullName()); } else { - //We found the virtual child, but its name could also been changed. So need to update it + //We found the virtual child, but its name could also been changed. So need to update it nextChild.renameTo(nextEntry.getFullName()); } - + if (next.isDirectory()) { nextChild.isDirectory = true; - + if (!_virtualFS.containsKey(nextChild.fullName)) { _virtualFS.put(nextChild.fullName, new HashMap()); - } + } } //Now, update other properties nextChild.setComment(next.getComment()); @@ -242,8 +243,8 @@ public class SystemZipHandler implements ISystemArchiveHandler nextChild.setCompressionMethod(methodIntValue.toString()); nextChild.setSize(next.getSize()); nextChild.setTimeStamp(next.getTime()); - - // key has not been encountered before, create a new + + // key has not been encountered before, create a new // element in the virtualFS. if (!_virtualFS.containsKey(nextChild.path)) { @@ -251,38 +252,39 @@ public class SystemZipHandler implements ISystemArchiveHandler recursivePopulate(nextChild.path, nextChild); } else // key has been encountered before, no need to recursively - // populate the subdirectories + // populate the subdirectories { HashMap hm = (HashMap) _virtualFS.get(nextChild.path); hm.put(nextChild.name, nextChild); - } + } } - + /** * Populates an entire branch of the tree that comprises the * virtual file system. The parameter is the leaf node, and from * the virtual path of the parameter, we can deduce what the ancestors * of the leaves are, and populate the tree from there. * @param next The ZipEntry from which the branch will be built. + * @since org.eclipse.rse.services 3.0 */ protected void fillBranchAfterRename(ZipEntry next, String oldName) { if (next.getName().equals("/")) return; // dummy entry //$NON-NLS-1$ VirtualChild nextChild = null; - + //We need to search this entry in the virtual file system tree. //If oldName is passed in, we use the old name. //otherwise, we use the entry name. String pathNameToSearchInVFS = null; String nameToSearchInVFS = null; boolean replace = (oldName != null); - + SystemUniversalZipEntry nextEntry = new SystemUniversalZipEntry(next); - + if (null != oldName) { int endOfPathPosition = oldName.lastIndexOf("/"); //$NON-NLS-1$ - if (endOfPathPosition != -1) + if (endOfPathPosition != -1) { if (endOfPathPosition == (oldName.length() - 1)) { @@ -291,7 +293,7 @@ public class SystemZipHandler implements ISystemArchiveHandler int endOfPathPosNameWithoutLastSlash = nameWithoutLastSlash.lastIndexOf("/"); //$NON-NLS-1$ if (endOfPathPosNameWithoutLastSlash != -1) { - //example for this case is: + //example for this case is: //fullpath folder1/folder12/ //Int this case, pathNameToSearchInVFS should be "folder1", and nameToSearchInVFS should be "folder12" pathNameToSearchInVFS = oldName.substring(0, endOfPathPosNameWithoutLastSlash); @@ -305,13 +307,13 @@ public class SystemZipHandler implements ISystemArchiveHandler nameToSearchInVFS = oldName.substring(0, endOfPathPosition); } } - else + else { pathNameToSearchInVFS = oldName.substring(0,endOfPathPosition); nameToSearchInVFS = oldName.substring(endOfPathPosition+1); } } - else + else { pathNameToSearchInVFS = ""; //$NON-NLS-1$ nameToSearchInVFS = oldName; @@ -322,7 +324,7 @@ public class SystemZipHandler implements ISystemArchiveHandler pathNameToSearchInVFS = nextEntry.getFullPath(); nameToSearchInVFS = nextEntry.getName(); } - + //try to find the virtual child from the memory tree if (_virtualFS.containsKey(pathNameToSearchInVFS)) { @@ -330,7 +332,7 @@ public class SystemZipHandler implements ISystemArchiveHandler if (itsDirectory.containsKey(nameToSearchInVFS)) { nextChild = (VirtualChild)itsDirectory.get(nameToSearchInVFS); - //We also need to remove this virtual child from VFS tree first, since we need to + //We also need to remove this virtual child from VFS tree first, since we need to //put it back any way later. if (replace) { @@ -343,27 +345,27 @@ public class SystemZipHandler implements ISystemArchiveHandler //It is the directory itself, remove the hashmap. _virtualFS.remove(pathNameToSearchInVFS); } - */ + */ } - + if (null == nextChild) { nextChild = new VirtualChild(this, nextEntry.getFullName()); } else { - //We found the virtual child, but its name could also been changed. So need to update it + //We found the virtual child, but its name could also been changed. So need to update it nextChild.renameTo(nextEntry.getFullName()); } - + if (next.isDirectory()) { nextChild.isDirectory = true; - + if (!_virtualFS.containsKey(nextChild.fullName)) { _virtualFS.put(nextChild.fullName, new HashMap()); - } + } } //Now, update other properties nextChild.setComment(next.getComment()); @@ -372,8 +374,8 @@ public class SystemZipHandler implements ISystemArchiveHandler nextChild.setCompressionMethod(methodIntValue.toString()); nextChild.setSize(next.getSize()); nextChild.setTimeStamp(next.getTime()); - - // key has not been encountered before, create a new + + // key has not been encountered before, create a new // element in the virtualFS. if (!_virtualFS.containsKey(nextChild.path)) { @@ -381,11 +383,11 @@ public class SystemZipHandler implements ISystemArchiveHandler populate(nextChild.path, nextChild); } else // key has been encountered before, no need to recursively - // populate the subdirectories + // populate the subdirectories { HashMap hm = (HashMap) _virtualFS.get(nextChild.path); hm.put(nextChild.name, nextChild); - } + } } @@ -404,13 +406,13 @@ public class SystemZipHandler implements ISystemArchiveHandler hm.put(value.name, value); return; } - + // else HashMap newValue = new HashMap(); newValue.put(value.name, value); _virtualFS.put(key, newValue); - - + + // base case 2 if (key.equals("")) //$NON-NLS-1$ { @@ -434,12 +436,15 @@ public class SystemZipHandler implements ISystemArchiveHandler recursivePopulate(newKey, nextValue); return; } - + } - - + + } - + + /** + * @since org.eclipse.rse.services 3.0 + */ protected void populate(String key, VirtualChild value) { // base case 1: key has been encountered before, finish recursing @@ -449,13 +454,13 @@ public class SystemZipHandler implements ISystemArchiveHandler hm.put(value.name, value); return; } - + // else HashMap newValue = new HashMap(); newValue.put(value.name, value); _virtualFS.put(key, newValue); - - + + // base case 2 if (key.equals("")) //$NON-NLS-1$ { @@ -479,10 +484,10 @@ public class SystemZipHandler implements ISystemArchiveHandler recursivePopulate(newKey, nextValue); return; } - + } - - + + } /* (non-Javadoc) @@ -492,12 +497,13 @@ public class SystemZipHandler implements ISystemArchiveHandler { return getVirtualChildrenList(true, archiveOperationMonitor); } - + /** * Same as getVirtualChildrenList(), but you can choose whether * to leave the zip file open or closed upon return. - */ - public VirtualChild[] getVirtualChildrenList(boolean closeZipFile, ISystemOperationMonitor archiveOperationMonitor) + * @since org.eclipse.rse.services 3.0 + */ + public VirtualChild[] getVirtualChildrenList(boolean closeZipFile, ISystemOperationMonitor archiveOperationMonitor) { if (!_exists) return new VirtualChild[0]; if (!updateVirtualFSIfNecessary(archiveOperationMonitor)) return new VirtualChild[0]; @@ -538,7 +544,7 @@ public class SystemZipHandler implements ISystemArchiveHandler { releaseMutex(mutexLockStatus); } - + return new VirtualChild[0]; } @@ -549,12 +555,13 @@ public class SystemZipHandler implements ISystemArchiveHandler { return getVirtualChildrenList(parent, true, archiveOperationMonitor); } - + /** * Same as getVirtualChildrenList(String parent) but you can choose whether - * or not you want to leave the zipfile open after return. - */ - public VirtualChild[] getVirtualChildrenList(String parent, boolean closeZipFile, ISystemOperationMonitor archiveOperationMonitor) + * or not you want to leave the zipfile open after return. + * @since org.eclipse.rse.services 3.0 + */ + public VirtualChild[] getVirtualChildrenList(String parent, boolean closeZipFile, ISystemOperationMonitor archiveOperationMonitor) { if (!_exists) return new VirtualChild[0]; if (!updateVirtualFSIfNecessary(archiveOperationMonitor)) return new VirtualChild[0]; @@ -605,9 +612,9 @@ public class SystemZipHandler implements ISystemArchiveHandler { releaseMutex(mutexLockStatus); } - + return new VirtualChild[0]; - + } /* (non-Javadoc) @@ -617,10 +624,10 @@ public class SystemZipHandler implements ISystemArchiveHandler { if (!_exists) return null; if (!updateVirtualFSIfNecessary(archiveOperationMonitor)) return null; - + fullVirtualName = ArchiveHandlerManager.cleanUpVirtualPath(fullVirtualName); VirtualChild[] values = null; - if (_virtualFS.containsKey(fullVirtualName)) + if (_virtualFS.containsKey(fullVirtualName)) { HashMap hm = (HashMap) _virtualFS.get(fullVirtualName); Object valueArray[] = hm.values().toArray(); @@ -629,11 +636,11 @@ public class SystemZipHandler implements ISystemArchiveHandler { values[i] = (VirtualChild) valueArray[i]; } - + } return values; } - + /* (non-Javadoc) * @see org.eclipse.rse.services.clientserver.archiveutils.ISystemArchiveHandler#getVirtualChildFolders(java.lang.String) */ @@ -644,7 +651,7 @@ public class SystemZipHandler implements ISystemArchiveHandler fullVirtualName = ArchiveHandlerManager.cleanUpVirtualPath(fullVirtualName); Vector folders = new Vector(); VirtualChild[] values = null; - if (_virtualFS.containsKey(fullVirtualName)) + if (_virtualFS.containsKey(fullVirtualName)) { HashMap hm = (HashMap) _virtualFS.get(fullVirtualName); Object valueArray[] = hm.values().toArray(); @@ -664,7 +671,7 @@ public class SystemZipHandler implements ISystemArchiveHandler /* (non-Javadoc) * @see org.eclipse.rse.services.clientserver.archiveutils.ISystemArchiveHandler#getVirtualFile(java.lang.String) */ - public VirtualChild getVirtualFile(String fullVirtualName, ISystemOperationMonitor archiveOperationMonitor) + public VirtualChild getVirtualFile(String fullVirtualName, ISystemOperationMonitor archiveOperationMonitor) { if (!_exists) return new VirtualChild(this, fullVirtualName); if (!updateVirtualFSIfNecessary(archiveOperationMonitor)) return new VirtualChild(this, fullVirtualName); @@ -690,7 +697,7 @@ public class SystemZipHandler implements ISystemArchiveHandler if (vc == null) return new VirtualChild(this, fullVirtualName); return vc; } - + /* (non-Javadoc) * @see org.eclipse.rse.services.clientserver.archiveutils.ISystemArchiveHandler#exists(java.lang.String) */ @@ -700,7 +707,7 @@ public class SystemZipHandler implements ISystemArchiveHandler fullVirtualName = ArchiveHandlerManager.cleanUpVirtualPath(fullVirtualName); if (fullVirtualName == "" || fullVirtualName == null) return false; //$NON-NLS-1$ - + if (_vfsLastModified == _file.lastModified()) { int i = fullVirtualName.lastIndexOf("/"); //$NON-NLS-1$ @@ -756,7 +763,7 @@ public class SystemZipHandler implements ISystemArchiveHandler } } } - + /* (non-Javadoc) * @see org.eclipse.rse.services.clientserver.archiveutils.ISystemArchiveHandler#getArchive() */ @@ -764,7 +771,7 @@ public class SystemZipHandler implements ISystemArchiveHandler { return _file; } - + /* (non-Javadoc) * @see org.eclipse.rse.services.clientserver.archiveutils.ISystemArchiveHandler#getTimeStampFor(java.lang.String) */ @@ -775,8 +782,8 @@ public class SystemZipHandler implements ISystemArchiveHandler /** * Same as getTimeStampFor(String fullVirtualName) but you can choose whether - * or not you want to leave the zipfile open after return. - */ + * or not you want to leave the zipfile open after return. + */ public long getTimeStampFor(String fullVirtualName, boolean closeZipFile) { if (!_exists) return 0; @@ -799,7 +806,7 @@ public class SystemZipHandler implements ISystemArchiveHandler } else return _file.lastModified(); } - + /* (non-Javadoc) * @see org.eclipse.rse.services.clientserver.archiveutils.ISystemArchiveHandler#getSizeFor(java.lang.String) */ @@ -808,6 +815,15 @@ public class SystemZipHandler implements ISystemArchiveHandler return getSizeFor(fullVirtualName, true); } + /** + * Same as {@link #getSizeFor(String)} but allows to specify whether to + * close the zip file or not. + * + * @param fullVirtualName absolute virtual path to the node to inspect + * @param closeZipFile true if the zip file should be closed + * @return the uncompressed size of the node requested. + * @see org.eclipse.rse.services.clientserver.archiveutils.ISystemArchiveHandler#getSizeFor(java.lang.String) + */ public long getSizeFor(String fullVirtualName, boolean closeZipFile) { if (!_exists) return 0; @@ -821,7 +837,7 @@ public class SystemZipHandler implements ISystemArchiveHandler entry = safeGetEntry(fullVirtualName); } catch (IOException e) - { + { if (closeZipFile) closeZipFile(); return 0; } @@ -830,7 +846,7 @@ public class SystemZipHandler implements ISystemArchiveHandler } else return 0; } - + /* (non-Javadoc) * @see org.eclipse.rse.services.clientserver.archiveutils.ISystemArchiveHandler#extractVirtualFile(java.lang.String, java.io.File) */ @@ -849,8 +865,9 @@ public class SystemZipHandler implements ISystemArchiveHandler /** * Same as extractVirtualFile(String fullVirtualName, File destination) but you can choose whether - * or not you want to leave the zipfile open after return. - */ + * or not you want to leave the zipfile open after return. + * @since org.eclipse.rse.services 3.0 + */ public boolean extractVirtualFile(String fullVirtualName, File destination, boolean closeZipFile, String sourceEncoding, boolean isText, ISystemOperationMonitor archiveOperationMonitor) { if (!_exists) return false; @@ -863,7 +880,7 @@ public class SystemZipHandler implements ISystemArchiveHandler if (openZipFile()) { fullVirtualName = ArchiveHandlerManager.cleanUpVirtualPath(fullVirtualName); - + entry = safeGetEntry(fullVirtualName); if (entry.isDirectory()) { @@ -881,20 +898,20 @@ public class SystemZipHandler implements ISystemArchiveHandler return true; } BufferedInputStream reader = new BufferedInputStream(is); - + if (!destination.exists()) { - File parentFile = destination.getParentFile(); - if (!parentFile.exists()) - parentFile.mkdirs(); - destination.createNewFile(); + File parentFile = destination.getParentFile(); + if (!parentFile.exists()) + parentFile.mkdirs(); + destination.createNewFile(); } BufferedOutputStream writer = new BufferedOutputStream( - new FileOutputStream(destination)); - + new FileOutputStream(destination)); + byte[] buf = new byte[1024]; int numRead = reader.read(buf); - + while (numRead > 0) { if (isText) @@ -908,41 +925,41 @@ public class SystemZipHandler implements ISystemArchiveHandler { writer.write(buf, 0, numRead); } - numRead = reader.read(buf); + numRead = reader.read(buf); } writer.close(); reader.close(); - } - destination.setLastModified(entry.getTime()); + } + destination.setLastModified(entry.getTime()); + if (closeZipFile) closeZipFile(); + return true; + } + catch (IOException e) + { + if (_virtualFS.containsKey(fullVirtualName)) + { + destination.delete(); + destination.mkdirs(); + destination.setLastModified(_file.lastModified()); if (closeZipFile) closeZipFile(); return true; } - catch (IOException e) - { - if (_virtualFS.containsKey(fullVirtualName)) - { - destination.delete(); - destination.mkdirs(); - destination.setLastModified(_file.lastModified()); - if (closeZipFile) closeZipFile(); - return true; - } - System.out.println(e.getMessage()); - if (closeZipFile) closeZipFile(); - return false; - } - finally - { - releaseMutex(mutexLockStatus); - } - + System.out.println(e.getMessage()); + if (closeZipFile) closeZipFile(); + return false; + } + finally + { + releaseMutex(mutexLockStatus); + } + } else { return false; } } - + /* (non-Javadoc) * @see org.eclipse.rse.services.clientserver.archiveutils.ISystemArchiveHandler#extractVirtualDirectory(java.lang.String, java.io.File) */ @@ -950,7 +967,7 @@ public class SystemZipHandler implements ISystemArchiveHandler { return extractVirtualDirectory(dir, destinationParent, (File) null, SystemEncodingUtil.ENCODING_UTF_8, false, archiveOperationMonitor); } - + /* (non-Javadoc) * @see org.eclipse.rse.services.clientserver.archiveutils.ISystemArchiveHandler#extractVirtualDirectory(java.lang.String, java.io.File, java.lang.String, boolean) */ @@ -958,7 +975,7 @@ public class SystemZipHandler implements ISystemArchiveHandler { return extractVirtualDirectory(dir, destinationParent, (File) null, sourceEncoding, isText, archiveOperationMonitor); } - + /* (non-Javadoc) * @see org.eclipse.rse.services.clientserver.archiveutils.ISystemArchiveHandler#extractVirtualDirectory(java.lang.String, java.io.File, java.io.File) */ @@ -966,7 +983,11 @@ public class SystemZipHandler implements ISystemArchiveHandler { return extractVirtualDirectory(dir, destinationParent, destination, SystemEncodingUtil.ENCODING_UTF_8, false, archiveOperationMonitor); } - + + /* + * (non-Javadoc) + * @see org.eclipse.rse.services.clientserver.archiveutils.ISystemArchiveHandler#extractVirtualDirectory(java.lang.String, java.io.File, java.io.File, java.lang.String, boolean, org.eclipse.rse.services.clientserver.ISystemOperationMonitor) + */ public boolean extractVirtualDirectory(String dir, File destinationParent, File destination, String sourceEncoding, boolean isText, ISystemOperationMonitor archiveOperationMonitor) { if (!_exists) return false; @@ -974,11 +995,11 @@ public class SystemZipHandler implements ISystemArchiveHandler if (!destinationParent.isDirectory()) return false; dir = ArchiveHandlerManager.cleanUpVirtualPath(dir); if (!_virtualFS.containsKey(dir)) return false; - + String name; int charsToTrim; int j = dir.lastIndexOf("/"); //$NON-NLS-1$ - if (j == -1) + if (j == -1) { charsToTrim = 0; name = dir; @@ -998,9 +1019,9 @@ public class SystemZipHandler implements ISystemArchiveHandler else { destination = new File(destinationParent, name); - } + } } - + if (!(destination == destinationParent)) { if (destination.isFile() && destination.exists()) @@ -1012,7 +1033,7 @@ public class SystemZipHandler implements ISystemArchiveHandler return false; } } - + if (!destination.exists()) { if (!destination.mkdirs()) @@ -1025,7 +1046,7 @@ public class SystemZipHandler implements ISystemArchiveHandler } File topFile = destination; - String topFilePath = topFile.getAbsolutePath().replace('\\', '/'); + String topFilePath = topFile.getAbsolutePath().replace('\\', '/'); //if (!dir.equals(topFile.getName())) String lastPortionOfDir = null; int lastSlashIndex = dir.lastIndexOf('/'); @@ -1037,10 +1058,10 @@ public class SystemZipHandler implements ISystemArchiveHandler { lastPortionOfDir = dir.substring(lastSlashIndex + 1); } - if (!topFilePath.endsWith(lastPortionOfDir)) + if (!topFilePath.endsWith(lastPortionOfDir)) { - rename(dir, topFile.getName(), archiveOperationMonitor); - dir = topFile.getName(); + rename(dir, topFile.getName(), archiveOperationMonitor); + dir = topFile.getName(); } VirtualChild[] newChildren = getVirtualChildrenList(dir, archiveOperationMonitor); @@ -1050,23 +1071,23 @@ public class SystemZipHandler implements ISystemArchiveHandler return false; } extractVirtualFile(dir + '/', topFile, sourceEncoding, isText, archiveOperationMonitor); - + for (int i = 0; i < newChildren.length; i++) { String newName = newChildren[i].fullName.substring(charsToTrim); char separator = File.separatorChar; newName = newName.replace('/', separator); - + File nextFile = new File(destinationParent, newName); /* // DKM: case where a rename has taken place - // don't want to extract root folder as it appears in zip - if (!nextFile.getParent().equals(destination.getPath()) && + // don't want to extract root folder as it appears in zip + if (!nextFile.getParent().equals(destination.getPath()) && nextFile.getParentFile().getParent().equals(destination.getParent())) { nextFile = new File(destination, nextFile.getName()); } - */ + */ if (!nextFile.exists()) { if (newChildren[i].isDirectory) @@ -1084,18 +1105,25 @@ public class SystemZipHandler implements ISystemArchiveHandler boolean success = false; if (newChildren[i].isDirectory) { - success = extractVirtualFile(newChildren[i].fullName + '/', nextFile, sourceEncoding, isText, archiveOperationMonitor); + success = extractVirtualFile(newChildren[i].fullName + '/', nextFile, sourceEncoding, isText, archiveOperationMonitor); } else { - success = extractVirtualFile(newChildren[i].fullName, nextFile, sourceEncoding, isText, archiveOperationMonitor); + success = extractVirtualFile(newChildren[i].fullName, nextFile, sourceEncoding, isText, archiveOperationMonitor); } if (!success) return false; - } + } } return true; } - + + /** + * Create an empty file, also creating parent folders if necessary. + * + * @param file An abstract file handle to create physically. + * @return true if successful, false + * otherwise. + */ protected boolean createFile(File file) { try @@ -1103,7 +1131,7 @@ public class SystemZipHandler implements ISystemArchiveHandler if (!file.createNewFile()) { System.out.println("File already exists: " + file.toString()); //$NON-NLS-1$ - return false; + return false; } else { @@ -1131,8 +1159,12 @@ public class SystemZipHandler implements ISystemArchiveHandler { return add(file, virtualPath, name, SystemEncodingUtil.ENCODING_UTF_8, SystemEncodingUtil.ENCODING_UTF_8, false, archiveOperationMonitor); } - - public boolean add(InputStream stream, String virtualPath, String name, String sourceEncoding, String targetEncoding, boolean isText, ISystemOperationMonitor archiveOperationMonitor) + + /* + * (non-Javadoc) + * @see org.eclipse.rse.services.clientserver.archiveutils.ISystemArchiveHandler#add(java.io.InputStream, java.lang.String, java.lang.String, java.lang.String, java.lang.String, boolean, org.eclipse.rse.services.clientserver.ISystemOperationMonitor) + */ + public boolean add(InputStream stream, String virtualPath, String name, String sourceEncoding, String targetEncoding, boolean isText, ISystemOperationMonitor archiveOperationMonitor) { if (!_exists) return false; virtualPath = ArchiveHandlerManager.cleanUpVirtualPath(virtualPath); @@ -1142,7 +1174,7 @@ public class SystemZipHandler implements ISystemArchiveHandler // wrong method return replace(virtualPath + "/" + name, stream, name, sourceEncoding, targetEncoding, isText, archiveOperationMonitor); //$NON-NLS-1$ } - + int mutexLockStatus = SystemReentrantMutex.LOCK_STATUS_NOLOCK; try { @@ -1158,12 +1190,12 @@ public class SystemZipHandler implements ISystemArchiveHandler // Open a new tempfile which will be our destination for the new zip outputTempFile = new File(_file.getAbsolutePath() + "temp"); //$NON-NLS-1$ ZipOutputStream dest = new ZipOutputStream( - new FileOutputStream(outputTempFile)); - + new FileOutputStream(outputTempFile)); + dest.setMethod(ZipOutputStream.DEFLATED); - // get all the entries in the old zip + // get all the entries in the old zip VirtualChild[] vcList = getVirtualChildrenList(false, archiveOperationMonitor); - + // if it is an empty zip file, no need to recreate it if (!(vcList.length == 1) || !vcList[0].fullName.equals("")) //$NON-NLS-1$ { @@ -1176,17 +1208,17 @@ public class SystemZipHandler implements ISystemArchiveHandler return false; } } - + // append the additional entry to the zip file. ZipEntry newEntry = appendBytes(stream, dest, virtualPath, name, sourceEncoding, targetEncoding, isText); // Add the new entry to the virtual file system in memory fillBranch(newEntry); - + dest.close(); - + // Now replace the old zip file with the new one replaceOldZip(outputTempFile); - + } catch (IOException e) { @@ -1199,7 +1231,7 @@ public class SystemZipHandler implements ISystemArchiveHandler return true; } } - + } catch(Exception e) { @@ -1209,14 +1241,14 @@ public class SystemZipHandler implements ISystemArchiveHandler { releaseMutex(mutexLockStatus); } - + return false; } /* (non-Javadoc) * @see org.eclipse.rse.services.clientserver.archiveutils.ISystemArchiveHandler#add(java.io.File[], java.lang.String, java.lang.String[]) */ - public boolean add(File[] files, String virtualPath, String[] names, ISystemOperationMonitor archiveOperationMonitor) + public boolean add(File[] files, String virtualPath, String[] names, ISystemOperationMonitor archiveOperationMonitor) { String[] encodings = new String[files.length]; boolean[] isTexts = new boolean[files.length]; @@ -1228,20 +1260,25 @@ public class SystemZipHandler implements ISystemArchiveHandler return add(files, virtualPath, names, encodings, encodings, isTexts, true, archiveOperationMonitor); } + /* + * (non-Javadoc) + * @see org.eclipse.rse.services.clientserver.archiveutils.ISystemArchiveHandler#add(java.io.File[], java.lang.String, java.lang.String[], java.lang.String[], java.lang.String[], boolean[], org.eclipse.rse.services.clientserver.ISystemOperationMonitor) + */ public boolean add(File[] files, String virtualPath, String[] names, String[] sourceEncodings, String[] targetEncodings, boolean[] isText, ISystemOperationMonitor archiveOperationMonitor) { return add(files, virtualPath, names, sourceEncodings, targetEncodings, isText, true, archiveOperationMonitor); } - + /** * Same as add(File[] files, String virtualPath, String[] names, String[] encodings) but you can choose whether - * or not you want to leave the zipfile open after return. - */ - public boolean add(File[] files, String virtualPath, String[] names, String[] sourceEncodings, String[] targetEncodings, boolean[] isText, boolean closeZipFile, ISystemOperationMonitor archiveOperationMonitor) + * or not you want to leave the zipfile open after return. + * @since org.eclipse.rse.services 3.0 + */ + public boolean add(File[] files, String virtualPath, String[] names, String[] sourceEncodings, String[] targetEncodings, boolean[] isText, boolean closeZipFile, ISystemOperationMonitor archiveOperationMonitor) { if (!_exists) return false; - + int mutexLockStatus = SystemReentrantMutex.LOCK_STATUS_NOLOCK; try { @@ -1253,7 +1290,7 @@ public class SystemZipHandler implements ISystemArchiveHandler virtualPath = ArchiveHandlerManager.cleanUpVirtualPath(virtualPath); int numFiles = files.length; for (int i = 0; i < numFiles; i++) - { + { if (archiveOperationMonitor != null && archiveOperationMonitor.isCanceled()) { //the operation has been canceled @@ -1262,10 +1299,10 @@ public class SystemZipHandler implements ISystemArchiveHandler } if (!files[i].exists() || !files[i].canRead()) return false; String fullVirtualName = getFullVirtualName(virtualPath, names[i]); - if (exists(fullVirtualName, archiveOperationMonitor)) + if (exists(fullVirtualName, archiveOperationMonitor)) { // sorry, wrong method buddy - return replace(fullVirtualName, files[i], names[i], archiveOperationMonitor); + return replace(fullVirtualName, files[i], names[i], archiveOperationMonitor); } } File outputTempFile; @@ -1273,12 +1310,12 @@ public class SystemZipHandler implements ISystemArchiveHandler // Open a new tempfile which will be our destination for the new zip outputTempFile = new File(_file.getAbsolutePath() + "temp"); //$NON-NLS-1$ ZipOutputStream dest = new ZipOutputStream( - new FileOutputStream(outputTempFile)); - + new FileOutputStream(outputTempFile)); + dest.setMethod(ZipOutputStream.DEFLATED); - // get all the entries in the old zip + // get all the entries in the old zip VirtualChild[] vcList = getVirtualChildrenList(false, archiveOperationMonitor); - + // if it is an empty zip file, no need to recreate it if (!(vcList.length == 1) || !vcList[0].fullName.equals("")) //$NON-NLS-1$ { @@ -1286,7 +1323,7 @@ public class SystemZipHandler implements ISystemArchiveHandler if (isCanceled) { dest.close(); - if (!(outputTempFile == null)) + if (!(outputTempFile == null)) { outputTempFile.delete(); } @@ -1294,18 +1331,18 @@ public class SystemZipHandler implements ISystemArchiveHandler return false; } } - + // Now for each new file to add // We need to remember the entries added, and if this operation is not canceled, we // will add them into Virtual File system. ZipEntry[] newEntriesAdded = new ZipEntry[numFiles]; for (int i = 0; i < numFiles; i++) - { - if (archiveOperationMonitor != null && archiveOperationMonitor.isCanceled()) + { + if (archiveOperationMonitor != null && archiveOperationMonitor.isCanceled()) { //the operation has been canceled dest.close(); - if (!(outputTempFile == null)) + if (!(outputTempFile == null)) { outputTempFile.delete(); } @@ -1317,17 +1354,17 @@ public class SystemZipHandler implements ISystemArchiveHandler // Add the new entry to the array first. newEntriesAdded[i] = newEntry; } - + dest.close(); - + // Now replace the old zip file with the new one replaceOldZip(outputTempFile); //Also need to add the new entries into VFS for (int i = 0; i < numFiles; i++) { - fillBranch(newEntriesAdded[i]); + fillBranch(newEntriesAdded[i]); } - + if (closeZipFile) closeZipFile(); return true; } @@ -1342,22 +1379,23 @@ public class SystemZipHandler implements ISystemArchiveHandler { releaseMutex(mutexLockStatus); } - + return false; } /** - * Helper method. . . populates found with a - * collapsed list of all nodes in the subtree - * of the file system rooted at parent. + * Helper method. populates found with a collapsed list of + * all nodes in the subtree of the file system rooted at parent. + * + * @since org.eclipse.rse.services 3.0 */ public static boolean listAllFiles(File parent, HashSet found, ISystemOperationMonitor archiveOperationMonitor) { File[] children = parent.listFiles(); if (children == null) // DKM - 56031, no authority on parent yields null { - found.remove(parent); - return false; + found.remove(parent); + return false; } for (int i = 0; i < children.length; i++) { @@ -1368,17 +1406,17 @@ public class SystemZipHandler implements ISystemArchiveHandler } if (!found.contains(children[i])) // prevent infinite loops due to symlinks { - if (children[i].canRead()) - { - found.add(children[i]); - if (children[i].isDirectory()) - { - listAllFiles(children[i], found, archiveOperationMonitor); + if (children[i].canRead()) + { + found.add(children[i]); + if (children[i].isDirectory()) + { + listAllFiles(children[i], found, archiveOperationMonitor); } - } + } } } - + return false; } @@ -1391,6 +1429,7 @@ public class SystemZipHandler implements ISystemArchiveHandler * @param omitChildren The set of names of children to omit when creating * the zipfile. Null or empty set if there are no omissions. * @throws IOException in case of a file I/O error + * @since org.eclipse.rse.services 3.0 */ protected boolean recreateZipDeleteEntries(VirtualChild[] vcList, ZipOutputStream dest, HashSet omitChildren, ISystemOperationMonitor archiveOperationMonitor) throws IOException { @@ -1411,7 +1450,7 @@ public class SystemZipHandler implements ISystemArchiveHandler //the operation has been canceled return true; } - + // for each entry, append it to the new temp zip // unless it is in the set of omissions if (omitChildren != null && omitChildren.contains(vcList[i].fullName)) continue; @@ -1424,23 +1463,23 @@ public class SystemZipHandler implements ISystemArchiveHandler } ZipEntry nextEntry = safeGetEntry(vcList[i].fullName); BufferedInputStream source = new BufferedInputStream( - _zipfile.getInputStream(nextEntry)); + _zipfile.getInputStream(nextEntry)); nextEntry.setCompressedSize(-1); dest.putNextEntry(nextEntry); byte[] buf = new byte[1024]; int numRead = source.read(buf); - + while (numRead > 0) { dest.write(buf, 0, numRead); - numRead = source.read(buf); + numRead = source.read(buf); } dest.closeEntry(); source.close(); - } + } return false; } - + /** * Recreates a zip file from a list of virtual children, but renaming the * one of the VirtualChildren. @@ -1449,6 +1488,7 @@ public class SystemZipHandler implements ISystemArchiveHandler * children are to be recreated * @param names HashMap maps the full path of a virtual file to the entry in the archive file * @throws IOException + * @since org.eclipse.rse.services 3.0 */ protected boolean recreateZipRenameEntries(VirtualChild[] vcList, ZipOutputStream dest, HashMap names, ISystemOperationMonitor archiveOperationMonitor) throws IOException { @@ -1486,20 +1526,20 @@ public class SystemZipHandler implements ISystemArchiveHandler continue; } BufferedInputStream source = new BufferedInputStream( - _zipfile.getInputStream(nextEntry)); + _zipfile.getInputStream(nextEntry)); newEntry.setCompressedSize(-1); dest.putNextEntry(newEntry); byte[] buf = new byte[1024]; int numRead = source.read(buf); - + while (numRead > 0) { dest.write(buf, 0, numRead); - numRead = source.read(buf); + numRead = source.read(buf); } dest.closeEntry(); source.close(); - } + } return false; } @@ -1508,7 +1548,7 @@ public class SystemZipHandler implements ISystemArchiveHandler * ZipFile managed by dest. The file is encoded in the encoding * specified by encoding. A new entry is created in the * ZipFile with virtual path and name of virtualPath and name - * respectively. + * respectively. * @return The ZipEntry that was added to the destination zip file. * @throws IOException */ @@ -1516,7 +1556,7 @@ public class SystemZipHandler implements ISystemArchiveHandler { ZipEntry newEntry; if (file.isDirectory()) - { + { String fullName = virtualPath + "/" + name; //$NON-NLS-1$ if (!fullName.endsWith("/")) fullName = fullName + "/"; //$NON-NLS-1$ //$NON-NLS-2$ newEntry = createSafeZipEntry(fullName); @@ -1530,18 +1570,18 @@ public class SystemZipHandler implements ISystemArchiveHandler if (!file.isDirectory()) { BufferedInputStream source = new BufferedInputStream( - new FileInputStream(file)); - + new FileInputStream(file)); + byte[] buf = new byte[1024]; int numRead = source.read(buf); long fileSize = file.length(); long totalRead = 0; while (numRead > 0 && totalRead < fileSize) { - totalRead += numRead; + totalRead += numRead; if (isText) { - // DKM - if you don't specify numRead here, then buf will get picked up wiht extra bytes from b4!!!! + // DKM - if you don't specify numRead here, then buf will get picked up wiht extra bytes from b4!!!! String bufString = new String(buf, 0, numRead, sourceEncoding); byte[] convertedBuf = bufString.getBytes(targetEncoding); int newSize = convertedBuf.length; @@ -1555,14 +1595,14 @@ public class SystemZipHandler implements ISystemArchiveHandler long maxRead = 1024; long deltaLeft = fileSize - totalRead; if (deltaLeft > 1024) - { - numRead = source.read(buf, 0, (int)maxRead); + { + numRead = source.read(buf, 0, (int)maxRead); } else { - numRead = source.read(buf, 0, (int)deltaLeft); + numRead = source.read(buf, 0, (int)deltaLeft); } - + } dest.closeEntry(); source.close(); @@ -1575,7 +1615,7 @@ public class SystemZipHandler implements ISystemArchiveHandler * ZipFile managed by dest. The stream is encoded in the encoding * specified by encoding. A new entry is created in the * ZipFile with virtual path and name of virtualPath and name - * respectively. + * respectively. * @return The ZipEntry that was added to the destination zip file. * @throws IOException */ @@ -1591,10 +1631,10 @@ public class SystemZipHandler implements ISystemArchiveHandler long totalRead = 0; while (numRead > 0 && source.available() > 0) { - totalRead += numRead; + totalRead += numRead; if (isText) { - // DKM - if you don't specify numRead here, then buf will get picked up wiht extra bytes from b4!!!! + // DKM - if you don't specify numRead here, then buf will get picked up wiht extra bytes from b4!!!! String bufString = new String(buf, 0, numRead, sourceEncoding); byte[] convertedBuf = bufString.getBytes(targetEncoding); int newSize = convertedBuf.length; @@ -1608,20 +1648,20 @@ public class SystemZipHandler implements ISystemArchiveHandler long maxRead = 1024; long deltaLeft = source.available(); if (deltaLeft > 1024) - { - numRead = source.read(buf, 0, (int)maxRead); + { + numRead = source.read(buf, 0, (int)maxRead); } else { - numRead = source.read(buf, 0, (int)deltaLeft); + numRead = source.read(buf, 0, (int)deltaLeft); } - + } dest.closeEntry(); source.close(); return newEntry; } - + /** * Replaces the old zip file managed by this SystemZipHandler, with * the zip file referred to by outputTempFile. @@ -1638,11 +1678,11 @@ public class SystemZipHandler implements ISystemArchiveHandler _zipfile = new ZipFile(_file); oldFile.delete(); } - + /* (non-Javadoc) * @see org.eclipse.rse.services.clientserver.archiveutils.ISystemArchiveHandler#delete(java.lang.String) */ - public boolean delete(String fullVirtualName, ISystemOperationMonitor archiveOperationMonitor) + public boolean delete(String fullVirtualName, ISystemOperationMonitor archiveOperationMonitor) { boolean returnCode = delete(fullVirtualName, true, archiveOperationMonitor); setArchiveOperationMonitorStatusDone(archiveOperationMonitor); @@ -1651,9 +1691,10 @@ public class SystemZipHandler implements ISystemArchiveHandler /** * Same as delete(String fullVirtualName) but you can choose whether - * or not you want to leave the zipfile open after return. - */ - public boolean delete(String fullVirtualName, boolean closeZipFile, ISystemOperationMonitor archiveOperationMonitor) + * or not you want to leave the zipfile open after return. + * @since org.eclipse.rse.services 3.0 + */ + public boolean delete(String fullVirtualName, boolean closeZipFile, ISystemOperationMonitor archiveOperationMonitor) { if (!_exists) return false; File outputTempFile = null; @@ -1674,30 +1715,30 @@ public class SystemZipHandler implements ISystemArchiveHandler if (closeZipFile) closeZipFile(); return false; } // file doesn't exist - + if (vc.isDirectory) // file is a directory, we must delete the contents { vcOmmit = getVirtualChildrenList(fullVirtualName, false, archiveOperationMonitor); } - + // Open a new tempfile which will be our destination for the new zip outputTempFile = new File(_file.getAbsolutePath() + "temp"); //$NON-NLS-1$ ZipOutputStream dest = new ZipOutputStream( - new FileOutputStream(outputTempFile)); + new FileOutputStream(outputTempFile)); dest.setMethod(ZipOutputStream.DEFLATED); - - // get all the entries in the old zip + + // get all the entries in the old zip vcList = getVirtualChildrenList(false, archiveOperationMonitor); - + HashSet omissions = new HashSet(); - + if (vc.isDirectory) { for (int i = 0; i < vcOmmit.length; i++) { omissions.add(vcOmmit[i].fullName); } - try + try { safeGetEntry(vc.fullName); omissions.add(vc.fullName); @@ -1708,7 +1749,7 @@ public class SystemZipHandler implements ISystemArchiveHandler { omissions.add(fullVirtualName); } - + // recreate the zip file without the omissions boolean isCanceled = recreateZipDeleteEntries(vcList, dest, omissions, archiveOperationMonitor); if (isCanceled) @@ -1718,12 +1759,12 @@ public class SystemZipHandler implements ISystemArchiveHandler if (closeZipFile) closeZipFile(); return false; } - + dest.close(); - + // Now replace the old zip file with the new one replaceOldZip(outputTempFile); - + // Now update the tree HashMap hm = (HashMap) _virtualFS.get(vc.path); hm.remove(vc.name); @@ -1775,16 +1816,17 @@ public class SystemZipHandler implements ISystemArchiveHandler /* (non-Javadoc) * @see org.eclipse.rse.services.clientserver.archiveutils.ISystemArchiveHandler#replace(java.lang.String, java.io.File, java.lang.String) */ - public boolean replace(String fullVirtualName, File file, String name, ISystemOperationMonitor archiveOperationMonitor) + public boolean replace(String fullVirtualName, File file, String name, ISystemOperationMonitor archiveOperationMonitor) { return replace(fullVirtualName, file, name, true, archiveOperationMonitor); } /** * Same as replace(String fullVirtualName, File file, String name) but you can choose whether - * or not you want to leave the zipfile open after return. - */ - public boolean replace(String fullVirtualName, File file, String name, boolean closeZipFile, ISystemOperationMonitor archiveOperationMonitor) + * or not you want to leave the zipfile open after return. + * @since org.eclipse.rse.services 3.0 + */ + public boolean replace(String fullVirtualName, File file, String name, boolean closeZipFile, ISystemOperationMonitor archiveOperationMonitor) { if (!_exists) return false; @@ -1795,9 +1837,9 @@ public class SystemZipHandler implements ISystemArchiveHandler // sorry, wrong method buddy return add(file, fullVirtualName, name, archiveOperationMonitor); } - - - + + + if (openZipFile()) { File outputTempFile = null; @@ -1806,13 +1848,13 @@ public class SystemZipHandler implements ISystemArchiveHandler // Open a new tempfile which will be our destination for the new zip outputTempFile = new File(_file.getAbsolutePath() + "temp"); //$NON-NLS-1$ ZipOutputStream dest = new ZipOutputStream( - new FileOutputStream(outputTempFile)); + new FileOutputStream(outputTempFile)); dest.setMethod(ZipOutputStream.DEFLATED); - // get all the entries in the old zip + // get all the entries in the old zip VirtualChild[] vcList = getVirtualChildrenList(false, archiveOperationMonitor); HashSet omissions = new HashSet(); omissions.add(fullVirtualName); - + boolean isCanceled = recreateZipDeleteEntries(vcList, dest, omissions, archiveOperationMonitor); if (isCanceled) { @@ -1821,11 +1863,11 @@ public class SystemZipHandler implements ISystemArchiveHandler if (closeZipFile) closeZipFile(); return false; } - + // Now append the additional entry to the zip file. int i = fullVirtualName.lastIndexOf("/"); //$NON-NLS-1$ String virtualPath; - if (i == -1) + if (i == -1) { virtualPath = ""; //$NON-NLS-1$ } @@ -1833,19 +1875,19 @@ public class SystemZipHandler implements ISystemArchiveHandler { virtualPath = fullVirtualName.substring(0,i); } - - + + // append the additional entry to the zip file. ZipEntry newEntry = appendFile(file, dest, virtualPath, name, SystemEncodingUtil.ENCODING_UTF_8, SystemEncodingUtil.ENCODING_UTF_8, false); - + // Add the new entry to the virtual file system in memory fillBranch(newEntry); - + dest.close(); - + // Now replace the old zip file with the new one replaceOldZip(outputTempFile); - + } catch (IOException e) { @@ -1858,10 +1900,14 @@ public class SystemZipHandler implements ISystemArchiveHandler return true; } else return false; - + } - public boolean replace(String fullVirtualName, InputStream stream, String name, String sourceEncoding, String targetEncoding, boolean isText, ISystemOperationMonitor archiveOperationMonitor) + /* + * (non-Javadoc) + * @see org.eclipse.rse.services.clientserver.archiveutils.ISystemArchiveHandler#replace(java.lang.String, java.io.InputStream, java.lang.String, java.lang.String, java.lang.String, boolean, org.eclipse.rse.services.clientserver.ISystemOperationMonitor) + */ + public boolean replace(String fullVirtualName, InputStream stream, String name, String sourceEncoding, String targetEncoding, boolean isText, ISystemOperationMonitor archiveOperationMonitor) { if (!_exists) return false; @@ -1880,9 +1926,9 @@ public class SystemZipHandler implements ISystemArchiveHandler // Open a new tempfile which will be our destination for the new zip outputTempFile = new File(_file.getAbsolutePath() + "temp"); //$NON-NLS-1$ ZipOutputStream dest = new ZipOutputStream( - new FileOutputStream(outputTempFile)); + new FileOutputStream(outputTempFile)); dest.setMethod(ZipOutputStream.DEFLATED); - // get all the entries in the old zip + // get all the entries in the old zip VirtualChild[] vcList = getVirtualChildrenList(false, archiveOperationMonitor); HashSet omissions = new HashSet(); omissions.add(fullVirtualName); @@ -1894,11 +1940,11 @@ public class SystemZipHandler implements ISystemArchiveHandler closeZipFile(); return false; } - + // Now append the additional entry to the zip file. int i = fullVirtualName.lastIndexOf("/"); //$NON-NLS-1$ String virtualPath; - if (i == -1) + if (i == -1) { virtualPath = ""; //$NON-NLS-1$ } @@ -1908,10 +1954,10 @@ public class SystemZipHandler implements ISystemArchiveHandler } appendBytes(stream, dest, virtualPath, name, sourceEncoding, targetEncoding, isText); dest.close(); - + // Now replace the old zip file with the new one replaceOldZip(outputTempFile); - + } catch (IOException e) { @@ -1926,20 +1972,21 @@ public class SystemZipHandler implements ISystemArchiveHandler else return false; } - + /* (non-Javadoc) * @see org.eclipse.rse.services.clientserver.archiveutils.ISystemArchiveHandler#fullRename(java.lang.String, java.lang.String) */ - public boolean fullRename(String fullVirtualName, String newFullVirtualName, ISystemOperationMonitor archiveOperationMonitor) + public boolean fullRename(String fullVirtualName, String newFullVirtualName, ISystemOperationMonitor archiveOperationMonitor) { return fullRename(fullVirtualName, newFullVirtualName, true, archiveOperationMonitor); } /** * Same as fullRename(String fullVirtualName, String newFullVirtualName) but you can choose whether - * or not you want to leave the zipfile open after return. - */ - public boolean fullRename(String fullVirtualName, String newFullVirtualName, boolean closeZipFile, ISystemOperationMonitor archiveOperationMonitor) + * or not you want to leave the zipfile open after return. + * @since org.eclipse.rse.services 3.0 + */ + public boolean fullRename(String fullVirtualName, String newFullVirtualName, boolean closeZipFile, ISystemOperationMonitor archiveOperationMonitor) { if (!_exists) return false; @@ -1961,9 +2008,9 @@ public class SystemZipHandler implements ISystemArchiveHandler // Open a new tempfile which will be our destination for the new zip outputTempFile = new File(_file.getAbsolutePath() + "temp"); //$NON-NLS-1$ ZipOutputStream dest = new ZipOutputStream( - new FileOutputStream(outputTempFile)); + new FileOutputStream(outputTempFile)); dest.setMethod(ZipOutputStream.DEFLATED); - // get all the entries in the old zip + // get all the entries in the old zip VirtualChild[] vcList = getVirtualChildrenList(false, archiveOperationMonitor); VirtualChild[] renameList = null; HashMap oldNewNames = new HashMap(); @@ -1978,7 +2025,7 @@ public class SystemZipHandler implements ISystemArchiveHandler int j = fullVirtualName.length(); String suffix = renameList[i].fullName.substring(j); String newName = newFullVirtualName + suffix; - if (renameList[i].isDirectory) + if (renameList[i].isDirectory) { newName = newName + "/"; //$NON-NLS-1$ oldNewNames.put(renameList[i].fullName + "/", newName); //$NON-NLS-1$ @@ -1993,13 +2040,13 @@ public class SystemZipHandler implements ISystemArchiveHandler oldNewNames.put(fullVirtualName + "/", newFullVirtualName + "/"); //$NON-NLS-1$ //$NON-NLS-2$ newOldNames.put(newFullVirtualName + "/", fullVirtualName + "/"); //$NON-NLS-1$ //$NON-NLS-2$ /* - try + try { safeGetEntry(fullVirtualName); names.put(fullVirtualName + "/", newFullVirtualName + "/"); //$NON-NLS-1$ //$NON-NLS-2$ } catch (IOException e) {} - */ + */ } else { @@ -2008,9 +2055,9 @@ public class SystemZipHandler implements ISystemArchiveHandler } // find the entry to rename and rename it boolean isCanceled = recreateZipRenameEntries(vcList, dest, oldNewNames, archiveOperationMonitor); - + dest.close(); - + if (isCanceled) { if (!(outputTempFile == null)) outputTempFile.delete(); @@ -2019,9 +2066,9 @@ public class SystemZipHandler implements ISystemArchiveHandler } // Now replace the old zip file with the new one replaceOldZip(outputTempFile); - + // Now rebuild the tree - updateTreeAfterRename(newOldNames, renameList); + updateTreeAfterRename(newOldNames, renameList); if (closeZipFile) closeZipFile(); return true; } @@ -2043,11 +2090,11 @@ public class SystemZipHandler implements ISystemArchiveHandler releaseMutex(mutexLockStatus); } } - + /* (non-Javadoc) * @see org.eclipse.rse.services.clientserver.archiveutils.ISystemArchiveHandler#move(java.lang.String, java.lang.String) */ - public boolean move(String fullVirtualName, String destinationVirtualPath, ISystemOperationMonitor archiveOperationMonitor) + public boolean move(String fullVirtualName, String destinationVirtualPath, ISystemOperationMonitor archiveOperationMonitor) { fullVirtualName = ArchiveHandlerManager.cleanUpVirtualPath(fullVirtualName); destinationVirtualPath = ArchiveHandlerManager.cleanUpVirtualPath(destinationVirtualPath); @@ -2063,7 +2110,7 @@ public class SystemZipHandler implements ISystemArchiveHandler /* (non-Javadoc) * @see org.eclipse.rse.services.clientserver.archiveutils.ISystemArchiveHandler#rename(java.lang.String, java.lang.String) */ - public boolean rename(String fullVirtualName, String newName, ISystemOperationMonitor archiveOperationMonitor) + public boolean rename(String fullVirtualName, String newName, ISystemOperationMonitor archiveOperationMonitor) { fullVirtualName = ArchiveHandlerManager.cleanUpVirtualPath(fullVirtualName); int i = fullVirtualName.lastIndexOf("/"); //$NON-NLS-1$ @@ -2076,8 +2123,8 @@ public class SystemZipHandler implements ISystemArchiveHandler setArchiveOperationMonitorStatusDone(archiveOperationMonitor); return returnValue; } - - + + /* (non-Javadoc) * @see org.eclipse.rse.services.clientserver.archiveutils.ISystemArchiveHandler#getFiles(java.lang.String[]) */ @@ -2101,7 +2148,7 @@ public class SystemZipHandler implements ISystemArchiveHandler name = fullName.substring(j+1); } try - { + { files[i] = File.createTempFile(name, "virtual"); //$NON-NLS-1$ files[i].deleteOnExit(); extractVirtualFile(fullNames[i], files[i], archiveOperationMonitor); @@ -2127,7 +2174,7 @@ public class SystemZipHandler implements ISystemArchiveHandler setArchiveOperationMonitorStatusDone(archiveOperationMonitor); return returnCode; } - + /* (non-Javadoc) * @see org.eclipse.rse.services.clientserver.archiveutils.ISystemArchiveHandler#createFile(java.lang.String) */ @@ -2138,18 +2185,19 @@ public class SystemZipHandler implements ISystemArchiveHandler setArchiveOperationMonitorStatusDone(archiveOperationMonitor); return returnCode; } - + /** * Creates a new, empty object in the virtual File system, and * creates an empty file or folder in the physical zip file. * @param name The name of the file or folder to create. The object * created will be a folder if and only if * name ends in a "/". - * @return Whether the creation was successful or not. + * @return Whether the creation was successful or not. + * @since org.eclipse.rse.services 3.0 */ protected boolean createVirtualObject(String name, boolean closeZipFile, ISystemOperationMonitor archiveOperationMonitor) { - if (!_exists) + if (!_exists) { return false; } @@ -2158,7 +2206,7 @@ public class SystemZipHandler implements ISystemArchiveHandler // The object already exists. return false; } - + int mutexLockStatus = SystemReentrantMutex.LOCK_STATUS_NOLOCK; try { @@ -2168,15 +2216,15 @@ public class SystemZipHandler implements ISystemArchiveHandler if (openZipFile()) { File outputTempFile; - + // Open a new tempfile which will be our destination for the new zip outputTempFile = new File(_file.getAbsolutePath() + "temp"); //$NON-NLS-1$ ZipOutputStream dest = new ZipOutputStream( - new FileOutputStream(outputTempFile)); + new FileOutputStream(outputTempFile)); dest.setMethod(ZipOutputStream.DEFLATED); - // get all the entries in the old zip + // get all the entries in the old zip VirtualChild[] vcList = getVirtualChildrenList(false, archiveOperationMonitor); - + // if it is an empty zip file, no need to recreate it if (!(vcList.length == 1) || !vcList[0].fullName.equals("")) //$NON-NLS-1$ { @@ -2189,17 +2237,17 @@ public class SystemZipHandler implements ISystemArchiveHandler return false; } } - + // append the additional entry to the zip file. ZipEntry newEntry = appendEmptyFile(dest, name); // Add the new entry to the virtual file system in memory fillBranch(newEntry); - + dest.close(); - + // Now replace the old zip file with the new one replaceOldZip(outputTempFile); - + if (closeZipFile) closeZipFile(); return true; } @@ -2210,7 +2258,7 @@ public class SystemZipHandler implements ISystemArchiveHandler System.out.println("Could not add a file."); //$NON-NLS-1$ System.out.println(e.getMessage()); if (closeZipFile) closeZipFile(); - return false; + return false; } finally { @@ -2218,7 +2266,7 @@ public class SystemZipHandler implements ISystemArchiveHandler } return false; } - + /** * Works similarly to appendFile, except no actual data is appended * to the zipfile, only an entry is created. Thus, if the file were @@ -2239,12 +2287,12 @@ public class SystemZipHandler implements ISystemArchiveHandler dest.write(new byte[0], 0, 0); dest.closeEntry(); } - return newEntry; + return newEntry; } - + /** * A "safe" ZipEntry is one whose virtual path does not begin with a - * "/". This seems to cause the least problems for archive utilities, + * "/". This seems to cause the least problems for archive utilities, * including this one. * @param name The virtual name for the new, safe ZipEntry. * @return The ZipEntry that is created. @@ -2254,13 +2302,17 @@ public class SystemZipHandler implements ISystemArchiveHandler if (name.startsWith("/")) name = name.substring(1); //$NON-NLS-1$ return new ZipEntry(name); } - + + /* + * (non-Javadoc) + * @see org.eclipse.rse.services.clientserver.archiveutils.ISystemArchiveHandler#getStandardName(org.eclipse.rse.services.clientserver.archiveutils.VirtualChild) + */ public String getStandardName(VirtualChild vc) { if (vc.isDirectory) return vc.fullName + "/"; //$NON-NLS-1$ return vc.fullName; } - + /** * Opens the zipfile that this handler manages. * @return Whether the zipfile was successfully opened. @@ -2280,7 +2332,7 @@ public class SystemZipHandler implements ISystemArchiveHandler } return true; } - + protected boolean closeZipFile() { try @@ -2295,11 +2347,12 @@ public class SystemZipHandler implements ISystemArchiveHandler } return true; } - + /** * If the mod-times of the underlying zip file and the file used to * create the virtualFS are different, update the virtualFS. * @return whether or not the op was successful. + * @since org.eclipse.rse.services 3.0 */ protected boolean updateVirtualFSIfNecessary(ISystemOperationMonitor archiveOperationMonitor) { @@ -2336,7 +2389,7 @@ public class SystemZipHandler implements ISystemArchiveHandler } return true; } - + /** * Returns the entry corresponding to name from _zipfile. Never returns * null, but rather, throws an IOException if it cannot find the entry. Tries to retrieve @@ -2350,26 +2403,30 @@ public class SystemZipHandler implements ISystemArchiveHandler if (entry == null) throw new IOException("SystemZipHandler.safeGetEntry(): The ZipEntry " + name + " cannot be found in " + _file.toString()); //$NON-NLS-1$ //$NON-NLS-2$ return entry; } - - public boolean create() + + /* + * (non-Javadoc) + * @see org.eclipse.rse.services.clientserver.archiveutils.ISystemArchiveHandler#create() + */ + public boolean create() { try { // The zipfile is our destination ZipOutputStream dest = new ZipOutputStream( - new FileOutputStream(_file)); + new FileOutputStream(_file)); dest.setMethod(ZipOutputStream.DEFLATED); - + VirtualChild[] vcList = new VirtualChild[0]; - + HashSet omissions = new HashSet(); // the above two statements force recreateZipDeleteEntries to create a dummy entry recreateZipDeleteEntries(vcList, dest, omissions, null); dest.close(); - - if (openZipFile()) + + if (openZipFile()) { - buildTree(); + buildTree(); closeZipFile(); } else @@ -2385,53 +2442,57 @@ public class SystemZipHandler implements ISystemArchiveHandler _exists = true; return true; } - - public SystemSearchLineMatch[] search(String fullVirtualName, SystemSearchStringMatcher matcher, ISystemOperationMonitor archiveOperationMonitor) + + /* + * (non-Javadoc) + * @see org.eclipse.rse.services.clientserver.archiveutils.ISystemArchiveHandler#search(java.lang.String, org.eclipse.rse.services.clientserver.search.SystemSearchStringMatcher, org.eclipse.rse.services.clientserver.ISystemOperationMonitor) + */ + public SystemSearchLineMatch[] search(String fullVirtualName, SystemSearchStringMatcher matcher, ISystemOperationMonitor archiveOperationMonitor) { - + // if the search string is empty or if it is "*", then return no matches // since it is a file search if (matcher.isSearchStringEmpty() || matcher.isSearchStringAsterisk()) { return new SystemSearchLineMatch[0]; } - + fullVirtualName = ArchiveHandlerManager.cleanUpVirtualPath(fullVirtualName); - + VirtualChild vc = getVirtualFile(fullVirtualName, archiveOperationMonitor); - + if (!vc.exists() || vc.isDirectory) { return new SystemSearchLineMatch[0]; } - + if (openZipFile()) { - + ZipEntry entry = null; - + SystemSearchLineMatch[] matches = null; - + try { entry = safeGetEntry(fullVirtualName); InputStream is = _zipfile.getInputStream(entry); - + if (is == null) { return new SystemSearchLineMatch[0]; } - + InputStreamReader isr = new InputStreamReader(is); BufferedReader bufReader = new BufferedReader(isr); - + SystemSearchStringMatchLocator locator = new SystemSearchStringMatchLocator(bufReader, matcher); matches = locator.locateMatches(); } catch (IOException e) { - System.out.println(e.getMessage()); + System.out.println(e.getMessage()); } - + closeZipFile(); - + if (matches == null) { return new SystemSearchLineMatch[0]; } @@ -2441,27 +2502,31 @@ public class SystemZipHandler implements ISystemArchiveHandler } else { return new SystemSearchLineMatch[0]; - } + } } - + + /* + * (non-Javadoc) + * @see org.eclipse.rse.services.clientserver.archiveutils.ISystemArchiveHandler#exists() + */ public boolean exists() { - return _exists; + return _exists; } - + /* (non-Javadoc) * @see org.eclipse.rse.services.clientserver.archiveutils.ISystemArchiveHandler#getCommentFor(java.lang.String) */ - public String getCommentFor(String fullVirtualName) + public String getCommentFor(String fullVirtualName) { return getCommentFor(fullVirtualName, true); } - /** + /** * same as getCommentFor(String) but you can choose whether or not to leave * the zipfile open after the method is closed */ - public String getCommentFor(String fullVirtualName, boolean closeZipFile) + public String getCommentFor(String fullVirtualName, boolean closeZipFile) { if (!_exists) return ""; //$NON-NLS-1$ @@ -2474,7 +2539,7 @@ public class SystemZipHandler implements ISystemArchiveHandler entry = safeGetEntry(fullVirtualName); } catch (IOException e) - { + { if (closeZipFile) closeZipFile(); return ""; //$NON-NLS-1$ } @@ -2489,16 +2554,16 @@ public class SystemZipHandler implements ISystemArchiveHandler /* (non-Javadoc) * @see org.eclipse.rse.core.archiveutils.ISystemArchiveHandler#getCompressedSizeFor(java.lang.String) */ - public long getCompressedSizeFor(String fullVirtualName) + public long getCompressedSizeFor(String fullVirtualName) { return getCompressedSizeFor(fullVirtualName, true); } - - /** + + /** * same as getCompressedSizeFor(String) but you can choose whether or not to leave * the zipfile open after the method is closed */ - public long getCompressedSizeFor(String fullVirtualName, boolean closeZipFile) + public long getCompressedSizeFor(String fullVirtualName, boolean closeZipFile) { if (!_exists) return 0; @@ -2511,7 +2576,7 @@ public class SystemZipHandler implements ISystemArchiveHandler entry = safeGetEntry(fullVirtualName); } catch (IOException e) - { + { if (closeZipFile) closeZipFile(); return 0; } @@ -2524,16 +2589,16 @@ public class SystemZipHandler implements ISystemArchiveHandler /* (non-Javadoc) * @see org.eclipse.rse.core.archiveutils.ISystemArchiveHandler#getCompressionMethodFor(java.lang.String) */ - public String getCompressionMethodFor(String fullVirtualName) + public String getCompressionMethodFor(String fullVirtualName) { return getCompressionMethodFor(fullVirtualName, true); } - /** + /** * same as getCompressionMethodFor(String) but you can choose whether or not to leave * the zipfile open after the method is closed - */ - public String getCompressionMethodFor(String fullVirtualName, boolean closeZipFile) + */ + public String getCompressionMethodFor(String fullVirtualName, boolean closeZipFile) { if (!_exists) return ""; //$NON-NLS-1$ @@ -2546,7 +2611,7 @@ public class SystemZipHandler implements ISystemArchiveHandler entry = safeGetEntry(fullVirtualName); } catch (IOException e) - { + { if (closeZipFile) closeZipFile(); return ""; //$NON-NLS-1$ } @@ -2555,10 +2620,11 @@ public class SystemZipHandler implements ISystemArchiveHandler } else return ""; //$NON-NLS-1$ } + /* (non-Javadoc) * @see org.eclipse.rse.core.archiveutils.ISystemArchiveHandler#getArchiveComment() */ - public String getArchiveComment() + public String getArchiveComment() { return ""; //$NON-NLS-1$ } @@ -2570,46 +2636,46 @@ public class SystemZipHandler implements ISystemArchiveHandler public String getClassification(String fullVirtualName) { return getClassification(fullVirtualName, true); } - + /** * Same as getClassification(String), but you can choose whether to leave the zip file * open after the method is closed. * @see org.eclipse.rse.services.clientserver.archiveutils.ISystemArchiveHandler#getClassification(java.lang.String) */ public String getClassification(String fullVirtualName, boolean closeZipFile) { - + // default type String type = "file"; //$NON-NLS-1$ - + if (!_exists) { return type; } - + fullVirtualName = ArchiveHandlerManager.cleanUpVirtualPath(fullVirtualName); - + // if it's not a class file, we do not classify it if (!fullVirtualName.endsWith(".class")) { //$NON-NLS-1$ return type; } - + // class file parser BasicClassFileParser parser = null; - + boolean isExecutable = false; - + if (openZipFile()) { - + // get the input stream for the entry InputStream stream = null; - + try { ZipEntry entry = safeGetEntry(fullVirtualName); stream = _zipfile.getInputStream(entry); - + // use class file parser to parse the class file parser = new BasicClassFileParser(stream); parser.parse(); - + // query if it is executable, i.e. whether it has main method isExecutable = parser.isExecutable(); @@ -2618,39 +2684,43 @@ public class SystemZipHandler implements ISystemArchiveHandler } } catch (IOException e) { - + if (closeZipFile) { closeZipFile(); } - + return type; } } - + // if it is executable, then also get qualified class name if (isExecutable && parser != null) { type = "executable(java"; //$NON-NLS-1$ - + String qualifiedClassName = parser.getQualifiedClassName(); - + if (qualifiedClassName != null) { - type = type + ":" + qualifiedClassName; //$NON-NLS-1$ + type = type + ":" + qualifiedClassName; //$NON-NLS-1$ } - + type = type + ")"; //$NON-NLS-1$ } - + return type; } - public boolean add(File file, String virtualPath, String name, String sourceEncoding, String targetEncoding, ISystemFileTypes registry, ISystemOperationMonitor archiveOperationMonitor) + /* + * (non-Javadoc) + * @see org.eclipse.rse.services.clientserver.archiveutils.ISystemArchiveHandler#add(java.io.File, java.lang.String, java.lang.String, java.lang.String, java.lang.String, org.eclipse.rse.services.clientserver.ISystemFileTypes, org.eclipse.rse.services.clientserver.ISystemOperationMonitor) + */ + public boolean add(File file, String virtualPath, String name, String sourceEncoding, String targetEncoding, ISystemFileTypes registry, ISystemOperationMonitor archiveOperationMonitor) { - if (!_exists) + if (!_exists) { setArchiveOperationMonitorStatusDone(archiveOperationMonitor); return false; } - + virtualPath = ArchiveHandlerManager.cleanUpVirtualPath(virtualPath); if (!file.isDirectory()) { @@ -2701,7 +2771,7 @@ public class SystemZipHandler implements ISystemArchiveHandler newNames[i] = sources[i].getAbsolutePath().substring(charsToTrim); newNames[i] = newNames[i].replace('\\','/'); if (sources[i].isDirectory() && !newNames[i].endsWith("/")) newNames[i] = newNames[i] + "/"; //$NON-NLS-1$ //$NON-NLS-2$ - + // this part can be changed to allow different encodings for different files sourceEncodings[i] = sourceEncoding; targetEncodings[i] = targetEncoding; @@ -2709,28 +2779,32 @@ public class SystemZipHandler implements ISystemArchiveHandler } sources[children.size()] = file; newNames[children.size()] = name; - sourceEncodings[children.size()] = sourceEncoding; - targetEncodings[children.size()] = targetEncoding; + sourceEncodings[children.size()] = sourceEncoding; + targetEncodings[children.size()] = targetEncoding; isTexts[children.size()] = registry.isText(file); if (!newNames[children.size()].endsWith("/")) newNames[children.size()] = newNames[children.size()] + "/"; //$NON-NLS-1$ //$NON-NLS-2$ - + boolean returnCode = add(sources, virtualPath, newNames, sourceEncodings, targetEncodings, isTexts, archiveOperationMonitor); setArchiveOperationMonitorStatusDone(archiveOperationMonitor); return returnCode; } } - public boolean add(File file, String virtualPath, String name, String sourceEncoding, String targetEncoding, boolean isText, ISystemOperationMonitor archiveOperationMonitor) + /* + * (non-Javadoc) + * @see org.eclipse.rse.services.clientserver.archiveutils.ISystemArchiveHandler#add(java.io.File, java.lang.String, java.lang.String, java.lang.String, java.lang.String, boolean, org.eclipse.rse.services.clientserver.ISystemOperationMonitor) + */ + public boolean add(File file, String virtualPath, String name, String sourceEncoding, String targetEncoding, boolean isText, ISystemOperationMonitor archiveOperationMonitor) { - if (!_exists) + if (!_exists) { setArchiveOperationMonitorStatusDone(archiveOperationMonitor); return false; } - + virtualPath = ArchiveHandlerManager.cleanUpVirtualPath(virtualPath); - + int mutexLockStatus = SystemReentrantMutex.LOCK_STATUS_NOLOCK; try { @@ -2740,7 +2814,7 @@ public class SystemZipHandler implements ISystemArchiveHandler if (!file.isDirectory()) { String fullVirtualName = getFullVirtualName(virtualPath, name); - if (exists(fullVirtualName, archiveOperationMonitor)) + if (exists(fullVirtualName, archiveOperationMonitor)) { boolean returnCode = replace(fullVirtualName, file, name, archiveOperationMonitor); setArchiveOperationMonitorStatusDone(archiveOperationMonitor); @@ -2785,7 +2859,7 @@ public class SystemZipHandler implements ISystemArchiveHandler newNames[i] = sources[i].getAbsolutePath().substring(charsToTrim); newNames[i] = newNames[i].replace('\\','/'); if (sources[i].isDirectory() && !newNames[i].endsWith("/")) newNames[i] = newNames[i] + "/"; //$NON-NLS-1$ //$NON-NLS-2$ - + // this part can be changed to allow different encodings for different files sourceEncodings[i] = sourceEncoding; targetEncodings[i] = targetEncoding; @@ -2805,16 +2879,16 @@ public class SystemZipHandler implements ISystemArchiveHandler } catch (Exception e) { - + } finally { releaseMutex(mutexLockStatus); } - + return false; } - + /** * Construct the full virtual name of a virtual file from its virtual path and name. * @param virtualPath the virtual path of this virtual file @@ -2834,7 +2908,7 @@ public class SystemZipHandler implements ISystemArchiveHandler } return fullVirtualName; } - + private void releaseMutex(int mutexLockStatus) { //We only release the mutex if we aquired it, not borrowed it. @@ -2843,7 +2917,7 @@ public class SystemZipHandler implements ISystemArchiveHandler _mutex.release(); } } - + private void setArchiveOperationMonitorStatusDone(ISystemOperationMonitor archiveOperationMonitor) { //We only set the status of the archive operation montor to done if it is not been canceled. diff --git a/rse/plugins/org.eclipse.rse.services/clientserver/org/eclipse/rse/internal/services/clientserver/archiveutils/TarOutputStream.java b/rse/plugins/org.eclipse.rse.services/clientserver/org/eclipse/rse/services/clientserver/archiveutils/TarOutputStream.java similarity index 92% rename from rse/plugins/org.eclipse.rse.services/clientserver/org/eclipse/rse/internal/services/clientserver/archiveutils/TarOutputStream.java rename to rse/plugins/org.eclipse.rse.services/clientserver/org/eclipse/rse/services/clientserver/archiveutils/TarOutputStream.java index 300881c6c59..e1d21f2ac37 100644 --- a/rse/plugins/org.eclipse.rse.services/clientserver/org/eclipse/rse/internal/services/clientserver/archiveutils/TarOutputStream.java +++ b/rse/plugins/org.eclipse.rse.services/clientserver/org/eclipse/rse/services/clientserver/archiveutils/TarOutputStream.java @@ -7,28 +7,28 @@ * * Initial Contributors: * The following IBM employees contributed to the Remote System Explorer - * component that contains this file: David McKnight, Kushal Munir, - * Michael Berger, David Dykstal, Phil Coulthard, Don Yantzi, Eric Simpson, + * component that contains this file: David McKnight, Kushal Munir, + * Michael Berger, David Dykstal, Phil Coulthard, Don Yantzi, Eric Simpson, * Emily Bruner, Mazen Faraj, Adrian Storisteanu, Li Ding, and Kent Hawley. * * Contributors: - * {Name} (company) - description of contribution. * Xuan Chen (IBM) - [api] SystemTarHandler has inconsistent API + * Martin Oberhuber (Wind River) - [cleanup] Move from internal to fix API leakage *******************************************************************************/ -package org.eclipse.rse.internal.services.clientserver.archiveutils; +package org.eclipse.rse.services.clientserver.archiveutils; import java.io.IOException; import java.io.OutputStream; -import org.eclipse.rse.services.clientserver.archiveutils.TarEntry; +import org.eclipse.rse.internal.services.clientserver.archiveutils.ITarConstants; /** * This class implements an output stream filter for writing files in the * tar file format. */ public class TarOutputStream extends OutputStream { - + private OutputStream out; private boolean isClosed; private boolean entryOpen; @@ -48,26 +48,26 @@ public class TarOutputStream extends OutputStream { * @see java.io.OutputStream#close() */ public void close() throws IOException { - + // if not already closed, then close the stream // before closing though, write out a block of empty data if (!isClosed) { - + byte[] dummy = new byte[ITarConstants.BLOCK_SIZE]; out.write(dummy); - + out.close(); - + isClosed = true; } } - + /** * Ensure that the stream is open. * @throws IOException if the stream is closed. */ private void ensureOpen() throws IOException { - + if (isClosed) { throw new IOException("Stream closed"); //$NON-NLS-1$ } @@ -81,54 +81,54 @@ public class TarOutputStream extends OutputStream { out.write(b); dataCount += 1; } - + /** * Begins writing a new tar entry, and positions the stream to the start of the entry data. * Closes the current entry if still active. * @throws IOException if an I/O occurs. */ public void putNextEntry(TarEntry entry) throws IOException { - + // previous entry open, so close it if (entryOpen) { closeEntry(); } - + // defer to the entry to write the entry fields entry.writeFields(out); - + // get the part of a block we need to fill int diff = ITarConstants.BLOCK_SIZE - ITarConstants.HEADER_LENGTH; - + // fill the block if we have used a part of it if (diff != 0) { byte[] dummy = new byte[diff]; out.write(dummy); } - + // set data count to 0 dataCount = 0; - + // indicate that entry is open entryOpen = true; } - + /** * Closes the current tar entry, and positions the stream for writing the next entry. * @throws IOException if an I/O error occurs. */ public void closeEntry() throws IOException { - + // get the part of a block int temp = (int)(dataCount % ITarConstants.BLOCK_SIZE); - + // fill the rest of the block with dummy data if we have filled part of a block if (temp != 0) { int diff = ITarConstants.BLOCK_SIZE - temp; byte[] dummy = new byte[diff]; out.write(dummy); } - + // indicate that entry has been closed entryOpen = false; } diff --git a/rse/plugins/org.eclipse.rse.services/clientserver/org/eclipse/rse/services/clientserver/processes/ISystemProcessRemoteConstants.java b/rse/plugins/org.eclipse.rse.services/clientserver/org/eclipse/rse/services/clientserver/processes/ISystemProcessRemoteConstants.java index fecbfe831a4..833d94daa79 100644 --- a/rse/plugins/org.eclipse.rse.services/clientserver/org/eclipse/rse/services/clientserver/processes/ISystemProcessRemoteConstants.java +++ b/rse/plugins/org.eclipse.rse.services/clientserver/org/eclipse/rse/services/clientserver/processes/ISystemProcessRemoteConstants.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2006, 2007 IBM Corporation and others. + * Copyright (c) 2006, 2008 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -7,12 +7,12 @@ * * Initial Contributors: * The following IBM employees contributed to the Remote System Explorer - * component that contains this file: David McKnight, Kushal Munir, - * Michael Berger, David Dykstal, Phil Coulthard, Don Yantzi, Eric Simpson, + * component that contains this file: David McKnight, Kushal Munir, + * Michael Berger, David Dykstal, Phil Coulthard, Don Yantzi, Eric Simpson, * Emily Bruner, Mazen Faraj, Adrian Storisteanu, Li Ding, and Kent Hawley. * * Contributors: - * {Name} (company) - description of contribution. + * Martin Oberhuber (Wind River) - [cleanup] add API "since" tags *******************************************************************************/ package org.eclipse.rse.services.clientserver.processes; @@ -28,7 +28,7 @@ public interface ISystemProcessRemoteConstants public static final int PROCESS_ATTRIBUTES_INDEX_TRACERPID = 5; public static final int PROCESS_ATTRIBUTES_INDEX_UID = 6; public static final int PROCESS_ATTRIBUTES_INDEX_USERNAME = 7; - public static final int PROCESS_ATTRIBUTES_INDEX_GID = 8; + public static final int PROCESS_ATTRIBUTES_INDEX_GID = 8; public static final int PROCESS_ATTRIBUTES_INDEX_VMSIZE = 9; public static final int PROCESS_ATTRIBUTES_INDEX_VMRSS = 10; public static final int PROCESS_ATTRIBUTES_COUNT = 11; @@ -42,7 +42,7 @@ public interface ISystemProcessRemoteConstants public static final char STATE_TRACED = 'T'; public static final char STATE_WAITING = 'D'; public static final char STATE_ZOMBIE = 'Z'; - + public static final char STATE_ZOS_SINGLE = '1'; public static final char STATE_ZOS_MSGQRECEIVEWAIT = 'A'; public static final char STATE_ZOS_MSGQSENDWAIT = 'B'; @@ -55,6 +55,7 @@ public interface ISystemProcessRemoteConstants public static final char STATE_ZOS_SWAPPEDOUT = 'I'; public static final char STATE_ZOS_PTHREADCREATED = 'J'; public static final char STATE_ZOS_OTHERKERNELWAIT = 'K'; + /** @since 3.0 renamed from STATE_ZOS_CANCELLED */ public static final char STATE_ZOS_CANCELED = 'L'; public static final char STATE_ZOS_MULTITHREAD = 'M'; public static final char STATE_ZOS_MEDIUMWEIGHTTHREAD = 'N'; @@ -94,6 +95,7 @@ public interface ISystemProcessRemoteConstants public static final int STATE_ZOS_SWAPPEDOUT_INDEX = 18; public static final int STATE_ZOS_PTHREADCREATED_INDEX = 19; public static final int STATE_ZOS_OTHERKERNELWAIT_INDEX = 20; + /** @since 3.0 renamed from STATE_ZOS_CANCELLED_INDEX */ public static final int STATE_ZOS_CANCELED_INDEX = 21; public static final int STATE_ZOS_MULTITHREAD_INDEX = 22; public static final int STATE_ZOS_MEDIUMWEIGHTTHREAD_INDEX = 23; @@ -109,8 +111,8 @@ public interface ISystemProcessRemoteConstants public static final int STATE_ZOS_MVSWAIT_INDEX = 33; public static final int STATE_ZOS_ZOMBIE_INDEX = 34; public static final int STATE_ZOS_ENDING_INDEX = 35; - - public static final char[] ALL_STATES = + + public static final char[] ALL_STATES = { STATE_ACTIVE, STATE_IDLE, @@ -146,11 +148,11 @@ public interface ISystemProcessRemoteConstants STATE_ZOS_WAITINGFORCHILD, STATE_ZOS_FORKING, STATE_ZOS_MVSWAIT, - STATE_ZOS_ZOMBIE + STATE_ZOS_ZOMBIE }; - - public static final String[] ALL_STATES_STR = - { + + public static final String[] ALL_STATES_STR = + { "ASTATE_ACTIVE", //$NON-NLS-1$ "ISTATE_IDLE", //$NON-NLS-1$ "OSTATE_NONEXISTENT", //$NON-NLS-1$ @@ -187,9 +189,9 @@ public interface ISystemProcessRemoteConstants "YSTATE_ZOS_MVSWAIT", //$NON-NLS-1$ "ZSTATE_ZOS_ZOMBIE" //$NON-NLS-1$ }; - + public static final String PROCESS_MINER_ERROR_NO_HANDLER = "No handler for this system type"; //$NON-NLS-1$ public static final String PROCESS_MINER_SUCCESS = "SUCCESS"; //$NON-NLS-1$ - + public static final String PROCESS_SIGNAL_TYPE_DEFAULT = "default"; //$NON-NLS-1$ } diff --git a/rse/plugins/org.eclipse.rse.services/src/org/eclipse/rse/services/files/IFileService.java b/rse/plugins/org.eclipse.rse.services/src/org/eclipse/rse/services/files/IFileService.java index b7d5b6cc7d0..da8caf36542 100644 --- a/rse/plugins/org.eclipse.rse.services/src/org/eclipse/rse/services/files/IFileService.java +++ b/rse/plugins/org.eclipse.rse.services/src/org/eclipse/rse/services/files/IFileService.java @@ -7,8 +7,8 @@ * * Initial Contributors: * The following IBM employees contributed to the Remote System Explorer - * component that contains this file: David McKnight, Kushal Munir, - * Michael Berger, David Dykstal, Phil Coulthard, Don Yantzi, Eric Simpson, + * component that contains this file: David McKnight, Kushal Munir, + * Michael Berger, David Dykstal, Phil Coulthard, Don Yantzi, Eric Simpson, * Emily Bruner, Mazen Faraj, Adrian Storisteanu, Li Ding, and Kent Hawley. * * Contributors: @@ -16,12 +16,13 @@ * Martin Oberhuber (Wind River) - [183824] Forward SystemMessageException from IRemoteFileSubsystem * Martin Oberhuber (Wind River) - [199548] Avoid touching files on setReadOnly() if unnecessary * Martin Oberhuber (Wind River) - [204710] Update Javadoc to mention that getUserHome() may return null - * David McKnight (IBM) - [207178] changing list APIs for file service and subsystems - * David McKnight (IBM) - [162195] new APIs for upload multi and download multi - * David McKnight (IBM) - [209552] API changes to use multiple and getting rid of deprecated - * David McKnight (IBM) - [210109] store constants in IFileService rather than IFileServiceConstants - * Kevin Doyle (IBM) - [208778] new API getOutputSteam for getting an output stream in append mode - * David McKnight (IBM) - [209704] added supportsEncodingConversion() + * David McKnight (IBM) - [207178] changing list APIs for file service and subsystems + * David McKnight (IBM) - [162195] new APIs for upload multi and download multi + * David McKnight (IBM) - [209552] API changes to use multiple and getting rid of deprecated + * David McKnight (IBM) - [210109] store constants in IFileService rather than IFileServiceConstants + * Kevin Doyle (IBM) - [208778] new API getOutputSteam for getting an output stream in append mode + * David McKnight (IBM) - [209704] added supportsEncodingConversion() + * Martin Oberhuber (Wind River) - [cleanup] Fix API since tags *******************************************************************************/ package org.eclipse.rse.services.files; @@ -39,7 +40,7 @@ import org.eclipse.rse.services.clientserver.messages.SystemMessageException; * A IFileService is an abstraction of a file service that runs over some sort of connection. * It can be shared among multiple instances of a subsystem. At some point this file * service layer may become official API but for now it is experimental. Each - * subsystem is currently responsible for layering an abstraction over whatever it + * subsystem is currently responsible for layering an abstraction over whatever it * wants to construct as a service. *

* This is a very bare bones definition. A real definition would probably have changed @@ -54,77 +55,90 @@ import org.eclipse.rse.services.clientserver.messages.SystemMessageException; *

*/ public interface IFileService extends IService -{ - /** - * Query constant (bit mask value 1) which indicates that a query should be - * on files. The filter(s) passed into the list methods will produce a subset - * of files matching the filter(s). +{ + /** + * Query constant (bit mask value 1) which indicates that a query should be + * on files. The filter(s) passed into the list methods will produce a + * subset of files matching the filter(s). + * + * This constant is passed into the IFileService list calls. Implementors of + * IFileService make use of this to determine what to query and what to + * return from the query. * - * This constant is passed into the IFileService list calls. Implementors of - * IFileService make use of this to determine what to query and what to return - * from the query. - * * @see IFileService#list(String,String,int,IProgressMonitor) * @see IFileService#listMultiple(String[],String[],int,IProgressMonitor) * @see IFileService#listMultiple(String[],String[],int[],IProgressMonitor) + * + * @since org.eclipse.rse.services 3.0 */ public static final int FILE_TYPE_FILES = 0x1; - - /** - * Query constant (bit mask value 2) which indicates that a query should be - * on folders. The filter(s) passed into the list methods will produce a subset - * of folders matching the filter(s). + + /** + * Query constant (bit mask value 2) which indicates that a query should be + * on folders. The filter(s) passed into the list methods will produce a + * subset of folders matching the filter(s). + * + * This constant is passed into the IFileService list calls. Implementors of + * IFileService make use of this to determine what to query and what to + * return from the query. * - * This constant is passed into the IFileService list calls. Implementors of - * IFileService make use of this to determine what to query and what to return - * from the query. - * * @see IFileService#list(String,String,int,IProgressMonitor) * @see IFileService#listMultiple(String[],String[],int,IProgressMonitor) * @see IFileService#listMultiple(String[],String[],int[],IProgressMonitor) + * + * @since org.eclipse.rse.services 3.0 */ public static final int FILE_TYPE_FOLDERS = 0x2; - - /** - * Query constant (bit mask value 0) which indicates that a query should produce - * folders and files. The filter(s) passed into the list methods will produce a - * subset of files matching the filter(s) and all the folders. - * Note that only files are filtered and all folders are returned when this is used. + + /** + * Query constant (bit mask value 0) which indicates that a query should + * produce folders and files. The filter(s) passed into the list methods + * will produce a subset of files matching the filter(s) and all the + * folders. Note that only files are filtered and all folders are returned + * when this is used. + * + * This constant is passed into the IFileService list calls. Implementors of + * IFileService make use of this to determine what to query and what to + * return from the query. * - * This constant is passed into the IFileService list calls. Implementors of - * IFileService make use of this to determine what to query and what to return - * from the query. - * * @see IFileService#list(String,String,int,IProgressMonitor) * @see IFileService#listMultiple(String[],String[],int,IProgressMonitor) * @see IFileService#listMultiple(String[],String[],int[],IProgressMonitor) + * + * @since org.eclipse.rse.services 3.0 */ public static final int FILE_TYPE_FILES_AND_FOLDERS = 0x0; /** - * Options constant (value 1 <<0) for specifying a stream - * that will append data to a file. + * Options constant (value 1 <<0) for specifying a stream that will + * append data to a file. * * @see IFileService#getOutputStream(String, String, int, IProgressMonitor) + * + * @since org.eclipse.rse.services 3.0 */ public static final int APPEND = 1 << 0; - + /** - * Options constant (value 2 <<0) for specifying that a file - * is Text instead of the default Binary. - * - * In Text mode, encoding conversions and line end conversions can be + * Options constant (value 2 <<0) for specifying that a file is Text + * instead of the default Binary. + * + * In Text mode, encoding conversions and line end conversions can be * performed on the stream. * * @see IFileService#getOutputStream(String, String, int, IProgressMonitor) + * + * @since org.eclipse.rse.services 3.0 */ public static final int TEXT_MODE = 2 << 0; - + /** * Options constant (value 0) to indicate that no bit options are set. + * + * @since org.eclipse.rse.services 3.0 */ public static final int NONE = 0; - + /** * Copy a file to the remote file system. The remote target is denoted by a * string representing the parent and a string representing the file. @@ -135,11 +149,11 @@ public interface IFileService extends IService * @param hostEncoding - the tgt encoding of the file (if text) * @param monitor the monitor for this potentially long running operation * @return true if the file was uploaded - * @throws SystemMessageException if an error occurs. + * @throws SystemMessageException if an error occurs. * Typically this would be one of those in the RemoteFileException family. */ public boolean upload(InputStream stream, String remoteParent, String remoteFile, boolean isBinary, String hostEncoding, IProgressMonitor monitor) throws SystemMessageException; - + /** * Copy a file to the remote file system. The remote target is denoted by a * string representing the parent and a string representing the file. @@ -151,7 +165,7 @@ public interface IFileService extends IService * @param hostEncoding - the tgt encoding of the file (if text) * @param monitor the monitor for this potentially long running operation * @return true if the file was uploaded - * @throws SystemMessageException if an error occurs. + * @throws SystemMessageException if an error occurs. * Typically this would be one of those in the * {@link RemoteFileException} family. */ @@ -169,288 +183,336 @@ public interface IFileService extends IService * @param hostEncodings - the tgt encodings of the files (if text) * @param monitor the monitor for this potentially long running operation * @return true if the files were uploaded - * @throws SystemMessageException if an error occurs. + * @throws SystemMessageException if an error occurs. * Typically this would be one of those in the * {@link RemoteFileException} family. + * + * @since org.eclipse.rse.services 3.0 */ public boolean uploadMultiple(File[] localFiles, String[] remoteParents, String[] remoteFiles, boolean[] isBinary, String[] srcEncodings, String[] hostEncodings, IProgressMonitor monitor) throws SystemMessageException; - + /** * Copy a file from the remote file system to the local system. * @param remoteParent - a String designating the remote parent. * @param remoteFile - a String designating the remote file residing in the parents. - * @param localFile - The file that is to be written. If the file exists it is + * @param localFile - The file that is to be written. If the file exists it is * overwritten. * @param isBinary - indicates whether the file is text on binary * @param hostEncoding - the encoding on the host (if text) * @param monitor the monitor for this potentially long running operation * @return true if the file was copied from the remote system. - * @throws SystemMessageException if an error occurs. - * Typically this would be one of those in the + * @throws SystemMessageException if an error occurs. + * Typically this would be one of those in the * {@link RemoteFileException} family. */ public boolean download(String remoteParent, String remoteFile, File localFile, boolean isBinary, String hostEncoding, IProgressMonitor monitor) throws SystemMessageException; /** * Copy files from the remote file system to the local system. + * * @param remoteParents - string designating the remote parents. - * @param remoteFiles - Strings designating the remote files residing in the parents. - * @param localFiles - The files that are to be written. If the files exists they are - * overwritten. + * @param remoteFiles - Strings designating the remote files residing in the + * parents. + * @param localFiles - The files that are to be written. If the files exists + * they are overwritten. * @param isBinary - indicates whether the files are text on binary * @param hostEncodings - the encodings on the host (if text) * @param monitor the monitor for this potentially long running operation * @return true if the files were copied from the remote system. - * @throws SystemMessageException if an error occurs. - * Typically this would be one of those in the - * {@link RemoteFileException} family. + * @throws SystemMessageException if an error occurs. Typically this would + * be one of those in the {@link RemoteFileException} family. + * + * @since org.eclipse.rse.services 3.0 */ public boolean downloadMultiple(String[] remoteParents, String[] remoteFiles, File[] localFiles, boolean[] isBinary, String[] hostEncodings, IProgressMonitor monitor) throws SystemMessageException; - - + + /** + * Get an abstract remote file handle for a specified path. + * * @param remoteParent * @param name * @param monitor the monitor for this potentially long running operation - * @return the host file given the parent path and file name. - * Must not return null, non-existing files should be - * reported with an IHostFile object where {@link IHostFile#exists()} - * returns false. - * @throws SystemMessageException if an error occurs. - * Typically this would be one of those in the RemoteFileException family. + * @return the host file given the parent path and file name. Must not + * return null, non-existing files should be + * reported with an IHostFile object where + * {@link IHostFile#exists()} returns false. + * @throws SystemMessageException if an error occurs. Typically this would + * be one of those in the RemoteFileException family. */ public IHostFile getFile(String remoteParent, String name, IProgressMonitor monitor) throws SystemMessageException; - - + + /** - * @param remoteParent - the name of the parent directory on the remote file - * system from which to retrieve the child list. - * @param fileFilter - a string that can be used to filter the children. Only - * those files matching the filter make it into the list. The interface - * does not dictate where the filtering occurs. - * @param fileType - indicates whether to query files, folders, both or some other type - * @param monitor the monitor for this potentially long running operation - * @return the list of host files. - * @throws SystemMessageException if an error occurs. - * Typically this would be one of those in the RemoteFileException family. + * List the contents of a remote folder. * + * @param remoteParent - the name of the parent directory on the remote file + * system from which to retrieve the child list. + * @param fileFilter - a string that can be used to filter the children. + * Only those files matching the filter make it into the list. + * The interface does not dictate where the filtering occurs. + * @param fileType - indicates whether to query files, folders, both or some + * other type + * @param monitor the monitor for this potentially long running operation + * @return the list of host files. + * @throws SystemMessageException if an error occurs. Typically this would + * be one of those in the RemoteFileException family. + * + * @since org.eclipse.rse.services 3.0 */ public IHostFile[] list(String remoteParent, String fileFilter, int fileType, IProgressMonitor monitor) throws SystemMessageException; - - - - /** + * Get multiple abstract remote file handles for an array of specified + * paths. + * * @param remoteParents - the list of remote parents * @param names - the list of file names * @param monitor the monitor for this potentially long running operation - * @return the host files given the parent paths and file names. This is basically a batch version of getFile(). - * Must not return null, non-existing files should be - * reported with an IHostFile object where {@link IHostFile#exists()} - * returns false. - * @throws SystemMessageException if an error occurs. - * Typically this would be one of those in the RemoteFileException family. + * @return the host files given the parent paths and file names. This is + * basically a batch version of getFile(). Must not return + * null, non-existing files should be reported with + * an IHostFile object where {@link IHostFile#exists()} returns + * false. + * @throws SystemMessageException if an error occurs. Typically this would + * be one of those in the RemoteFileException family. + * + * @since org.eclipse.rse.services 3.0 */ public IHostFile[] getFileMultiple(String remoteParents[], String names[], IProgressMonitor monitor) throws SystemMessageException; - - /** - * @param remoteParents - the names of the parent directories on the remote file - * system from which to retrieve the collective child list. - * @param fileFilters - a set of strings that can be used to filter the children. Only - * those files matching the filter corresponding to it's remoteParent make it into the list. The interface - * does not dictate where the filtering occurs. For each remoteParent, there must be a corresponding - * fileFilter. - * @param fileTypes - indicates whether to query files, folders, both or some other type. For - * each remoteParent, there must be a corresponding fileType. - * For the default list of available file types see IFileServiceContants - * @param monitor the monitor for this potentially long running operation - * @return the collective list of host files that reside in each of the remoteParents with it's corresponding filter. - * @throws SystemMessageException if an error occurs. - * Typically this would be one of those in the RemoteFileException family. - */ - public IHostFile[] listMultiple(String[] remoteParents, String[] fileFilters, int[] fileTypes, IProgressMonitor monitor) throws SystemMessageException; - - /** - * @param remoteParents - the names of the parent directories on the remote file - * system from which to retrieve the collective child list. - * @param fileFilters - a set of strings that can be used to filter the children. Only - * those files matching the filter corresponding to it's remoteParent make it into the list. The interface - * does not dictate where the filtering occurs. For each remoteParent, there must be a corresponding - * fileFilter. - * @param fileType - indicates whether to query files, folders, both or some other type. For - * each remoteParent, there must be a corresponding fileType. - * For the default list of available file types see IFileServiceContants - * @param monitor the monitor for this potentially long running operation - * @return the collective list of host files that reside in each of the remoteParents with it's corresponding filter. - * @throws SystemMessageException if an error occurs. - * Typically this would be one of those in the RemoteFileException family. - */ - public IHostFile[] listMultiple(String[] remoteParents, String[] fileFilters, int fileType, IProgressMonitor monitor) throws SystemMessageException; - /** + * List the contents of multiple remote folders. + * + * @param remoteParents - the names of the parent directories on the remote + * file system from which to retrieve the collective child list. + * @param fileFilters - a set of strings that can be used to filter the + * children. Only those files matching the filter corresponding + * to it's remoteParent make it into the list. The interface does + * not dictate where the filtering occurs. For each remoteParent, + * there must be a corresponding fileFilter. + * @param fileTypes - indicates whether to query files, folders, both or + * some other type. For each remoteParent, there must be a + * corresponding fileType. For the default list of available file + * types see IFileServiceContants * @param monitor the monitor for this potentially long running operation - * Return the list of roots for this system - * @return the list of host files. - * @throws SystemMessageException if an error occurs. - * Typically this would be one of those in the RemoteFileException family. + * @return the collective list of host files that reside in each of the + * remoteParents with it's corresponding filter. + * @throws SystemMessageException if an error occurs. Typically this would + * be one of those in the RemoteFileException family. + * + * @since org.eclipse.rse.services 3.0 + */ + public IHostFile[] listMultiple(String[] remoteParents, String[] fileFilters, int[] fileTypes, IProgressMonitor monitor) throws SystemMessageException; + + /** + * List the contents of multiple remote folders. + * + * @param remoteParents - the names of the parent directories on the remote + * file system from which to retrieve the collective child list. + * @param fileFilters - a set of strings that can be used to filter the + * children. Only those files matching the filter corresponding + * to it's remoteParent make it into the list. The interface does + * not dictate where the filtering occurs. For each remoteParent, + * there must be a corresponding fileFilter. + * @param fileType - indicates whether to query files, folders, both or some + * other type. All results will be of the specified type. For the + * default list of available file types see + * IFileServiceContants + * @param monitor the monitor for this potentially long running operation + * @return the collective list of host files that reside in each of the + * remoteParents with it's corresponding filter. + * @throws SystemMessageException if an error occurs. Typically this would + * be one of those in the RemoteFileException family. + * + * @since org.eclipse.rse.services 3.0 + */ + public IHostFile[] listMultiple(String[] remoteParents, String[] fileFilters, int fileType, IProgressMonitor monitor) throws SystemMessageException; + + + /** + * Get abstract remote file handles for the known remote file system roots. + * + * @param monitor the monitor for this potentially long running operation + * Return the list of roots for this system + * @return the list of host files. + * @throws SystemMessageException if an error occurs. Typically this would + * be one of those in the RemoteFileException family. */ public IHostFile[] getRoots(IProgressMonitor monitor) throws SystemMessageException; - + /** * Return the user's home directory on this connection. * - * The resulting IHostFile object is just a handle, so there is no guarantee + * The resulting IHostFile object is just a handle, so there is no guarantee * that it refers to an existing file. * * This method may also return null if the home directory could * not be determined (for instance, because the connection is not yet connected). * In this case, clients are encouraged to query the home directory again once * the connection is connected. - * + * * @return A handle to the current user's home directory, or null - * if the home directory could not be determined. + * if the home directory could not be determined. */ public IHostFile getUserHome(); /** - * Create a file on the host + * Create a file on the host. + * * @param remoteParent the parent directory * @param fileName the name of the new file * @param monitor the monitor for this potentially long running operation * @return the newly created file - * @throws SystemMessageException if an error occurs. - * Typically this would be one of those in the RemoteFileException family. + * @throws SystemMessageException if an error occurs. Typically this would + * be one of those in the RemoteFileException family. */ public IHostFile createFile(String remoteParent, String fileName, IProgressMonitor monitor) throws SystemMessageException; - + /** - * Create a folder on the host + * Create a folder on the host. + * * @param remoteParent the parent directory * @param folderName the name of the new folder * @param monitor the progress monitor * @return the newly created folder - * @throws SystemMessageException if an error occurs. - * Typically this would be one of those in the RemoteFileException family. + * @throws SystemMessageException if an error occurs. Typically this would + * be one of those in the RemoteFileException family. */ public IHostFile createFolder(String remoteParent, String folderName, IProgressMonitor monitor) throws SystemMessageException; - + /** - * Deletes a file or folder on the host + * Delete a file or folder on the host. + * * @param remoteParent the folder containing the file to delete * @param fileName the name of the file or folder to delete * @param monitor the progress monitor * @return true if successful - * @throws SystemMessageException if an error occurs. - * Typically this would be one of those in the RemoteFileException family. + * @throws SystemMessageException if an error occurs. Typically this would + * be one of those in the RemoteFileException family. */ public boolean delete(String remoteParent, String fileName, IProgressMonitor monitor) throws SystemMessageException; /** - * Deletes a set of files or folders on the host. Should throw an exception if some files and folders were deleted and others were not - * due to an exception during the operation. Without an exception thrown in such cases, views may not be refreshed correctly to account - * for deleted resources. + * Delete a set of files or folders on the host. Should throw an exception + * if some files and folders were deleted and others were not due to an + * exception during the operation. Without an exception thrown in such + * cases, views may not be refreshed correctly to account for deleted + * resources. + * * @param remoteParents the array of folders containing the files to delete * @param fileNames the names of the files or folders to delete * @param monitor the progress monitor - * @return true iff all deletes are successful - * @throws SystemMessageException if an error occurs. - * Typically this would be one of those in the RemoteFileException family. + * @return true if all delete operations are successful, + * false otherwise. + * @throws SystemMessageException if an error occurs. Typically this would + * be one of those in the RemoteFileException family. */ public boolean deleteBatch(String[] remoteParents, String[] fileNames, IProgressMonitor monitor) throws SystemMessageException; /** - * Renames a file or folder on the host + * Rename a file or folder on the host. + * * @param remoteParent the folder containing the file to rename * @param oldName the old name of the file or folder to rename * @param newName the new name for the file * @param monitor the progress monitor * @return true if successful - * @throws SystemMessageException if an error occurs. - * Typically this would be one of those in the RemoteFileException family. + * @throws SystemMessageException if an error occurs. Typically this would + * be one of those in the RemoteFileException family. */ public boolean rename(String remoteParent, String oldName, String newName, IProgressMonitor monitor) throws SystemMessageException; - + /** - * Renames a file or folder on the host + * Rename a file or folder on the host. + * * @param remoteParent the folder containing the file to rename * @param oldName the old name of the file or folder to rename * @param newName the new name for the file * @param oldFile the file to update with the change * @param monitor the progress monitor * @return true if successful - * @throws SystemMessageException if an error occurs. - * Typically this would be one of those in the RemoteFileException family. + * @throws SystemMessageException if an error occurs. Typically this would + * be one of those in the RemoteFileException family. */ public boolean rename(String remoteParent, String oldName, String newName, IHostFile oldFile, IProgressMonitor monitor) throws SystemMessageException; - + /** - * Move the file or folder specified + * Move the file or folder specified to a different remote path. + * * @param srcParent the folder containing the file or folder to move * @param srcName the new of the file or folder to move * @param tgtParent the destination folder for the move * @param tgtName the name of the moved file or folder * @param monitor the progress monitor * @return true if the file was moved - * @throws SystemMessageException if an error occurs. - * Typically this would be one of those in the RemoteFileException family. + * @throws SystemMessageException if an error occurs. Typically this would + * be one of those in the RemoteFileException family. */ public boolean move(String srcParent, String srcName, String tgtParent, String tgtName, IProgressMonitor monitor) throws SystemMessageException; /** - * Copy the file or folder to the specified destination + * Copy the file or folder to the specified destination. + * * @param srcParent the folder containing the file or folder to copy * @param srcName the new of the file or folder to copy * @param tgtParent the destination folder for the copy * @param tgtName the name of the copied file or folder * @param monitor the progress monitor * @return true if the file was copied successfully - * @throws SystemMessageException if an error occurs. - * Typically this would be one of those in the RemoteFileException family. + * @throws SystemMessageException if an error occurs. Typically this would + * be one of those in the RemoteFileException family. */ public boolean copy(String srcParent, String srcName, String tgtParent, String tgtName, IProgressMonitor monitor) throws SystemMessageException; /** - * Copy a set of files or folders to the specified destination + * Copy a set of files or folders to the specified destination. + * * @param srcParents the folders containing each file or folder to copy * @param srcNames the names of the files or folders to copy * @param tgtParent the destination folder for the copy * @param monitor the progress monitor - * @return true if all files were copied - * @throws SystemMessageException if an error occurs. - * Typically this would be one of those in the RemoteFileException family. + * @return true if all files were copied, false + * or exception otherwise. + * @throws SystemMessageException if an error occurs. Typically this would + * be one of those in the RemoteFileException family. */ public boolean copyBatch(String[] srcParents, String[] srcNames, String tgtParent, IProgressMonitor monitor) throws SystemMessageException; /** - * Indicates whether the file system is case sensitive + * Indicates whether the file system is case sensitive. + * * @return true if the file system has case sensitive file names */ public boolean isCaseSensitive(); - + /** - * Sets the last modified stamp of the file or folder with the specified timestamp + * Set the last modified stamp of the file or folder with the specified + * timestamp. + * * @param parent the parent path of the file to set * @param name the name of the file to set - * @param timestamp the new timestamp + * @param timestamp the new timestamp * @param monitor the progress monitor * @return true if the file timestamp was changed successfully */ public boolean setLastModified(String parent, String name, long timestamp, IProgressMonitor monitor) throws SystemMessageException; - + /** - * Sets the readonly permission of the file or folder + * Set the read-only permission of the specified file or folder. + * * @param parent the parent path of the file to set * @param name the name of the file to set - * @param readOnly indicates whether to make the file readonly or read-write + * @param readOnly indicates whether to make the file read-only or + * read-write * @param monitor the progress monitor - * @return true if the readonly permission was changed successfully, or the permission already was as desired + * @return true if the read-only permission was changed successfully, or the + * permission already was as desired */ public boolean setReadOnly(String parent, String name, boolean readOnly, IProgressMonitor monitor) throws SystemMessageException; - + /** * Gets the remote encoding. * @param monitor the progress monitor. @@ -459,51 +521,65 @@ public interface IFileService extends IService * @since 2.0 */ public String getEncoding(IProgressMonitor monitor) throws SystemMessageException; - + /** - * Gets the input stream to access the contents a remote file. Clients should close the input stream when done. + * Get the input stream to access the contents a remote file. Clients should + * close the input stream when done. + * * @param remoteParent the absolute path of the parent. * @param remoteFile the name of the remote file. - * @param isBinary true if the file is a binary file, false otherwise. + * @param isBinary true if the file is a binary file, + * false otherwise. * @param monitor the progress monitor. * @return the input stream to access the contents of the remote file. - * @throws SystemMessageException if an error occurs. S - * @since 2.0 + * @throws SystemMessageException if an error occurs. + * @since org.eclipse.rse.services 2.0 */ public InputStream getInputStream(String remoteParent, String remoteFile, boolean isBinary, IProgressMonitor monitor) throws SystemMessageException; - + /** - * Gets the output stream to write to a remote file. Clients should close the output stream when done. + * Get the output stream to write to a remote file. Clients should close the + * output stream when done. + * * @param remoteParent the absolute path of the parent. * @param remoteFile the name of the remote file. - * @param isBinary true if the file is a binary file, false otherwise. + * @param isBinary true if the file is a binary file, + * false otherwise. * @param monitor the progress monitor. * @return the input stream to access the contents of the remote file. * @throws SystemMessageException if an error occurs. - * @since 2.0 - * @deprecated Use {@link #getOutputStream(String, String, int, IProgressMonitor)} instead + * @since org.eclipse.rse.services 2.0 + * @deprecated Use + * {@link #getOutputStream(String, String, int, IProgressMonitor)} + * instead */ public OutputStream getOutputStream(String remoteParent, String remoteFile, boolean isBinary, IProgressMonitor monitor) throws SystemMessageException; - + /** - * Gets the output stream to write/append to a remote file. Clients should close the output stream when done. + * Get the output stream to write/append to a remote file. Clients should + * close the output stream when done. + * * @param remoteParent the absolute path of the parent. * @param remoteFile the name of the remote file. - * @param options bit wise or of option constants. Valid constants are {@link IFileService#APPEND}, {@link IFileService#TEXT_MODE}, and {@link IFileService#NONE} + * @param options bit wise or of option constants. Valid constants are + * {@link IFileService#APPEND}, {@link IFileService#TEXT_MODE}, + * and {@link IFileService#NONE} * @param monitor the progress monitor. * @return the input stream to access the contents of the remote file. * @throws SystemMessageException if an error occurs. - * @since 3.0 + * @since org.eclipse.rse.services 3.0 */ public OutputStream getOutputStream(String remoteParent, String remoteFile, int options, IProgressMonitor monitor) throws SystemMessageException; /** * Indicates whether this file service supports code page conversion using - * the IFileServiceCodePageConverter mechanism. Certain extensions, such as - * property pages for encoding conversion can determine whether or not to + * the IFileServiceCodePageConverter mechanism. Certain extensions, such as + * property pages for encoding conversion can determine whether or not to * display or enable themselves based on result of this call. * * @return whether this service supports encoding conversion + * + * @since org.eclipse.rse.services 3.0 */ public boolean supportsEncodingConversion(); } diff --git a/rse/plugins/org.eclipse.rse.services/src/org/eclipse/rse/services/search/IHostSearchConstants.java b/rse/plugins/org.eclipse.rse.services/src/org/eclipse/rse/services/search/IHostSearchConstants.java index c4829bc8276..d8a83d8c674 100644 --- a/rse/plugins/org.eclipse.rse.services/src/org/eclipse/rse/services/search/IHostSearchConstants.java +++ b/rse/plugins/org.eclipse.rse.services/src/org/eclipse/rse/services/search/IHostSearchConstants.java @@ -11,7 +11,7 @@ * Emily Bruner, Mazen Faraj, Adrian Storisteanu, Li Ding, and Kent Hawley. * * Contributors: - * {Name} (company) - description of contribution. + * Martin Oberhuber (Wind River) - [cleanup] Add API "since" tags ********************************************************************************/ package org.eclipse.rse.services.search; @@ -30,6 +30,8 @@ public interface IHostSearchConstants { /** * Status indicating configuration has been canceled, 2. + * + * @since 3.0 this was renamed from CANCELLED in earlier versions */ public static final int CANCELED = 2;