diff --git a/src/main/java/com/ibm/as400/access/IFSCachedAttributes.java b/src/main/java/com/ibm/as400/access/IFSCachedAttributes.java
index a42a4934..3b37a1f5 100644
--- a/src/main/java/com/ibm/as400/access/IFSCachedAttributes.java
+++ b/src/main/java/com/ibm/as400/access/IFSCachedAttributes.java
@@ -16,193 +16,179 @@
/**
-Store cached attributes.
-**/
-class IFSCachedAttributes implements Serializable
+ * Store cached attributes.
+ **/
+class IFSCachedAttributes implements Serializable
{
- static final long serialVersionUID = 4L;
-
- static final int FA_READONLY = 0x01;
- static final int FA_HIDDEN = 0x02;
-
- long accessDate_;
- long creationDate_;
- int fixedAttributes_;
- boolean isDirectory_;
- boolean isFile_;
- boolean isSymbolicLink_;
- long modificationDate_;
- String name_;
- int objectType_;
- String parent_; // path of directory
- long size_; // @A1c
- byte[] restartID_; // @C3a
-
- //@AC7 Start
- int fileDataCCSID_;
- String ownerName_;
- int fileAsp_;
- int fileSystemType_;
- static final int UNINITIALIZED = -1;
- //@AC7 End
-
-/**
-Construct listCachedAttributes object from a list of attributes.
-**/
- IFSCachedAttributes(long accessDate, long creationDate, int fixedAttributes,
- long modificationDate, int objectType, long size,
- String name, String parent, boolean isDirectory, boolean isFile,
- byte[] restartID, boolean isSymbolicLink, int fileSystemType) // @A1c @C3c
- {
- accessDate_ = accessDate;
- creationDate_ = creationDate;
- fixedAttributes_ = fixedAttributes;
- isDirectory_ = isDirectory;
- isFile_ = isFile;
- modificationDate_ = modificationDate;
- name_ = name;
- objectType_ = objectType;
- parent_ = parent;
- size_ = size;
- restartID_ = restartID; // @C3a
- isSymbolicLink_ = isSymbolicLink;
+ static final long serialVersionUID = 4L;
+
+ static final int FA_READONLY = 0x01;
+ static final int FA_HIDDEN = 0x02;
+
+ long accessDate_;
+ long creationDate_;
+ int fixedAttributes_;
+ boolean isDirectory_;
+ boolean isFile_;
+ boolean isSymbolicLink_;
+ long modificationDate_;
+ String name_;
+ int objectType_;
+ String parent_; // path of directory
+ long size_;
+ byte[] restartID_;
+
+ int fileDataCCSID_;
+ String ownerName_;
+ String description_;
+ int fileAsp_;
+ int fileSystemType_;
- //@AC7 Start
- fileSystemType_ = fileSystemType;
- ownerName_ = null;
- fileAsp_ = UNINITIALIZED;
- fileDataCCSID_ = UNINITIALIZED;
- //@AC7 End
- }
-
-/**
-Return access date.
-**/
- long getAccessDate()
- {
- return accessDate_;
- }
-
-/**
-Return creation date.
-**/
- long getCreationDate()
- {
- return creationDate_;
- }
-
-/**
-Return fixed attributes.
-**/
- int getFixedAttributes()
- {
- return fixedAttributes_;
- }
-
-/**
-Return isDir_
-**/
- boolean getIsDirectory()
- {
- return isDirectory_;
- }
-
-/**
-Return isFile_
-**/
- boolean getIsFile()
- {
- return isFile_;
- }
-
-/**
-Return modification date.
-**/
- long getModificationDate()
- {
- return modificationDate_;
- }
-
-/**
-Return name.
-**/
- String getName()
- {
- return name_;
- }
-
-/**
-Return object type.
-**/
- int getObjectType()
- {
- return objectType_;
- }
-
-/**
-Return path of parent directory.
-**/
- String getParent()
- {
- return parent_;
- }
-
-// @C3a
-/**
-Return restart ID.
-**/
- byte[] getRestartID()
- {
- return restartID_;
- }
-
-/**
-Return size.
-**/
- long getSize() // @A1c
- {
- return size_;
- }
-
-/**
-Return isSymbolicLink_
-**/
- boolean isSymbolicLink()
- {
- return isSymbolicLink_;
- }
-
- //@AC7 Start
- /**
- * Return File system type
- */
- int getFileSystemType() {
- return fileSystemType_;
- }
-
- /**
- *
- * @return Owner name
- */
- String getOwnerName() {
- return ownerName_;
- }
-
- /**
- *
- * @return File ASP
- */
- int getFileAsp() {
- return fileAsp_;
- }
-
- /**
- *
- * @return File data CCSID
- */
- int getFileDataCcsid() {
- return fileDataCCSID_;
- }
-//@AC7 End
-
+ static final int UNINITIALIZED = -1;
+
+ /**
+ * Construct listCachedAttributes object from a list of attributes.
+ **/
+ IFSCachedAttributes(long accessDate, long creationDate, int fixedAttributes, long modificationDate, int objectType,
+ long size, String name, String parent, boolean isDirectory, boolean isFile, byte[] restartID,
+ boolean isSymbolicLink, int fileSystemType)
+ {
+ accessDate_ = accessDate;
+ creationDate_ = creationDate;
+ fixedAttributes_ = fixedAttributes;
+ isDirectory_ = isDirectory;
+ isFile_ = isFile;
+ modificationDate_ = modificationDate;
+ name_ = name;
+ objectType_ = objectType;
+ parent_ = parent;
+ size_ = size;
+ restartID_ = restartID;
+ isSymbolicLink_ = isSymbolicLink;
+
+ fileSystemType_ = fileSystemType;
+
+ // These fields are special and we do not get from cache
+ description_ = null;
+ ownerName_ = null;
+ fileAsp_ = UNINITIALIZED;
+ fileDataCCSID_ = UNINITIALIZED;
+ }
+
+ /**
+ * Return access date.
+ **/
+ long getAccessDate() {
+ return accessDate_;
+ }
+
+ /**
+ * Return creation date.
+ **/
+ long getCreationDate() {
+ return creationDate_;
+ }
+
+ /**
+ * Return fixed attributes.
+ **/
+ int getFixedAttributes() {
+ return fixedAttributes_;
+ }
+
+ /**
+ * Return isDir_
+ **/
+ boolean getIsDirectory() {
+ return isDirectory_;
+ }
+
+ /**
+ * Return isFile_
+ **/
+ boolean getIsFile() {
+ return isFile_;
+ }
+
+ /**
+ * Return modification date.
+ **/
+ long getModificationDate() {
+ return modificationDate_;
+ }
+
+ /**
+ * Return name.
+ **/
+ String getName() {
+ return name_;
+ }
+
+ /**
+ * Return object type.
+ **/
+ int getObjectType() {
+ return objectType_;
+ }
+
+ /**
+ * Return path of parent directory.
+ **/
+ String getParent() {
+ return parent_;
+ }
+
+ /**
+ * Return restart ID.
+ **/
+ byte[] getRestartID() {
+ return restartID_;
+ }
+
+ /**
+ * Return size.
+ **/
+ long getSize()
+ {
+ return size_;
+ }
+
+ /**
+ * Return isSymbolicLink_
+ **/
+ boolean isSymbolicLink() {
+ return isSymbolicLink_;
+ }
+
+ /**
+ * Return File system type
+ */
+ int getFileSystemType() {
+ return fileSystemType_;
+ }
+
+ /**
+ * @return Owner name
+ */
+ String getOwnerName() {
+ return ownerName_;
+ }
+
+ /**
+ * @return File ASP
+ */
+ int getFileAsp() {
+ return fileAsp_;
+ }
+
+ /**
+ * @return File data CCSID
+ */
+ int getFileDataCcsid() {
+ return fileDataCCSID_;
+ }
+
+ public String getDescription() {
+ return description_;
+ }
}
diff --git a/src/main/java/com/ibm/as400/access/IFSFile.java b/src/main/java/com/ibm/as400/access/IFSFile.java
index 1b4124ee..135571f4 100644
--- a/src/main/java/com/ibm/as400/access/IFSFile.java
+++ b/src/main/java/com/ibm/as400/access/IFSFile.java
@@ -125,8 +125,7 @@
* @see IFSFileWriter
**/
-public class IFSFile
- implements Serializable, Comparable // @B9c
+public class IFSFile implements Serializable, Comparable
{
static final long serialVersionUID = 4L;
@@ -183,542 +182,408 @@
Using POSIX semantics, all files are listed that match the pattern and do no
transient private VetoableChangeSupport vetos_;
transient private Vector fileListeners_;
transient private IFSFileImpl impl_;
- transient private ServiceProgramCall servicePgm_;
private AS400 system_;
private String path_ = ""; // Note: This is never allowed to be null.
- private Permission permission_; //@A6A
+
+ private Permission permission_;
private String subType_;
- //@D2C Changed IFSListAttrsRep to IFSCachedAttributes
- transient private IFSCachedAttributes cachedAttributes_;//@A7A
- private boolean isDirectory_; //@A7A
- private boolean isFile_; //@A7A
+ transient private IFSCachedAttributes cachedAttributes_;
+ private boolean isDirectory_;
+ private boolean isFile_;
private boolean isSymbolicLink_;
private int patternMatching_; // type of pattern matching to use when listing files
private boolean sortLists_; // whether file-lists are returned from the File Server in sorted order
- // Several pieces of member data set by listFiles0() for IFSFileEnumeration @D5A
- // to indicate the number of objects returned from the IFS File Server and @D5A
- // also the restartName and restartID info of the last object returned. @D5A
- private int listFiles0LastNumObjsReturned_; //@D5A
- private String listFiles0LastRestartName_=null; //@D5A
- private byte[] listFiles0LastRestartID_; //@D5A
+ // Several pieces of member data set by listFiles0() for IFSFileEnumeration
+ // to indicate the number of objects returned from the IFS File Server and
+ // also the restartName and restartID info of the last object returned.
+ private int listFiles0LastNumObjsReturned_;
+ private String listFiles0LastRestartName_=null;
+ private byte[] listFiles0LastRestartID_;
/**
- Constructs an IFSFile object.
- It creates a default IFSFile instance.
+ * Constructs an IFSFile object. It creates a default IFSFile instance.
**/
- public IFSFile()
- {
- initializeTransient();
+ public IFSFile() {
+ initializeTransient();
}
-
/**
- Constructs an IFSFile object.
- It creates an IFSFile instance that represents the integrated file system
- object on system that has a path name of directory, that is
- followed by the separator character and name.
- @param system The system that contains the file.
- @param directory The directory.
- @param name The file name.
+ * Constructs an IFSFile object. It creates an IFSFile instance that represents the integrated file system object on
+ * system that has a path name of directory, that is followed by the separator character and
+ * name.
+ *
+ * @param system The system that contains the file.
+ * @param directory The directory.
+ * @param name The file name.
**/
- public IFSFile(AS400 system,
- IFSFile directory,
- String name)
+ public IFSFile(AS400 system, IFSFile directory, String name)
{
- // Validate arguments.
- if (system == null)
- throw new NullPointerException("system");
- if (directory == null)
- throw new NullPointerException("directory");
- else if (name == null)
- throw new NullPointerException("name");
+ if (system == null)
+ throw new NullPointerException("system");
+ if (directory == null)
+ throw new NullPointerException("directory");
+ else if (name == null)
+ throw new NullPointerException("name");
- initializeTransient();
-
- // Build the file's full path name.
- path_ = directory.getAbsolutePath();
- if (path_.charAt(path_.length() - 1) != separatorChar)
- {
- // Append a separator character.
- path_ += separator;
- }
- path_ += name;
-
- system_ = system;
-
- // @A6A Add permission property.
- permission_ = null;
+ initialize(system, directory.getAbsolutePath(), name);
}
-
/**
- Constructs an IFSFile object.
- It creates an IFSFile instance that represents the integrated file system
- object on system that has a path name of path.
- @param system The system that contains the file.
- @param path The absolute path name of the file.
+ * Constructs an IFSFile object. It creates an IFSFile instance that represents the integrated file system object on
+ * system that has a path name of path.
+ *
+ * @param system The system that contains the file.
+ * @param path The absolute path name of the file.
**/
- public IFSFile(AS400 system,
- String path)
+ public IFSFile(AS400 system, String path)
{
- // Validate arguments.
- if (system == null)
- throw new NullPointerException("system");
- else if (path == null)
- throw new NullPointerException("path");
-
- initializeTransient();
+ if (system == null)
+ throw new NullPointerException("system");
+ else if (path == null)
+ throw new NullPointerException("path");
- // If the specified path doesn't start with the separator character,
- // add one. All paths are absolute for IFS.
- if (path.length() == 0 || path.charAt(0) != separatorChar)
- {
- path_ = separator + path;
- }
- else
- {
- path_ = path;
- }
-
- system_ = system;
+ initialize(system, null, path);
}
-
/**
- Constructs an IFSFile object.
- It creates an IFSFile instance that represents the integrated file system
- object on system that has a
- path name is of directory, followed by the separator character
- and name.
- @param system The system that contains the file.
- @param directory The directory path name.
- @param name The file name.
+ * Constructs an IFSFile object. It creates an IFSFile instance that represents the integrated file system object on
+ * system that has a path name is of directory, followed by the separator character and name.
+ *
+ * @param system The system that contains the file.
+ * @param directory The directory path name.
+ * @param name The file name.
+ **/
+ public IFSFile(AS400 system, String directory, String name)
+ {
+ if (system == null)
+ throw new NullPointerException("system");
+ else if (directory == null)
+ throw new NullPointerException("directory");
+ else if (name == null)
+ throw new NullPointerException("name");
+
+ initialize(system, directory, name);
+ }
+
+ /**
+ * Creates a new IFSFile instance from a parent abstract pathname and a child pathname string.
+ *
+ * The directory argument cannot be null. The constructed IFSFile instance uses the following settings taken + * from directory: + *
- * The directory argument cannot be null. The constructed - * IFSFile instance uses the following settings taken from - * directory: - *
Object
's path.
- * If the other object is not an IFSFile or java.io.File,
- * this method throws a ClassCastException
, since
- * IFSFile is comparable only to IFSFile and java.io.File.
- *
- * Note:
The comparison is case sensitive.
- *
- * @param obj The Object
to be compared.
- *
- * @return 0
if this IFSFile path equals the argument's path;
- * a value less than 0
if this IFSFile path is less than the argument's
- * path; and a value greater than 0
if this IFSFile path is greater
- * than the argument's path.
- *
-**/
+ /**
+ * Compares the path of this IFSFile with an Object
's path. If the other object is not an IFSFile or
+ * java.io.File, this method throws a ClassCastException
, since IFSFile is comparable only to IFSFile and
+ * java.io.File.
+ *
+ *
+ * Note:
+ * The comparison is case sensitive.
+ *
+ * @param obj The Object
to be compared.
+ *
+ * @return 0
if this IFSFile path equals the argument's path; a value less than 0
if this
+ * IFSFile path is less than the argument's path; and a value greater than 0
if this IFSFile path
+ * is greater than the argument's path.
+ *
+ **/
+ @Override
public int compareTo(Object obj)
{
- if (obj instanceof IFSFile)
- return getPath().compareTo(((IFSFile)obj).getPath());
- else
+ if (obj instanceof IFSFile)
+ return getPath().compareTo(((IFSFile)obj).getPath());
+
return getPath().compareTo(((java.io.File)obj).getPath());
}
-
/**
- * Copies this file or directory to the specified file or directory
- * on the system.
- * If the destination file already exists, it is overwritten.
- * If this IFSFile represents a directory:
+ * Copies this file or directory to the specified file or directory on the system. If the destination file already
+ * exists, it is overwritten. If this IFSFile represents a directory:
*
- This method is not supported for files in the following file systems: -
+ * This method is not supported for files in the following file systems: + *
- When the IFSFile object represents the root of the QSYS file system, this method may return a partial list of the contents of the directory.
-
- @return An array of objects in the directory. This list does not
- include the current directory or the parent directory. If this
- object does not represent a directory, or this object represents
- an empty directory, an empty object array is returned.
-
Note: Due to a limitation in the File Server, at most 65,535 files will be listed.
- * @throws IOException If an error occurs while communicating with the system.
-
- @see #setPatternMatching(int)
- @exception ConnectionDroppedException If the connection is dropped unexpectedly.
- @exception ExtendedIOException If an error occurs while communicating with the system, or the directory is not accessible.
- @exception InterruptedIOException If this thread is interrupted.
- @exception ServerStartupException If the host server cannot be started.
- @exception UnknownHostException If the system cannot be located.
-
- **/
- public IFSFile[] listFiles()
- throws IOException
- {
- return listFiles((IFSFileFilter)null, "*");
- }
-
-
- //@A7A Added function to return an array of files in a directory.
- /**
- Lists the integrated file system objects in the directory represented by this object that satisfy filter. With the use of this method, attribute information is cached and will not be automatically refreshed from the system. This means that retrieving attribute information for files returned in the list is much faster than using the {@link #list(IFSFileFilter) list} method, but attribute information may become inconsistent with the system.
-
- When the IFSFile object represents the root of the QSYS file system, this method may return a partial list of the contents of the directory.
+ * Lists the integrated file system objects in the directory represented by this object that satisfy filter.
+ *
+ * @param filter A file object filter.
+ * @param pattern The pattern that all filenames must match. Acceptable characters are wildcards (*) and question
+ * marks (?).
+ * @return An array of object names in the directory that satisfy the filter and pattern. This list does not include
+ * the current directory or the parent directory. If this object does not represent a directory, null is
+ * returned. If this object represents an empty directory, or the filter or pattern does not match any files,
+ * an empty string array is returned. The IFSFile object passed to the filter object have cached file
+ * attribute information. Maintaining references to these IFSFile objects after the list operation increases
+ * the chances that their file attribute information will not be valid.
+ * Note: Due to a limitation in the File Server, at most 65,535 files will be listed.
+ * @throws IOException If an error occurs while communicating with the system.
+ *
+ * @see #listFiles(IFSFileFilter,String)
+ * @see #setPatternMatching(int)
+ * @exception ConnectionDroppedException If the connection is dropped unexpectedly.
+ * @exception ExtendedIOException If an error occurs while communicating with the system or the directory is
+ * not accessible.
+ * @exception InterruptedIOException If this thread is interrupted.
+ * @exception ServerStartupException If the host server cannot be started.
+ * @exception UnknownHostException If the system cannot be located.
+ *
+ **/
+ public String[] list(IFSFileFilter filter, String pattern) throws IOException
+ {
+ // Validate arguments. Note that we tolerate a null-valued 'filter'.
+ if (pattern == null)
+ throw new NullPointerException("pattern");
- @param filter A file object filter.
- @return An array of objects in the directory. This list does not
- include the current directory or the parent directory. If this
- object does not represent a directory, or this
- object represents an empty directory, an empty object array is returned.
-
Note: Due to a limitation in the File Server, at most 65,535 files will be listed.
- * @throws IOException If an error occurs while communicating with the system.
+ try {
+ return list0(filter, pattern);
+ }
+ catch (AS400SecurityException e) {
+ Trace.log(Trace.ERROR, SECURITY_EXCEPTION, e);
+ throw new ExtendedIOException(path_, ExtendedIOException.ACCESS_DENIED);
+ }
+ }
- @see #setPatternMatching(int)
- @exception ConnectionDroppedException If the connection is dropped unexpectedly.
- @exception ExtendedIOException If an error occurs while communicating with the system, or the directory is not accessible.
- @exception InterruptedIOException If this thread is interrupted.
- @exception ServerStartupException If the host server cannot be started.
- @exception UnknownHostException If the system cannot be located.
+ /**
+ * Lists the integrated file system objects in the directory represented by this object that match pattern.
+ *
+ * @param pattern The pattern that all filenames must match. Acceptable characters are wildcards (*) and question
+ * marks (?).
+ * @return An array of object names in the directory that match the pattern. This list does not include the current
+ * directory or the parent directory. If this object does not represent a directory, null is returned. If this
+ * object represents an empty directory, or the pattern does not match any files, an empty string array is
+ * returned.
+ * Note: Due to a limitation in the File Server, at most 65,535 files will be listed.
+ * @throws IOException If an error occurs while communicating with the system.
+ *
+ * @see #listFiles(String)
+ * @see #setPatternMatching(int)
+ * @exception ConnectionDroppedException If the connection is dropped unexpectedly.
+ * @exception ExtendedIOException If an error occurs while communicating with the system, or the directory is
+ * not accessible.
+ * @exception InterruptedIOException If this thread is interrupted.
+ * @exception ServerStartupException If the host server cannot be started.
+ * @exception UnknownHostException If the system cannot be located.
+ *
+ **/
+ public String[] list(String pattern) throws IOException
+ {
+ return list(null, pattern);
+ }
+ /**
+ * Lists the integrated file system objects in the directory represented by this object. With the use of this method,
+ * attribute information is cached and will not be automatically refreshed from the system. This means that retrieving
+ * attribute information for files returned in the list is much faster than using the {@link #list() list} method, but
+ * attribute information may become inconsistent with the system.
+ *
+ * When the IFSFile object represents the root of the QSYS file system, this method may return a partial list of the
+ * contents of the directory.
+ *
+ * @return An array of objects in the directory. This list does not include the current directory or the parent
+ * directory. If this object does not represent a directory, or this object represents an empty directory, an
+ * empty object array is returned.
+ * Note: Due to a limitation in the File Server, at most 65,535 files will be listed.
+ * @throws IOException If an error occurs while communicating with the system.
+ *
+ * @see #setPatternMatching(int)
+ * @exception ConnectionDroppedException If the connection is dropped unexpectedly.
+ * @exception ExtendedIOException If an error occurs while communicating with the system, or the directory is
+ * not accessible.
+ * @exception InterruptedIOException If this thread is interrupted.
+ * @exception ServerStartupException If the host server cannot be started.
+ * @exception UnknownHostException If the system cannot be located.
+ *
**/
- public IFSFile[] listFiles(IFSFileFilter filter)
- throws IOException
+ public IFSFile[] listFiles() throws IOException
{
- return listFiles(filter, "*");
+ return listFiles((IFSFileFilter)null, "*");
}
+ /**
+ * Lists the integrated file system objects in the directory represented by this object that satisfy filter.
+ * With the use of this method, attribute information is cached and will not be automatically refreshed from the
+ * system. This means that retrieving attribute information for files returned in the list is much faster than using
+ * the {@link #list(IFSFileFilter) list} method, but attribute information may become inconsistent with the system.
+ *
+ * When the IFSFile object represents the root of the QSYS file system, this method may return a partial list of the
+ * contents of the directory.
+ *
+ * @param filter A file object filter.
+ * @return An array of objects in the directory. This list does not include the current directory or the parent
+ * directory. If this object does not represent a directory, or this object represents an empty directory, an
+ * empty object array is returned.
+ * Note: Due to a limitation in the File Server, at most 65,535 files will be listed.
+ * @throws IOException If an error occurs while communicating with the system.
+ *
+ * @see #setPatternMatching(int)
+ * @exception ConnectionDroppedException If the connection is dropped unexpectedly.
+ * @exception ExtendedIOException If an error occurs while communicating with the system, or the directory is
+ * not accessible.
+ * @exception InterruptedIOException If this thread is interrupted.
+ * @exception ServerStartupException If the host server cannot be started.
+ * @exception UnknownHostException If the system cannot be located.
+ *
+ **/
+ public IFSFile[] listFiles(IFSFileFilter filter) throws IOException
+ {
+ return listFiles(filter, "*");
+ }
- //@A7A Added function to return an array of files in a directory.
/**
- Lists the integrated file system objects in the directory represented by this object that satisfy filter. With the use of this method, attribute information is cached and will not be automatically refreshed from the system. This means that retrieving attribute information for files returned in the list is much faster than using the {@link #list(IFSFileFilter,String) list} method, but attribute information may become inconsistent with the system.
-
- When pattern
is "*" and the IFSFile object represents the root of the QSYS file system, this method may return a partial list of the contents of the directory.
+ * Lists the integrated file system objects in the directory represented by this object that satisfy filter.
+ * With the use of this method, attribute information is cached and will not be automatically refreshed from the
+ * system. This means that retrieving attribute information for files returned in the list is much faster than using
+ * the {@link #list(IFSFileFilter,String) list} method, but attribute information may become inconsistent with the
+ * system.
+ *
+ * When pattern
is "*" and the IFSFile object represents the root of the QSYS file system, this method
+ * may return a partial list of the contents of the directory.
+ *
+ * @param filter A file object filter.
+ * @param pattern The pattern that all filenames must match. Acceptable characters are wildcards (*) and question
+ * marks (?).
+ * @return An array of object names in the directory that satisfy the filter and pattern. This list does not include
+ * the current directory or the parent directory. If this object does not represent a directory, this object
+ * represents an empty directory, or the filter or pattern does not match any files, an empty object array is
+ * returned. The IFSFile object passed to the filter object has cached file attribute information. Maintaining
+ * references to these IFSFile objects after the list operation increases the chances that their file
+ * attribute information will not be valid.
+ * Note: Due to a limitation in the File Server, at most 65,535 files will be listed.
+ * @throws IOException If an error occurs while communicating with the system.
+ *
+ * @see #setPatternMatching(int)
+ * @exception ConnectionDroppedException If the connection is dropped unexpectedly.
+ * @exception ExtendedIOException If an error occurs while communicating with the system, or the directory is
+ * not accessible.
+ * @exception InterruptedIOException If this thread is interrupted.
+ * @exception ServerStartupException If the host server cannot be started.
+ * @exception UnknownHostException If the system cannot be located.
+ *
+ **/
+ public IFSFile[] listFiles(IFSFileFilter filter, String pattern) throws IOException
+ {
+ // Validate arguments. Note that we tolerate a null-valued 'filter'.
+ if (pattern == null)
+ throw new NullPointerException("pattern");
+
+ try {
+ return listFiles0(filter, pattern, -1, (String) null, (byte[]) null, true);
+ }
+ catch (AS400SecurityException e) {
+ Trace.log(Trace.ERROR, SECURITY_EXCEPTION, e);
+ throw new ExtendedIOException(path_, ExtendedIOException.ACCESS_DENIED);
+ }
+ }
- @param filter A file object filter.
- @param pattern The pattern that all filenames must match. Acceptable
- characters are wildcards (*) and
- question marks (?).
- @return An array of object names in the directory that satisfy the filter
- and pattern. This list does not include the current directory or the parent
- directory. If this object does not represent a directory, this object represents an empty directory, or the filter or pattern does
- not match any files, an empty object array is returned. The IFSFile object
- passed to the filter object has cached file attribute information. Maintaining
- references to these IFSFile objects after the list operation increases the
- chances that their file attribute information will not be valid.
-
Note: Due to a limitation in the File Server, at most 65,535 files will be listed.
- * @throws IOException If an error occurs while communicating with the system.
-
- @see #setPatternMatching(int)
- @exception ConnectionDroppedException If the connection is dropped unexpectedly.
- @exception ExtendedIOException If an error occurs while communicating with the system, or the directory is not accessible.
- @exception InterruptedIOException If this thread is interrupted.
- @exception ServerStartupException If the host server cannot be started.
- @exception UnknownHostException If the system cannot be located.
-
- **/
- public IFSFile[] listFiles(IFSFileFilter filter, String pattern)
- throws IOException
- {
- // Validate arguments. Note that we tolerate a null-valued 'filter'.
- if (pattern == null)
- throw new NullPointerException("pattern");
-
- try
- {
- return listFiles0(filter, pattern, -1, (String)null, (byte[])null, true); // @D4C @C3C @D7C
- }
- catch (AS400SecurityException e)
- {
- Trace.log(Trace.ERROR, SECURITY_EXCEPTION, e);
- // return null; // @B6d
- throw new ExtendedIOException(path_, ExtendedIOException.ACCESS_DENIED); // @B6a
- }
- }
-
-
- //@A7A Added function to return an array of files in a directory.
- /**
- Lists the integrated file system objects in the directory represented by this object that match pattern. With the use of this method, attribute information is cached and will not be automatically refreshed from the system. This means that retrieving attribute information for files returned in the list is much faster than using the {@link #list(String) list} method, but attribute information may become inconsistent with the system.
-
- When pattern
is "*" and the IFSFile object represents the root of the QSYS file system, this method may return a partial list of the contents of the directory.
-
- @param pattern The pattern that all filenames must match. Acceptable characters
- are wildcards (*) and
- question marks (?).
- @return An array of object names in the directory that match the pattern. This
- list does not include the current directory or the parent directory. If this
- object does not represent a directory, this object
- represents an empty directory, or the pattern does not match any files,
- an empty object array is returned.
-
Note: Due to a limitation in the File Server, at most 65,535 files will be listed.
- * @throws IOException If an error occurs while communicating with the system.
-
- @see #setPatternMatching(int)
- @exception ConnectionDroppedException If the connection is dropped unexpectedly.
- @exception ExtendedIOException If an error occurs while communicating with the system, or the directory is not accessible.
- @exception InterruptedIOException If this thread is interrupted.
- @exception ServerStartupException If the host server cannot be started.
- @exception UnknownHostException If the system cannot be located.
-
- **/
- public IFSFile[] listFiles(String pattern)
- throws IOException
- {
- return listFiles((IFSFileFilter)null, pattern);
- }
-
- //@A7A Added function to return an array of files in a directory.
- //@C3c Moved logic to new private method.
/**
- Lists the integrated file system objects in the directory represented by this
- object that satisfy filter. With the use of this method, attribute
- information is cached and will not be automatically refreshed from the system.
- This means attribute information may become inconsistent with the system.
- @param filter A file object filter.
- @param pattern The pattern that all filenames must match.
- @param maxGetCount The maximum number of directory entries to retrieve.
- -1 indicates that all entries that match the search criteria should be retrieved.
- @param restartName The file name from which to start the search.
- If null, the search is started at the beginning of the list.
- Acceptable characters are wildcards (*) and question marks (?).
+ * Lists the integrated file system objects in the directory represented by this object that match pattern.
+ * With the use of this method, attribute information is cached and will not be automatically refreshed from the
+ * system. This means that retrieving attribute information for files returned in the list is much faster than using
+ * the {@link #list(String) list} method, but attribute information may become inconsistent with the system.
+ *
+ * When pattern
is "*" and the IFSFile object represents the root of the QSYS file system, this method
+ * may return a partial list of the contents of the directory.
+ *
+ * @param pattern The pattern that all filenames must match. Acceptable characters are wildcards (*) and question
+ * marks (?).
+ * @return An array of object names in the directory that match the pattern. This list does not include the current
+ * directory or the parent directory. If this object does not represent a directory, this object represents an
+ * empty directory, or the pattern does not match any files, an empty object array is returned.
+ * Note: Due to a limitation in the File Server, at most 65,535 files will be listed.
+ * @throws IOException If an error occurs while communicating with the system.
+ *
+ * @see #setPatternMatching(int)
+ * @exception ConnectionDroppedException If the connection is dropped unexpectedly.
+ * @exception ExtendedIOException If an error occurs while communicating with the system, or the directory is
+ * not accessible.
+ * @exception InterruptedIOException If this thread is interrupted.
+ * @exception ServerStartupException If the host server cannot be started.
+ * @exception UnknownHostException If the system cannot be located.
+ *
**/
- IFSFile[] listFiles0(IFSFileFilter filter, String pattern, int maxGetCount, String restartName) // @D4C
- throws IOException, AS400SecurityException
+ public IFSFile[] listFiles(String pattern) throws IOException
{
- return listFiles0(filter, pattern, maxGetCount, restartName, null, true); //@D7C
+ return listFiles((IFSFileFilter)null, pattern);
+ }
+
+ /*
+ * INTERNAL USE ONLY - SUBJECT TO CHANGE
+ *
+ * Lists the integrated file system objects in the directory represented by this object that satisfy filter.
+ * With the use of this method, attribute information is cached and will not be automatically refreshed from the
+ * system. This means attribute information may become inconsistent with the system.
+ *
+ * @param filter A file object filter.
+ * @param pattern The pattern that all filenames must match.
+ * @param maxGetCount The maximum number of directory entries to retrieve. -1 indicates that all entries that match
+ * the search criteria should be retrieved.
+ * @param restartName The file name from which to start the search. If null, the search is started at the beginning of
+ * the list. Acceptable characters are wildcards (*) and question marks (?).
+ */
+ IFSFile[] listFiles0(IFSFileFilter filter, String pattern, int maxGetCount, String restartName) throws IOException, AS400SecurityException
+ {
+ return listFiles0(filter, pattern, maxGetCount, restartName, null, true); //@D7C
}
- //@C3a Relocated logic from original listFiles0 method.
/**
Lists the integrated file system objects in the directory represented by this
object that satisfy filter. With the use of this method, attribute
@@ -2779,73 +2491,62 @@ IFSFile[] listFiles0(IFSFileFilter filter, String pattern, int maxGetCount, Stri
Acceptable characters are wildcards (*) and question marks (?).
**/
private IFSFile[] listFiles0(IFSFileFilter filter, String pattern, int maxGetCount, String restartName,
- byte[] restartID, boolean allowSortedRequests) // @D4C @D7C
- throws IOException, AS400SecurityException
- {
- // Do not specify both restartName and restartID. Specify one or the other.
-
- // Ensure that we are connected to the system.
- if (impl_ == null)
- chooseImpl();
-
- // Assume that the 'pattern' argument has been validated as non-null.
- // Note that we tolerate a null-valued 'filter' argument.
-
- // List the attributes of all files in this directory. Have to append
- // a file separator and * to the path so that all files in the
- // directory are returned.
- String directory = path_;
- if (directory.lastIndexOf(separatorChar) != directory.length() - 1)
- {
- // Add a separator character.
- directory = directory + separatorChar;
- }
- IFSCachedAttributes[] fileAttributeList; //@C3C
- if (restartName != null) {
- fileAttributeList = impl_.listDirectoryDetails(directory + pattern, directory, maxGetCount, restartName); //@D2C @D4C
- }
- else {
- fileAttributeList = impl_.listDirectoryDetails(directory + pattern, directory, maxGetCount, restartID,allowSortedRequests); //@C3a @D7C
- }
-
- // Add the name for each reply that matches the filter to the array
- // of files.
-
- if (Trace.isTraceOn()) Trace.log(Trace.DIAGNOSTIC, "IFSFile::listFile0(): returned ("+listFiles0LastNumObjsReturned_+") pre objects");
- if (fileAttributeList == null)
- {
- return new IFSFile[0];
- }
- else
- {
- // Save number of objects read, restartname, and restartID @D5A
- listFiles0LastNumObjsReturned_ = fileAttributeList.length; // @D5A
+ byte[] restartID, boolean allowSortedRequests) throws IOException, AS400SecurityException
+ {
+ // Do not specify both restartName and restartID. Specify one or the other.
+
+ // Ensure that we are connected to the system.
+ if (impl_ == null)
+ chooseImpl();
+
+ // Assume that the 'pattern' argument has been validated as non-null.
+ // Note that we tolerate a null-valued 'filter' argument.
+
+ // List the attributes of all files in this directory. Have to append
+ // a file separator and * to the path so that all files in the
+ // directory are returned.
+ String directory = path_;
+ if (directory.lastIndexOf(separatorChar) != directory.length() - 1)
+ directory = directory + separatorChar;
+
+ IFSCachedAttributes[] fileAttributeList;
+ if (restartName != null)
+ fileAttributeList = impl_.listDirectoryDetails(directory + pattern, directory, maxGetCount, restartName);
+ else
+ fileAttributeList = impl_.listDirectoryDetails(directory + pattern, directory, maxGetCount, restartID,allowSortedRequests);
+
+ // Add the name for each reply that matches the filter to the array of files.
+
+ if (Trace.isTraceOn()) Trace.log(Trace.DIAGNOSTIC, "IFSFile::listFile0(): returned ("+listFiles0LastNumObjsReturned_+") pre objects");
+
+ if (fileAttributeList == null)
+ return new IFSFile[0];
+
+ // Save number of objects read, restartname, and restartID
+ listFiles0LastNumObjsReturned_ = fileAttributeList.length;
IFSFile[] files = new IFSFile[fileAttributeList.length];
if (fileAttributeList.length > 0)
{
- IFSFile lastFile = new IFSFile(system_, fileAttributeList[fileAttributeList.length - 1]);
+ IFSFile lastFile = new IFSFile(system_, fileAttributeList[fileAttributeList.length - 1]);
- // Save the last restartName and restartID from the files @D5A
- // returned from the server (to be used for subsequent reads) @D5A
- listFiles0LastRestartName_ = lastFile.getName(); // @D5A
- listFiles0LastRestartID_ = lastFile.getRestartID(); // @D5A
+ // Save the last restartName and restartID from the files
+ // returned from the server (to be used for subsequent reads)
+ listFiles0LastRestartName_ = lastFile.getName();
+ listFiles0LastRestartID_ = lastFile.getRestartID();
}
int j = 0;
- for (int i = 0; i < fileAttributeList.length; i++) {
- IFSFile file = new IFSFile(system_, fileAttributeList[i]); //@D2C
- if (filter == null || filter.accept(file)) //@D2C
- {
- files[j++] = file; //@D2C
- }
+ for (int i = 0; i < fileAttributeList.length; i++)
+ {
+ IFSFile file = new IFSFile(system_, fileAttributeList[i]);
+ if (filter == null || filter.accept(file))
+ files[j++] = file;
}
if (j == 0)
- {
files = new IFSFile[0];
- }
else if (files.length != j)
{
// Copy the objects to an array of the exact size.
@@ -2855,707 +2556,674 @@ else if (files.length != j)
}
if (Trace.isTraceOn()) Trace.log(Trace.DIAGNOSTIC, "IFSFile::listFile0(): returned ("+files.length+") post objects");
+
return files;
- }
}
- //@C3a
- IFSFile[] listFiles0(IFSFileFilter filter, String pattern, int maxGetCount, byte[] restartID)
- throws IOException, AS400SecurityException
+ /*
+ * INTERNAL USE ONLY - SUBJECT TO CHANGE
+ */
+ IFSFile[] listFiles0(IFSFileFilter filter, String pattern, int maxGetCount, byte[] restartID) throws IOException, AS400SecurityException
{
// This method is only called by IFSEnumeration() which reads 128 objects at a time. @D7A
// The IFS file server does not allow "sort" and "restart ID" to be set in the same server request.
// Therefore, since the user may have previously called setSorted(), we need to inform
// IFSFileImplRemote to not allow sorting on this server request. The last parameter
// indicates "allowSortedRequests" and is set to "false"
- return listFiles0(filter, pattern, maxGetCount, null, restartID, false); //@D7C
+ return listFiles0(filter, pattern, maxGetCount, null, restartID, false);
}
- //@C3a
- IFSFile[] listFiles0(IFSFileFilter filter, String pattern)
- throws IOException, AS400SecurityException
+ /*
+ * INTERNAL USE ONLY - SUBJECT TO CHANGE
+ */
+ IFSFile[] listFiles0(IFSFileFilter filter, String pattern) throws IOException, AS400SecurityException
{
- return listFiles0(filter, pattern, -1, null, null, true); //@D7C
+ return listFiles0(filter, pattern, -1, null, null, true);
}
-
-//internal mkdir that returns return codes and throws exceptions.
- int mkdir0(String directory)
- throws IOException, AS400SecurityException
+ /*
+ * INTERNAL USE ONLY - SUBJECT TO CHANGE
+ *
+ * internal mkdirs that returns return codes and throws exceptions
+ */
+ int mkdir0(String directory) throws IOException, AS400SecurityException
{
- // Assume the argument has been validated as non-null.
+ // Assume the argument has been validated as non-null.
- if (impl_ == null)
- chooseImpl();
+ if (impl_ == null)
+ chooseImpl();
- return impl_.mkdir(directory);
+ return impl_.mkdir(directory);
}
- /** Creates an integrated file system directory whose path name is
- specified by this object.
-
- @return true if the directory was created; false otherwise.
- * @throws IOException If an error occurs while communicating with the system.
-
- @exception ConnectionDroppedException If the connection is dropped unexpectedly.
- @exception ExtendedIOException If an error occurs while communicating with the system.
- @exception InterruptedIOException If this thread is interrupted.
- @exception ServerStartupException If the host server cannot be started.
- @exception UnknownHostException If the system cannot be located.
-
+ /**
+ * Creates an integrated file system directory whose path name is specified by this object.
+ *
+ * @return true if the directory was created; false otherwise.
+ * @throws IOException If an error occurs while communicating with the system.
+ *
+ * @exception ConnectionDroppedException If the connection is dropped unexpectedly.
+ * @exception ExtendedIOException If an error occurs while communicating with the system.
+ * @exception InterruptedIOException If this thread is interrupted.
+ * @exception ServerStartupException If the host server cannot be started.
+ * @exception UnknownHostException If the system cannot be located.
+ *
**/
- public boolean mkdir()
- throws IOException
+ public boolean mkdir() throws IOException
{
- int returnCode = IFSReturnCodeRep.FILE_NOT_FOUND;
- try
- {
- returnCode = mkdir0(path_);
- }
- catch (AS400SecurityException e)
- {
- Trace.log(Trace.ERROR, SECURITY_EXCEPTION, e);
- throw new ExtendedIOException(path_, ExtendedIOException.ACCESS_DENIED);
- }
+ int returnCode = IFSReturnCodeRep.FILE_NOT_FOUND;
+ try {
+ returnCode = mkdir0(path_);
+ }
+ catch (AS400SecurityException e) {
+ Trace.log(Trace.ERROR, SECURITY_EXCEPTION, e);
+ throw new ExtendedIOException(path_, ExtendedIOException.ACCESS_DENIED);
+ }
- return (returnCode == IFSReturnCodeRep.SUCCESS);
+ return (returnCode == IFSReturnCodeRep.SUCCESS);
}
-//internal mkdirs that returns return codes and throws exceptions
- int mkdirs0()
- throws IOException, AS400SecurityException
+ /*
+ * INTERNAL USE ONLY - SUBJECT TO CHANGE
+ *
+ * internal mkdirs that returns return codes and throws exceptions
+ */
+ int mkdirs0() throws IOException, AS400SecurityException
{
- if (impl_ == null)
- chooseImpl();
+ if (impl_ == null)
+ chooseImpl();
- return impl_.mkdirs();
+ return impl_.mkdirs();
}
/**
- Creates an integrated file system directory whose path name is
- specified by this object. In addition, create all parent directories as necessary.
-
- @return true if the directory (or directories) were created; false otherwise.
- * @throws IOException If an error occurs while communicating with the system.
-
- @exception ConnectionDroppedException If the connection is dropped unexpectedly.
- @exception ExtendedIOException If an error occurs while communicating with the system.
- @exception InterruptedIOException If this thread is interrupted.
- @exception ServerStartupException If the host server cannot be started.
- @exception UnknownHostException If the system cannot be located.
-
- **/
- public boolean mkdirs()
- throws IOException
+ * Creates an integrated file system directory whose path name is specified by this object. In addition, create all
+ * parent directories as necessary.
+ *
+ * @return true if the directory (or directories) were created; false otherwise.
+ * @throws IOException If an error occurs while communicating with the system.
+ *
+ * @exception ConnectionDroppedException If the connection is dropped unexpectedly.
+ * @exception ExtendedIOException If an error occurs while communicating with the system.
+ * @exception InterruptedIOException If this thread is interrupted.
+ * @exception ServerStartupException If the host server cannot be started.
+ * @exception UnknownHostException If the system cannot be located.
+ *
+ **/
+ public boolean mkdirs() throws IOException
{
- int returnCode = IFSReturnCodeRep.FILE_NOT_FOUND;
- try
- {
- returnCode = mkdirs0();
- }
- catch (AS400SecurityException e)
- {
- Trace.log(Trace.ERROR, SECURITY_EXCEPTION, e);
- // returnCode = IFSReturnCodeRep.FILE_NOT_FOUND; //@A7D Unnecessary assignment.
- throw new ExtendedIOException(path_, ExtendedIOException.ACCESS_DENIED); // @B6a
- }
- return (returnCode == IFSReturnCodeRep.SUCCESS);
+ int returnCode = IFSReturnCodeRep.FILE_NOT_FOUND;
+ try {
+ returnCode = mkdirs0();
+ }
+ catch (AS400SecurityException e) {
+ Trace.log(Trace.ERROR, SECURITY_EXCEPTION, e);
+ throw new ExtendedIOException(path_, ExtendedIOException.ACCESS_DENIED);
+ }
+
+ return (returnCode == IFSReturnCodeRep.SUCCESS);
}
- /**
- Restores the state of this object from an object input stream.
- @param ois The stream of state information.
- @exception IOException
- @exception ClassNotFoundException
- **/
- private void readObject(java.io.ObjectInputStream ois)
- throws IOException, ClassNotFoundException
+ /*
+ * Restores the state of this object from an object input stream.
+ *
+ * @param ois The stream of state information.
+ * @exception IOException
+ * @exception ClassNotFoundException
+ */
+ private void readObject(java.io.ObjectInputStream ois) throws IOException, ClassNotFoundException
{
- // Restore the non-static and non-transient fields.
- ois.defaultReadObject();
+ // Restore the non-static and non-transient fields.
+ ois.defaultReadObject();
- // Initialize the transient fields.
- initializeTransient();
+ // Initialize the transient fields.
+ initializeTransient();
}
/**
- Removes a file listener so that it no longer receives file events from
- this IFSFile.
- @param listener The file listener.
+ * Removes a file listener so that it no longer receives file events from this IFSFile.
+ *
+ * @param listener The file listener.
**/
public void removeFileListener(FileListener listener)
{
- if (listener == null)
- throw new NullPointerException("listener");
+ if (listener == null)
+ throw new NullPointerException("listener");
fileListeners_.removeElement(listener);
}
/**
- Removes a property change listener.
- @param listener The property change listener to remove.
+ * Removes a property change listener.
+ *
+ * @param listener The property change listener to remove.
**/
public void removePropertyChangeListener(PropertyChangeListener listener)
{
- if (listener == null)
- throw new NullPointerException("listener");
+ if (listener == null)
+ throw new NullPointerException("listener");
- changes_.removePropertyChangeListener(listener);
+ changes_.removePropertyChangeListener(listener);
}
/**
- Removes a vetoable change listener.
- @param listener The vetoable change listener to remove.
+ * Removes a vetoable change listener.
+ *
+ * @param listener The vetoable change listener to remove.
**/
public void removeVetoableChangeListener(VetoableChangeListener listener)
{
- if (listener == null)
- throw new NullPointerException("listener");
+ if (listener == null)
+ throw new NullPointerException("listener");
+
+ vetos_.removeVetoableChangeListener(listener);
+ }
+
+ /*
+ * INTERNAL USE ONLY - SUBJECT TO CHANGE
+ *
+ * internal renameTo that returns an error code
+ */
+ int renameTo0(IFSFile file) throws IOException, PropertyVetoException, AS400SecurityException
+ {
+ // Assume the argument has been validated as non-null.
+
+ if (impl_ == null)
+ chooseImpl();
+
+ String targetPath = file.getAbsolutePath();
+ if (targetPath.length() == 0)
+ throw new ExtendedIllegalStateException("path", ExtendedIllegalStateException.PROPERTY_NOT_SET);
+
+ // Fire a vetoable change event.
+ vetos_.fireVetoableChange("path", path_, file.getAbsolutePath());
+
+ // Rename the file.
+ int rc = impl_.renameTo(file.getImpl());
+
+ if (rc == IFSReturnCodeRep.SUCCESS)
+ {
+ String oldPath = path_;
+ path_ = file.getAbsolutePath();
+
+ // Fire the property change event having null as the name to
+ // indicate that the path, parent, etc. have changed.
+ changes_.firePropertyChange("path", oldPath, path_);
+
+ // Clear any cached attributes.
+ cachedAttributes_ = null;
+ }
+
+ return rc;
+ }
+
+ /**
+ * Renames the integrated file system object specified by this object to have the path name of file. Wildcards
+ * are not permitted in this file name.
+ *
+ * @param file The new file name.
+ *
+ * @return true if successful; false otherwise.
+ * @throws IOException If an error occurs while communicating with the system.
+ *
+ * @exception ConnectionDroppedException If the connection is dropped unexpectedly.
+ * @exception ExtendedIOException If an error occurs while communicating with the system.
+ * @exception InterruptedIOException If this thread is interrupted.
+ * @exception PropertyVetoException If the change is vetoed.
+ * @exception ServerStartupException If the host server cannot be started.
+ * @exception UnknownHostException If the system cannot be located.
+ *
+ **/
+ public boolean renameTo(IFSFile file) throws IOException, PropertyVetoException
+ {
+ // Validate the argument.
+ if (file == null)
+ throw new NullPointerException("file");
+
+ int returnCode = IFSReturnCodeRep.FILE_NOT_FOUND;
+ try {
+ returnCode = renameTo0(file);
+ }
+ catch (AS400SecurityException e) {
+ Trace.log(Trace.ERROR, SECURITY_EXCEPTION, e);
+ throw new ExtendedIOException(path_, ExtendedIOException.ACCESS_DENIED);
+ }
+
+ return (returnCode == IFSReturnCodeRep.SUCCESS);
+ }
+
+ /*
+ * INTERNAL USE ONLY - SUBJECT TO CHANGE
+ *
+ * Sets the access mode of the integrated file system object. This method is supported for IBM i V5R1 and higher. For
+ * older releases, it does nothing and returns false.
+ *
+ * @param accessType The type of access to set on the file. Valid values are:
- AS400 as400 = new AS400("mySystem"); - IFSFileInputStream is1 = new IFSFileInputStream(as400, "/Dir/File"); - IFSFileInputStream is2 = new IFSFileInputStream(is1.getFD()); --Reading in one object advances the current file position of all objects that share the same descriptor. -@see IFSFileInputStream#getFD -@see IFSFileOutputStream#getFD -@see IFSRandomAccessFile#getFD -**/ -public final class IFSFileDescriptor - implements java.io.Serializable + * Represents an integrated file system file descriptor. Instances of the file descriptor class serve as an opaque + * handle to the underlying structure representing an open file or an open socket. Applications should not create their + * own file descriptors.
+ * AS400 as400 = new AS400("mySystem"); + * IFSFileInputStream is1 = new IFSFileInputStream(as400, "/Dir/File"); + * IFSFileInputStream is2 = new IFSFileInputStream(is1.getFD()); + *+ * + * Reading in one object advances the current file position of all objects that share the same descriptor. + * + * @see IFSFileInputStream#getFD + * @see IFSFileOutputStream#getFD + * @see IFSRandomAccessFile#getFD + **/ +public final class IFSFileDescriptor implements java.io.Serializable { static final long serialVersionUID = 4L; - private transient long fileOffset_; - private transient Object parent_; // The object that instantiated - // this IFSDescriptor. - private String path_ = ""; - private int shareOption_; - private AS400 system_; - private boolean closed_ = false; + private transient long fileOffset_; + private transient Object parent_; // The object that instantiated + // this IFSDescriptor. + private String path_ = ""; + private int shareOption_; + private AS400 system_; + private boolean closed_ = false; - private transient Object fileOffsetLock_ = new Object(); - // Semaphore for synchronizing access to fileOffset_. + // Semaphore for synchronizing access to fileOffset_. + private transient Object fileOffsetLock_ = new Object(); - private transient IFSFileDescriptorImpl impl_; + private transient IFSFileDescriptorImpl impl_; + /** + * Constructs an IFSFileDescriptor object. + **/ + public IFSFileDescriptor() + { + } -/** -Constructs an IFSFileDescriptor object. -**/ - public IFSFileDescriptor() - { - } - - IFSFileDescriptor(AS400 system, - String path, - int shareOption, - Object parent) - { - system_ = system; - path_ = path; - shareOption_ = shareOption; - parent_ = parent; - } + IFSFileDescriptor(AS400 system, String path, int shareOption, Object parent) + { + system_ = system; + path_ = path; + shareOption_ = shareOption; + parent_ = parent; + } - IFSFileDescriptor(int shareOption, - Object parent) - { - shareOption_ = shareOption; - parent_ = parent; - } + IFSFileDescriptor(int shareOption, Object parent) + { + shareOption_ = shareOption; + parent_ = parent; + } /** Chooses the appropriate implementation. **/ void chooseImpl () { - if (impl_ == null) - { - impl_ = (IFSFileDescriptorImpl) system_.loadImpl2 - ("com.ibm.as400.access.IFSFileDescriptorImplRemote", - "com.ibm.as400.access.IFSFileDescriptorImplProxy"); + if (impl_ != null) + return; + + impl_ = (IFSFileDescriptorImpl) system_.loadImpl2("com.ibm.as400.access.IFSFileDescriptorImplRemote", + "com.ibm.as400.access.IFSFileDescriptorImplProxy"); // Get the "impl" object for the parent, so we can pass it to the impl_. Object parentImpl = null; if (parent_ != null) { - // Get the impl object for the parent. - //@A3D Class clazz = parent_.getClass (); - //@A3D Method method = clazz.getDeclaredMethod ("getImpl", new Class[] {}); - //@A3D parentImpl = method.invoke (parent_, new Object[] {}); - //@A3A - String className = parent_.getClass().getName(); - if (parent_ instanceof IFSFileInputStream) { - parentImpl = ((IFSFileInputStream)parent_).getImpl(); - } - else if (parent_ instanceof IFSFileOutputStream) { - parentImpl = ((IFSFileOutputStream)parent_).getImpl(); - } - else if (parent_ instanceof IFSTextFileInputStream) { - parentImpl = ((IFSTextFileInputStream)parent_).getImpl(); - } - else if (parent_ instanceof IFSTextFileOutputStream) { - parentImpl = ((IFSTextFileOutputStream)parent_).getImpl(); - } - else if (parent_ instanceof IFSRandomAccessFile) { - parentImpl = ((IFSRandomAccessFile)parent_).getImpl(); - } - else { - Trace.log(Trace.ERROR, "IFSFileDescriptor has invalid parent: " + className); - throw new InternalErrorException (InternalErrorException.UNEXPECTED_EXCEPTION); - } + // Get the impl object for the parent. + String className = parent_.getClass().getName(); + if (parent_ instanceof IFSFileInputStream) + parentImpl = ((IFSFileInputStream) parent_).getImpl(); + else if (parent_ instanceof IFSFileOutputStream) + parentImpl = ((IFSFileOutputStream) parent_).getImpl(); + else if (parent_ instanceof IFSTextFileInputStream) + parentImpl = ((IFSTextFileInputStream) parent_).getImpl(); + else if (parent_ instanceof IFSTextFileOutputStream) + parentImpl = ((IFSTextFileOutputStream) parent_).getImpl(); + else if (parent_ instanceof IFSRandomAccessFile) + parentImpl = ((IFSRandomAccessFile) parent_).getImpl(); + else + { + Trace.log(Trace.ERROR, "IFSFileDescriptor has invalid parent: " + className); + throw new InternalErrorException(InternalErrorException.UNEXPECTED_EXCEPTION); + } } - impl_.initialize(fileOffset_, parentImpl, - path_, shareOption_, system_.getImpl()); - } + impl_.initialize(fileOffset_, parentImpl, path_, shareOption_, system_.getImpl()); } void close() { - if (impl_ != null) impl_.close(); - closed_ = true; + if (impl_ != null) + impl_.close(); + closed_ = true; } - /** - Fires events to indicate file has been closed. - This static method is provided as a utility for use by other classes. + * Fires events to indicate file has been closed. This static method is provided as a utility for use by other + * classes. **/ static void fireClosedEvents(Object source, Vector fileListeners) { - FileEvent event = new FileEvent(source, FileEvent.FILE_CLOSED); - synchronized(fileListeners) - { - Enumeration e = fileListeners.elements(); - while (e.hasMoreElements()) + FileEvent event = new FileEvent(source, FileEvent.FILE_CLOSED); + synchronized (fileListeners) { - FileListener listener = (FileListener)e.nextElement(); - listener.fileClosed(event); + Enumeration e = fileListeners.elements(); + while (e.hasMoreElements()) + { + FileListener listener = (FileListener) e.nextElement(); + listener.fileClosed(event); + } } - } } - /** - Fires events to indicate file has been modified. - This static method is provided as a utility for use by other classes. + * Fires events to indicate file has been modified. This static method is provided as a utility for use by other + * classes. **/ static void fireModifiedEvents(Object source, Vector fileListeners) { - FileEvent event = new FileEvent(source, FileEvent.FILE_MODIFIED); - synchronized(fileListeners) - { - Enumeration e = fileListeners.elements(); - while (e.hasMoreElements()) + FileEvent event = new FileEvent(source, FileEvent.FILE_MODIFIED); + synchronized (fileListeners) { - FileListener listener = (FileListener)e.nextElement(); - listener.fileModified(event); + Enumeration e = fileListeners.elements(); + while (e.hasMoreElements()) + { + FileListener listener = (FileListener) e.nextElement(); + listener.fileModified(event); + } } - } } /** - Fires events to indicate file has been opened. - This static method is provided as a utility for use by other classes. + * Fires events to indicate file has been opened. This static method is provided as a utility for use by other + * classes. **/ static void fireOpenedEvents(Object source, Vector fileListeners) { - FileEvent event = new FileEvent(source, FileEvent.FILE_OPENED); - synchronized(fileListeners) - { - Enumeration e = fileListeners.elements(); - while (e.hasMoreElements()) + FileEvent event = new FileEvent(source, FileEvent.FILE_OPENED); + synchronized (fileListeners) { - FileListener listener = (FileListener)e.nextElement(); - listener.fileOpened(event); + Enumeration e = fileListeners.elements(); + while (e.hasMoreElements()) + { + FileListener listener = (FileListener) e.nextElement(); + listener.fileOpened(event); + } } - } } @@ -201,171 +188,149 @@ static void fireOpenedEvents(Object source, Vector fileListeners) IFSFileDescriptorImpl getImpl() { - if (impl_ == null) chooseImpl(); - return impl_; + if (impl_ == null) + chooseImpl(); + return impl_; } /** - Returns the file's "data CCSID" setting. + * Returns the file's "data CCSID" setting. **/ - int getCCSID() - throws IOException + int getCCSID() throws IOException { - if (impl_ == null) chooseImpl(); - return impl_.getCCSID(); + if (impl_ == null) + chooseImpl(); + return impl_.getCCSID(); } long getFileOffset() { - if (impl_ == null) - { - return fileOffset_; - } - else + if (impl_ == null) + return fileOffset_; + return impl_.getFileOffset(); } - String getPath() - { - return path_; // this field is never reset by the ImplRemote + String getPath() { + return path_; // this field is never reset by the ImplRemote } - int getShareOption() - { - return shareOption_; // this field is never reset by the ImplRemote + int getShareOption() { + return shareOption_; // this field is never reset by the ImplRemote } - AS400 getSystem() - { - return system_; // this field is never reset by the ImplRemote + AS400 getSystem() { + return system_; // this field is never reset by the ImplRemote } void incrementFileOffset(long fileOffsetIncrement) { - if (impl_ == null) - { - synchronized(fileOffsetLock_) + if (impl_ == null) { - fileOffset_ += fileOffsetIncrement; - } - } - else - impl_.incrementFileOffset(fileOffsetIncrement); + synchronized (fileOffsetLock_) { + fileOffset_ += fileOffsetIncrement; + } + } + else + impl_.incrementFileOffset(fileOffsetIncrement); } - boolean isClosed() - { - return closed_; + boolean isClosed() { + return closed_; } boolean isOpen() { - if (impl_ == null) - return false; - else + if (impl_ == null) + return false; + return impl_.isOpen(); } /** - Restores the state of this object from an object input stream. - @param ois The stream of state information. - @exception IOException If an error occurs while communicating with the server. - @exception ClassNotFoundException + * Restores the state of this object from an object input stream. + * + * @param ois The stream of state information. + * @exception IOException If an error occurs while communicating with the server. + * @exception ClassNotFoundException **/ - private void readObject(java.io.ObjectInputStream ois) - throws IOException, ClassNotFoundException + private void readObject(java.io.ObjectInputStream ois) throws IOException, ClassNotFoundException { - // Restore the non-static and non-transient fields. - ois.defaultReadObject(); - - // Initialize the transient fields. - fileOffset_ = 0; - parent_ = null; - fileOffsetLock_ = new Object(); - impl_ = null; + // Restore the non-static and non-transient fields. + ois.defaultReadObject(); + + // Initialize the transient fields. + fileOffset_ = 0; + parent_ = null; + fileOffsetLock_ = new Object(); + impl_ = null; } - void setFileOffset(long fileOffset) //@A1C - Change parameter from int to long + void setFileOffset(long fileOffset) // @A1C - Change parameter from int to long { - if (impl_ == null) - { - synchronized(fileOffsetLock_) + if (impl_ == null) { - fileOffset_ = fileOffset; - } - } - else - impl_.setFileOffset(fileOffset); + synchronized (fileOffsetLock_) { + fileOffset_ = fileOffset; + } + } + else + impl_.setFileOffset(fileOffset); } void setPath(String path) { - if (impl_ == null) - path_ = path; - else - throw new ExtendedIllegalStateException("path", - ExtendedIllegalStateException.PROPERTY_NOT_CHANGED); + if (impl_ == null) + path_ = path; + else + throw new ExtendedIllegalStateException("path", ExtendedIllegalStateException.PROPERTY_NOT_CHANGED); } void setShareOption(int shareOption) { - if (impl_ == null) - shareOption_ = shareOption; - else - throw new ExtendedIllegalStateException("shareOption", - ExtendedIllegalStateException.PROPERTY_NOT_CHANGED); + if (impl_ == null) + shareOption_ = shareOption; + else + throw new ExtendedIllegalStateException("shareOption", ExtendedIllegalStateException.PROPERTY_NOT_CHANGED); } void setSystem(AS400 system) { - if (impl_ == null) - system_ = system; - else - throw new ExtendedIllegalStateException("system", - ExtendedIllegalStateException.PROPERTY_NOT_CHANGED); + if (impl_ == null) + system_ = system; + else + throw new ExtendedIllegalStateException("system", ExtendedIllegalStateException.PROPERTY_NOT_CHANGED); } /** - Force the system buffers to synchronize with the underlying device. - * @throws IOException If an error occurs while communicating with the system. - **/ // $A1 + * Force the system buffers to synchronize with the underlying device. + * + * @throws IOException If an error occurs while communicating with the system. + **/ public void sync() throws IOException { - if (impl_ == null) - { - if (parent_ == null) + if (impl_ == null) { - Trace.log(Trace.ERROR, "Parent is null, nothing to synchronize."); - // Tolerate the error. - } - else if (parent_ instanceof IFSRandomAccessFile) - { - ((IFSRandomAccessFile)parent_).flush(); - } - else if (parent_ instanceof IFSFileOutputStream) - { - ((IFSFileOutputStream)parent_).flush(); - } + if (parent_ == null) + Trace.log(Trace.ERROR, "Parent is null, nothing to synchronize."); + else if (parent_ instanceof IFSRandomAccessFile) + ((IFSRandomAccessFile) parent_).flush(); + else if (parent_ instanceof IFSFileOutputStream) + ((IFSFileOutputStream) parent_).flush(); + else + Trace.log(Trace.ERROR, "Parent does not have a flush() method: " + parent_.getClass().getName()); + } else - { - Trace.log(Trace.ERROR, "Parent does not have a flush() method: " + - parent_.getClass().getName()); - // Tolerate the error. - } - } - else - { - impl_.sync(); - } + impl_.sync(); } -/** -Determines if this file descriptor represents an open file. -@return true if this file descriptor represents a valid, open file; false otherwise. -**/ - public boolean valid() - { - return isOpen(); + /** + * Determines if this file descriptor represents an open file. + * + * @return true if this file descriptor represents a valid, open file; false otherwise. + **/ + public boolean valid() { + return isOpen(); } } diff --git a/src/main/java/com/ibm/as400/access/IFSFileDescriptorImplProxy.java b/src/main/java/com/ibm/as400/access/IFSFileDescriptorImplProxy.java index 88e9a15f..44b118e0 100644 --- a/src/main/java/com/ibm/as400/access/IFSFileDescriptorImplProxy.java +++ b/src/main/java/com/ibm/as400/access/IFSFileDescriptorImplProxy.java @@ -16,125 +16,107 @@ import java.io.IOException; import java.lang.reflect.InvocationTargetException; - /** - Provides a local proxy implementation for the IFSFileDescriptor class. + * Provides a local proxy implementation for the IFSFileDescriptor class. **/ -class IFSFileDescriptorImplProxy -extends AbstractProxyImpl -implements IFSFileDescriptorImpl +class IFSFileDescriptorImplProxy extends AbstractProxyImpl implements IFSFileDescriptorImpl { - private static final String copyright = "Copyright (C) 1997-2000 International Business Machines Corporation and others."; - - - - IFSFileDescriptorImplProxy () - { - super ("IFSFileDescriptor"); - } - - public void close() - { - try { - connection_.callMethod (pxId_, "close"); - } - catch (InvocationTargetException e) { - throw ProxyClientConnection.rethrow (e); - } - } - - public int getCCSID() throws IOException - { - try { - return connection_.callMethod (pxId_, "getCCSID") - .getReturnValueInt(); - } - catch (InvocationTargetException e) { - throw ProxyClientConnection.rethrow (e); - } - } - - public long getFileOffset() - { - try { - return connection_.callMethod (pxId_, "getFileOffset") - .getReturnValueLong(); - } - catch (InvocationTargetException e) { - throw ProxyClientConnection.rethrow (e); - } - } - - public void incrementFileOffset(long fileOffsetIncrement) - { - try { - connection_.callMethod (pxId_, "incrementFileOffset", - new Class[] { Long.TYPE }, - new Object[] { Long.valueOf(fileOffsetIncrement)}); - } - catch (InvocationTargetException e) { - throw ProxyClientConnection.rethrow (e); + private static final String copyright = "Copyright (C) 1997-2000 International Business Machines Corporation and others."; + + IFSFileDescriptorImplProxy() { + super("IFSFileDescriptor"); + } + + @Override + public void close() + { + try { + connection_.callMethod(pxId_, "close"); + } + catch (InvocationTargetException e) { + throw ProxyClientConnection.rethrow(e); + } + } + + @Override + public int getCCSID() throws IOException + { + try { + return connection_.callMethod(pxId_, "getCCSID").getReturnValueInt(); + } + catch (InvocationTargetException e) { + throw ProxyClientConnection.rethrow(e); + } + } + + @Override + public long getFileOffset() + { + try { + return connection_.callMethod(pxId_, "getFileOffset").getReturnValueLong(); + } + catch (InvocationTargetException e) { + throw ProxyClientConnection.rethrow(e); + } + } + + @Override + public void incrementFileOffset(long fileOffsetIncrement) + { + try { + connection_.callMethod(pxId_, "incrementFileOffset", new Class[] { Long.TYPE }, new Object[] { Long.valueOf(fileOffsetIncrement) }); + } + catch (InvocationTargetException e) { + throw ProxyClientConnection.rethrow(e); + } + } + + @Override + public void initialize(long fileOffset, Object parentImpl, String path, int shareOption, AS400Impl system) + { + try { + connection_.callMethod(pxId_, "initialize", + new Class[] { Long.TYPE, Object.class, String.class, Integer.TYPE, AS400Impl.class }, + new Object[] { Long.valueOf(fileOffset), parentImpl, path, Integer.valueOf(shareOption), system }); + } + catch (InvocationTargetException e) { + throw ProxyClientConnection.rethrow(e); + } + } + + @Override + public boolean isOpen() + { + try { + return connection_.callMethod(pxId_, "isOpen").getReturnValueBoolean(); + } + catch (InvocationTargetException e) { + throw ProxyClientConnection.rethrow(e); + } + } + + @Override + public void setFileOffset(long fileOffset) + { + try { + connection_.callMethod(pxId_, "setFileOffset", new Class[] { Long.TYPE }, new Object[] { Long.valueOf(fileOffset) }); + } + catch (InvocationTargetException e) { + throw ProxyClientConnection.rethrow(e); + } + } + + @Override + public void sync() throws IOException + { + try { + connection_.callMethod(pxId_, "sync"); + } + catch (InvocationTargetException e) { + throw ProxyClientConnection.rethrow1(e); + } } - } - - public void initialize(long fileOffset, Object parentImpl, String path, int shareOption, - AS400Impl system) - { - try { - connection_.callMethod (pxId_, "initialize", - new Class[] { Long.TYPE, - Object.class, - String.class, - Integer.TYPE, - AS400Impl.class - }, - new Object[] { Long.valueOf(fileOffset), - parentImpl, - path, - Integer.valueOf(shareOption), - system - }); - } - catch (InvocationTargetException e) { - throw ProxyClientConnection.rethrow (e); - } - } - - public boolean isOpen() - { - try { - return connection_.callMethod (pxId_, "isOpen") - .getReturnValueBoolean(); - } - catch (InvocationTargetException e) { - throw ProxyClientConnection.rethrow (e); - } - } - - public void setFileOffset(long fileOffset) - { - try { - connection_.callMethod (pxId_, "setFileOffset", - new Class[] { Long.TYPE }, - new Object[] { Long.valueOf(fileOffset)}); - } - catch (InvocationTargetException e) { - throw ProxyClientConnection.rethrow (e); - } - } - - public void sync() throws IOException - { - try { - connection_.callMethod (pxId_, "sync"); - } - catch (InvocationTargetException e) { - throw ProxyClientConnection.rethrow1 (e); - } - } - } - diff --git a/src/main/java/com/ibm/as400/access/IFSFileDescriptorImplRemote.java b/src/main/java/com/ibm/as400/access/IFSFileDescriptorImplRemote.java index e56797de..3528e732 100644 --- a/src/main/java/com/ibm/as400/access/IFSFileDescriptorImplRemote.java +++ b/src/main/java/com/ibm/as400/access/IFSFileDescriptorImplRemote.java @@ -35,414 +35,366 @@ /** Provides a full remote implementation for the IFSFileDescriptor class. **/ -class IFSFileDescriptorImplRemote -implements IFSFileDescriptorImpl +class IFSFileDescriptorImplRemote implements IFSFileDescriptorImpl { - private static final int UNINITIALIZED = -1; // @B8a - private static final int MAX_BYTES_PER_READ = 16000000; // limit of file server - - // Note: We allow direct access to some of these fields, for performance. @B2C - ConverterImplRemote converter_; - private int fileHandle_ = UNINITIALIZED; // @B8c - int preferredServerCCSID_; - private int fileDataCCSID_ = UNINITIALIZED; - private int fileAsp_ = UNINITIALIZED;//@V4A - private int fileSystemType_ = UNINITIALIZED;//@V4A - int serverDatastreamLevel_; // @B3A - int requestedDatastreamLevel_; // @B6a - private long fileOffset_; - boolean isOpen_; - boolean isOpenAllowed_ = true; - private Object parent_; // The object that instantiated this IFSDescriptor. - String path_ = ""; - byte[] pathnameBytes_; - transient Object serverLock_ = new Object(); - AS400Server server_; // Note: AS400Server is not serializable. - private int shareOption_; - AS400ImplRemote system_; - - private Object fileOffsetLock_ = new Object(); - // Semaphore for synchronizing access to fileOffset_. - - private int maxDataBlockSize_ = 1024; // @B2A - // Used by IFSFileOutputStreamImplRemote, IFSRandomAccessFileImplRemote. - - private boolean determinedSystemVRM_ = false; // @B3A @B4C - private int systemVRM_; // @B3A @B4C - transient int errorRC_; // error return code from most recent request - int patternMatching_ = IFSFile.PATTERN_DEFAULT; // pattern-matching semantics + private static final int UNINITIALIZED = -1; + private static final int MAX_BYTES_PER_READ = 16000000; // limit of file server + + // Note: We allow direct access to some of these fields, for performance. + ConverterImplRemote converter_; + private int fileHandle_ = UNINITIALIZED; + int preferredServerCCSID_; + private int fileDataCCSID_ = UNINITIALIZED; + private int fileAsp_ = UNINITIALIZED; + private int fileSystemType_ = UNINITIALIZED; + int serverDatastreamLevel_; + int requestedDatastreamLevel_; + private long fileOffset_; + boolean isOpen_; + boolean isOpenAllowed_ = true; + private Object parent_; // The object that instantiated this IFSDescriptor. + String path_ = ""; + byte[] pathnameBytes_; + transient Object serverLock_ = new Object(); + AS400Server server_; // Note: AS400Server is not serializable. + private int shareOption_; + AS400ImplRemote system_; + private Object fileOffsetLock_ = new Object(); // Semaphore for synchronizing access to fileOffset_. + private int maxDataBlockSize_ = 1024; + private Integer systemVRM_; + transient int errorRC_; // error return code from most recent request + int patternMatching_ = IFSFile.PATTERN_DEFAULT; // pattern-matching semantics - // Used for debugging only. This should always be false for production. - // When this is false, all debug code will theoretically compile out. - private static final boolean DEBUG = false; // @B3A + // Used for debugging only. This should always be false for production. + private static final boolean DEBUG = false; - //@AC7 Start - String fileOwnerName_ = null; - boolean isDirectory_ = false; - //@AC7 End + String fileOwnerName_ = null; - // Static initialization code. - static - { - // Add all byte stream reply data streams of interest to the - // AS400 server's reply data stream hash table. - AS400Server.addReplyStream(new IFSCloseRep(), AS400.FILE); - AS400Server.addReplyStream(new IFSExchangeAttrRep(), AS400.FILE); - AS400Server.addReplyStream(new IFSLockBytesRep(), AS400.FILE); - AS400Server.addReplyStream(new IFSReturnCodeRep(), AS400.FILE); - AS400Server.addReplyStream(new IFSWriteRep(), AS400.FILE); - AS400Server.addReplyStream(new IFSReadRep(), AS400.FILE); - } + static + { + // Add all byte stream reply data streams of interest to the + // AS400 server's reply data stream hash table. + AS400Server.addReplyStream(new IFSCloseRep(), AS400.FILE); + AS400Server.addReplyStream(new IFSExchangeAttrRep(), AS400.FILE); + AS400Server.addReplyStream(new IFSLockBytesRep(), AS400.FILE); + AS400Server.addReplyStream(new IFSReturnCodeRep(), AS400.FILE); + AS400Server.addReplyStream(new IFSWriteRep(), AS400.FILE); + AS400Server.addReplyStream(new IFSReadRep(), AS400.FILE); + } // Cast an IFSFileDescriptorImpl object into an IFSFileDescriptorImplRemote. // Used by various IFS*ImplRemote classes. static IFSFileDescriptorImplRemote castImplToImplRemote(IFSFileDescriptorImpl fd) { - try - { - return (IFSFileDescriptorImplRemote)fd; - } - catch (ClassCastException e) - { - Trace.log(Trace.ERROR, "Argument is not an instance of IFSFileDescriptorImplRemote", e); - throw new - InternalErrorException(InternalErrorException.UNEXPECTED_EXCEPTION); - } + try { + return (IFSFileDescriptorImplRemote)fd; + } + catch (ClassCastException e) + { + Trace.log(Trace.ERROR, "Argument is not an instance of IFSFileDescriptorImplRemote", e); + throw new InternalErrorException(InternalErrorException.UNEXPECTED_EXCEPTION); + } } - // @B8m - Moved this method here from IFSFileImplRemote. - // Determine if the directory entry can be accessed in the specified - // manner. + // Determine if the directory entry can be accessed in the specified manner. // Returns the returnCode that was set (as a side effect) by createFileHandle(). - int checkAccess(int access, int openOption) // @D1C @B8c - throws IOException, AS400SecurityException + int checkAccess(int access, int openOption) throws IOException, AS400SecurityException { - int fileHandle = UNINITIALIZED; - try { - fileHandle = createFileHandle(access, openOption); - } - finally { - if (fileHandle != UNINITIALIZED) close(fileHandle); // we don't need this handle anymore - } - return errorRC_; + int fileHandle = UNINITIALIZED; + try { + fileHandle = createFileHandle(access, openOption); + } finally { + if (fileHandle != UNINITIALIZED) + close(fileHandle); // we don't need this handle anymore + } + + return errorRC_; } - + @Override public void close() { - try { - close0(); - } - catch (IOException e) { - Trace.log(Trace.ERROR, "Error while closing file " + path_, e); - } + try { + close0(); + } + catch (IOException e) { + Trace.log(Trace.ERROR, "Error while closing file " + path_, e); + } } - - public void close0() throws IOException + public void close0() throws IOException { - isOpen_ = false; - close(fileHandle_); - fileHandle_ = UNINITIALIZED; + isOpen_ = false; + close(fileHandle_); + fileHandle_ = UNINITIALIZED; } void close(int fileHandle) throws IOException { - if (fileHandle == UNINITIALIZED) return; // @B8c + if (fileHandle == UNINITIALIZED) + return; - // Close the file. Send a close request to the server. - ClientAccessDataStream ds = null; - IFSCloseReq req = new IFSCloseReq(fileHandle); - try - { - ds = (ClientAccessDataStream) server_.sendAndReceive(req); - } - catch(ConnectionDroppedException e) - { - Trace.log(Trace.ERROR, "Byte stream connection lost during close", e); - connectionDropped(e); - } - catch(InterruptedException e) - { - Trace.log(Trace.ERROR, "Interrupted", e); - InterruptedIOException throwException = new InterruptedIOException(e.getMessage()); - throwException.initCause(e); - throw throwException; - } + // Close the file. Send a close request to the server. + ClientAccessDataStream ds = null; + IFSCloseReq req = new IFSCloseReq(fileHandle); + try { + ds = (ClientAccessDataStream) server_.sendAndReceive(req); + } + catch (ConnectionDroppedException e) { + Trace.log(Trace.ERROR, "Byte stream connection lost during close", e); + connectionDropped(e); + } + catch (InterruptedException e) { + Trace.log(Trace.ERROR, "Interrupted", e); + InterruptedIOException throwException = new InterruptedIOException(e.getMessage()); + throwException.initCause(e); + throw throwException; + } - // Validate the reply. - if (ds instanceof IFSCloseRep) - { - int rc = ((IFSCloseRep) ds).getReturnCode(); - if (rc != 0) + // Validate the reply. + if (ds instanceof IFSCloseRep) { - Trace.log(Trace.ERROR, "IFSCloseRep return code", rc); - throw new ExtendedIOException(path_, rc); + int rc = ((IFSCloseRep) ds).getReturnCode(); + if (rc != 0) { + Trace.log(Trace.ERROR, "IFSCloseRep return code", rc); + throw new ExtendedIOException(path_, rc); + } } - } - else if (ds instanceof IFSReturnCodeRep) - { - int rc = ((IFSReturnCodeRep) ds).getReturnCode(); - if (rc != IFSReturnCodeRep.SUCCESS) + else if (ds instanceof IFSReturnCodeRep) + { + int rc = ((IFSReturnCodeRep) ds).getReturnCode(); + if (rc != IFSReturnCodeRep.SUCCESS) { + Trace.log(Trace.ERROR, "IFSReturnCodeRep return code", descriptionForReturnCode(rc)); + throw new ExtendedIOException(path_, rc); + } + } + else { - Trace.log(Trace.ERROR, "IFSReturnCodeRep return code", descriptionForReturnCode(rc)); - throw new ExtendedIOException(path_, rc); + Trace.log(Trace.ERROR, "Unknown reply data stream", ds.data_); + throw new InternalErrorException(Integer.toHexString(ds.getReqRepID()), InternalErrorException.DATA_STREAM_UNKNOWN); } - } - else - { - Trace.log(Trace.ERROR, "Unknown reply data stream", ds.data_); - throw new - InternalErrorException(Integer.toHexString(ds.getReqRepID()), - InternalErrorException.DATA_STREAM_UNKNOWN); - } } - /** Establishes communications with the server. - - @exception AS400SecurityException If a security or authority error occurs. - @exception IOException If an error occurs while communicating with the server. **/ - void connect() // @B2A - code relocated from IFSFileOutputStreamImplRemote,etc. - throws IOException, AS400SecurityException + void connect() throws IOException, AS400SecurityException { - // Connect to the byte stream server if not already connected. - if (server_ == null) - { - // Ensure that the system has been set. + if (server_ != null) + return; + if (system_ == null) - { - throw new ExtendedIllegalStateException("system", - ExtendedIllegalStateException.PROPERTY_NOT_SET); - } + throw new ExtendedIllegalStateException("system", ExtendedIllegalStateException.PROPERTY_NOT_SET); try { - server_ = system_.getConnection(AS400.FILE, false /*forceNewConnection*/, false /*skip signon server */ ); + server_ = system_.getConnection(AS400.FILE, false /* forceNewConnection */, false /* skip signon server */ ); } - catch(AS400SecurityException e) - { - Trace.log(Trace.ERROR, "Access to byte stream server on '" + - system_.getSystemName() + "' denied.", e); - throw e; + catch (AS400SecurityException e) { + Trace.log(Trace.ERROR, "Access to byte stream server on '" + system_.getSystemName() + "' denied.", e); + throw e; } - // Exchange attributes with the server. exchangeServerAttributes(); - } } /** Disconnects from the byte stream server. - @exception ConnectionDroppedException If the connection is dropped unexpectedly. **/ - void connectionDropped(ConnectionDroppedException e) // @B2A - code relocated from IFSFileOutputStreamImplRemote,etc. - throws ConnectionDroppedException + void connectionDropped(ConnectionDroppedException e) throws ConnectionDroppedException { - if (server_ != null) - { - system_.disconnectServer(server_); - server_ = null; - try { close(); } catch (Exception exc) {} // Note: Not relevant for IFSFileImplRemote. - } - Trace.log(Trace.ERROR, "Byte stream connection lost."); - throw e; + if (server_ != null) + { + system_.disconnectServer(server_); + server_ = null; + try { + close(); + } + catch (Exception exc) { } // Note: Not relevant for IFSFileImplRemote. + } + + Trace.log(Trace.ERROR, "Byte stream connection lost."); + throw e; } /** * Copies a file or directory to another file or directory. **/ - boolean copyTo(String destinationPath, boolean replace) - throws AS400SecurityException, IOException + boolean copyTo(String destinationPath, boolean replace) throws AS400SecurityException, IOException { - ClientAccessDataStream ds = null; - IFSCopyReq req = new IFSCopyReq(path_, destinationPath, replace); - try - { - ds = (ClientAccessDataStream) server_.sendAndReceive(req); - } - catch(ConnectionDroppedException e) - { - Trace.log(Trace.ERROR, "Byte stream connection lost during copy", e); - connectionDropped(e); - } - catch(InterruptedException e) - { - Trace.log(Trace.ERROR, "Interrupted", e); - InterruptedIOException throwException = new InterruptedIOException(e.getMessage()); - throwException.initCause(e); - throw throwException; - } - if (ds instanceof IFSReturnCodeRep) - { - int rc = ((IFSReturnCodeRep) ds).getReturnCode(); - if (rc != IFSReturnCodeRep.SUCCESS) + ClientAccessDataStream ds = null; + IFSCopyReq req = new IFSCopyReq(path_, destinationPath, replace); + + try { + ds = (ClientAccessDataStream) server_.sendAndReceive(req); + } + catch(ConnectionDroppedException e) { - String path = (rc == IFSReturnCodeRep.DUPLICATE_DIR_ENTRY_NAME ? destinationPath : path_); - throwSecurityExceptionIfAccessDenied(path,rc); // check for "access denied" - Trace.log(Trace.ERROR, "IFSReturnCodeRep return code", descriptionForReturnCode(rc)); - throw new ExtendedIOException(path, rc); + Trace.log(Trace.ERROR, "Byte stream connection lost during copy", e); + connectionDropped(e); } - return true; - } - else - { + catch(InterruptedException e) + { + Trace.log(Trace.ERROR, "Interrupted", e); + InterruptedIOException throwException = new InterruptedIOException(e.getMessage()); + throwException.initCause(e); + throw throwException; + } + + if (ds instanceof IFSReturnCodeRep) + { + int rc = ((IFSReturnCodeRep) ds).getReturnCode(); + if (rc != IFSReturnCodeRep.SUCCESS) + { + String path = (rc == IFSReturnCodeRep.DUPLICATE_DIR_ENTRY_NAME ? destinationPath : path_); + throwSecurityExceptionIfAccessDenied(path,rc); // check for "access denied" + Trace.log(Trace.ERROR, "IFSReturnCodeRep return code", descriptionForReturnCode(rc)); + throw new ExtendedIOException(path, rc); + } + + return true; + } + Trace.log(Trace.ERROR, "Unknown reply data stream", ds.data_); - throw new - InternalErrorException(Integer.toHexString(ds.getReqRepID()), - InternalErrorException.DATA_STREAM_UNKNOWN); - } + throw new InternalErrorException(Integer.toHexString(ds.getReqRepID()), InternalErrorException.DATA_STREAM_UNKNOWN); } - // Opens the file for 'read' access, and returns a file handle. - // If failure, sets errorRC_ and returns UNINITIALIZED. - private final int createFileHandle() - throws IOException, AS400SecurityException - { - return createFileHandle(IFSOpenReq.READ_ACCESS, IFSOpenReq.OPEN_OPTION_FAIL_OPEN); + private final int createFileHandle() throws IOException, AS400SecurityException { + return createFileHandle(IFSOpenReq.READ_ACCESS, IFSOpenReq.OPEN_OPTION_FAIL_OPEN); } // Opens the file with specified access and option, and returns a file handle. // If failure, sets errorRC_ and returns UNINITIALIZED. - int createFileHandle(int access, int openOption) // @D1C @B8c - throws IOException, AS400SecurityException + int createFileHandle(int access, int openOption) throws IOException, AS400SecurityException { - int returnCode = IFSReturnCodeRep.FILE_NOT_FOUND; - int fileHandle = UNINITIALIZED; - errorRC_ = 0; + int returnCode = IFSReturnCodeRep.FILE_NOT_FOUND; + int fileHandle = UNINITIALIZED; + errorRC_ = 0; - // Try to open the file for the specified type of access. - try - { - // Process an open file request. - // For 3rd parm (file data CCSID), specify 0 since we don't care about CCSID. - IFSOpenReq req = new IFSOpenReq(getPathnameAsBytes(), preferredServerCCSID_, - 0, access, IFSOpenReq.DENY_NONE, - IFSOpenReq.NO_CONVERSION, - openOption, serverDatastreamLevel_); // @D1C - ClientAccessDataStream ds = (ClientAccessDataStream) server_.sendAndReceive(req); - if (ds instanceof IFSOpenRep) + // Try to open the file for the specified type of access. + try { - // The open was successful. Close the file if appropriate. - returnCode = IFSReturnCodeRep.SUCCESS; - fileHandle = ((IFSOpenRep) ds).getFileHandle(); // @B8a + // Process an open file request. + // For 3rd parm (file data CCSID), specify 0 since we don't care about CCSID. + IFSOpenReq req = new IFSOpenReq(getPathnameAsBytes(), preferredServerCCSID_, 0, access, + IFSOpenReq.DENY_NONE, IFSOpenReq.NO_CONVERSION, openOption, serverDatastreamLevel_); + ClientAccessDataStream ds = (ClientAccessDataStream) server_.sendAndReceive(req); + if (ds instanceof IFSOpenRep) + { + // The open was successful. Close the file if appropriate. + returnCode = IFSReturnCodeRep.SUCCESS; + fileHandle = ((IFSOpenRep) ds).getFileHandle(); // @B8a + } + else if (ds instanceof IFSReturnCodeRep) + { + returnCode = ((IFSReturnCodeRep) ds).getReturnCode(); + throwSecurityExceptionIfAccessDenied(path_,returnCode); // check for "access denied" + } + else + { + Trace.log(Trace.ERROR, "Unknown reply data stream", ds.data_); + throw new InternalErrorException(Integer.toHexString(ds.getReqRepID()), InternalErrorException.DATA_STREAM_UNKNOWN); + } } - else if (ds instanceof IFSReturnCodeRep) + catch(ConnectionDroppedException e) { - returnCode = ((IFSReturnCodeRep) ds).getReturnCode(); - throwSecurityExceptionIfAccessDenied(path_,returnCode); // check for "access denied" + Trace.log(Trace.ERROR, "Byte stream server connection lost", e); + connectionDropped(e); } - else + catch(InterruptedException e) { - // Unknown data stream. - Trace.log(Trace.ERROR, "Unknown reply data stream", ds.data_); - throw new - InternalErrorException(Integer.toHexString(ds.getReqRepID()), - InternalErrorException.DATA_STREAM_UNKNOWN); + Trace.log(Trace.ERROR, "Interrupted", e); + InterruptedIOException throwException = new InterruptedIOException(e.getMessage()); + throwException.initCause(e); + throw throwException; } - } - catch(ConnectionDroppedException e) - { - Trace.log(Trace.ERROR, "Byte stream server connection lost", e); - connectionDropped(e); - } - catch(InterruptedException e) - { - Trace.log(Trace.ERROR, "Interrupted", e); - InterruptedIOException throwException = new InterruptedIOException(e.getMessage()); - throwException.initCause(e); - throw throwException; - } - if (returnCode != IFSReturnCodeRep.SUCCESS) - { - if (Trace.isTraceOn() && Trace.isTraceDiagnosticOn()) + if (returnCode != IFSReturnCodeRep.SUCCESS) { - Trace.log(Trace.DIAGNOSTIC, "Unable to open file " + path_ + ": " + - "IFSReturnCodeRep return code", descriptionForReturnCode(returnCode)); + if (Trace.isTraceOn() && Trace.isTraceDiagnosticOn()) + { + Trace.log(Trace.DIAGNOSTIC, "Unable to open file " + path_ + ": " + + "IFSReturnCodeRep return code", descriptionForReturnCode(returnCode)); + } + + errorRC_ = returnCode; + return UNINITIALIZED; } - errorRC_ = returnCode; - return UNINITIALIZED; - } - return fileHandle; + return fileHandle; } - /** - Exchanges server attributes. - @exception IOException If an error occurs while communicating with the server. - **/ - void exchangeServerAttributes() // @B2A - code relocated from IFSFileOutputStreamImplRemote,etc. - throws IOException, AS400SecurityException + void exchangeServerAttributes() throws IOException, AS400SecurityException { synchronized (serverLock_) { DataStream ds = server_.getExchangeAttrReply(); IFSExchangeAttrRep rep = null; - try { rep = (IFSExchangeAttrRep)ds; } + try { + rep = (IFSExchangeAttrRep)ds; + } catch (ClassCastException e) { - if (ds instanceof IFSReturnCodeRep) - { - int rc = ((IFSReturnCodeRep) ds).getReturnCode(); - throwSecurityExceptionIfAccessDenied(path_,rc); // check for "access denied" - Trace.log(Trace.ERROR, "IFSReturnCodeRep return code", descriptionForReturnCode(rc)); - throw new ExtendedIOException(path_, rc); - } - else { - String className = ( ds == null ? "null" : ds.getClass().getName()); - Trace.log(Trace.ERROR, "Unexpected reply from Exchange Server Attributes: " + className); - throw new InternalErrorException(InternalErrorException.DATA_STREAM_UNKNOWN); - } + if (ds instanceof IFSReturnCodeRep) + { + int rc = ((IFSReturnCodeRep) ds).getReturnCode(); + throwSecurityExceptionIfAccessDenied(path_,rc); // check for "access denied" + Trace.log(Trace.ERROR, "IFSReturnCodeRep return code", descriptionForReturnCode(rc)); + throw new ExtendedIOException(path_, rc); + } + else + { + String className = ( ds == null ? "null" : ds.getClass().getName()); + Trace.log(Trace.ERROR, "Unexpected reply from Exchange Server Attributes: " + className); + throw new InternalErrorException(InternalErrorException.DATA_STREAM_UNKNOWN); + } } // Note: For releases after V5R4, we ask for Datastream Level 16; // for V5R3 thru V5R4, we ask for Datastream Level 8; // for V4R5 thru V5R2, we ask for Datastream Level 2; - // for earlier systems, we ask for Datastream Level 0. // @B6c + // for earlier systems, we ask for Datastream Level 0. if (getSystemVRM() >= 0x00060100) requestedDatastreamLevel_ = 16; else if (getSystemVRM() >= 0x00050300) requestedDatastreamLevel_ = 8; - else if (getSystemVRM() >= 0x00040500) // @B3A @B4C + else if (getSystemVRM() >= 0x00040500) requestedDatastreamLevel_ = 2; else requestedDatastreamLevel_ = 0; + if (rep == null) { ds = null; + try { - int[] preferredCcsids; // @A2A - // Datastream level 8 was introduced in release V5R3. - if (getSystemVRM() >= 0x00050300) - { // System is post-V5R2. - preferredCcsids = new int[] {0x04b0,0x34b0,0xf200}; // UTF-16, new or old Unicode. - } - // Note: Pre-V4R5 systems hang when presented with multiple - // preferred CCSIDs in the exchange of attributes. @B3A @B4C - else if (getSystemVRM() >= 0x00040500) // @B3A @B4C - { // System is V4R5 or later. We can present a list of preferred CCSIDs. - preferredCcsids = new int[] {0x34b0,0xf200}; // New or old Unicode. - } - else - { // System is pre-V4R5. Exchange attr's the old way. - preferredCcsids = new int[] {0xf200}; // Old Unicode only. - } - - // Use GMT date/time, don't use posix style return codes, - // use PC pattern matching semantics, - // maximum data transfer size of 0xffffffff. - ds = server_.sendExchangeAttrRequest( //@B3A + int[] preferredCcsids; + + // Datastream level 8 was introduced in release V5R3. Present a list of preferred CCSIDs, if possible. + if (getSystemVRM() >= 0x00050300) + preferredCcsids = new int[] {0x04b0,0x34b0,0xf200}; // UTF-16, new or old Unicode. + else if (getSystemVRM() >= 0x00040500) + preferredCcsids = new int[] {0x34b0,0xf200}; // New or old Unicode. + else + { + // System is pre-V4R5. Exchange attr's the old way. + // Note: Pre-V4R5 systems hang when presented with multiple + // preferred CCSIDs in the exchange of attributes. + preferredCcsids = new int[] {0xf200}; // Old Unicode only. + } + + // Use GMT date/time, don't use posix style return codes, + // use PC pattern matching semantics, + // maximum data transfer size of 0xffffffff. + ds = server_.sendExchangeAttrRequest( new IFSExchangeAttrReq(true, false, IFSExchangeAttrReq.PC_PATTERN_MATCH, 0xffffffff, requestedDatastreamLevel_, - preferredCcsids)); // @A2C - rep = (IFSExchangeAttrRep)ds; + preferredCcsids)); + rep = (IFSExchangeAttrRep)ds; } catch(ConnectionDroppedException e) { @@ -467,18 +419,19 @@ else if (getSystemVRM() >= 0x00040500) // @B3A @B4C } catch(ClassCastException e) { - if (ds instanceof IFSReturnCodeRep) - { - int rc = ((IFSReturnCodeRep) ds).getReturnCode(); - throwSecurityExceptionIfAccessDenied(path_,rc); // check for "access denied" - Trace.log(Trace.ERROR, "IFSReturnCodeRep return code", descriptionForReturnCode(rc)); - throw new ExtendedIOException(path_, rc); - } - else { - String className = ( ds == null ? "null" : ds.getClass().getName()); - Trace.log(Trace.ERROR, "Unexpected reply from Exchange Server Attributes: " + className); - throw new InternalErrorException(InternalErrorException.DATA_STREAM_UNKNOWN); - } + if (ds instanceof IFSReturnCodeRep) + { + int rc = ((IFSReturnCodeRep) ds).getReturnCode(); + throwSecurityExceptionIfAccessDenied(path_,rc); // check for "access denied" + Trace.log(Trace.ERROR, "IFSReturnCodeRep return code", descriptionForReturnCode(rc)); + throw new ExtendedIOException(path_, rc); + } + else + { + String className = ( ds == null ? "null" : ds.getClass().getName()); + Trace.log(Trace.ERROR, "Unexpected reply from Exchange Server Attributes: " + className); + throw new InternalErrorException(InternalErrorException.DATA_STREAM_UNKNOWN); + } } } @@ -488,26 +441,24 @@ else if (getSystemVRM() >= 0x00040500) // @B3A @B4C maxDataBlockSize_ = ((IFSExchangeAttrRep) rep).getMaxDataBlockSize(); preferredServerCCSID_ = rep.getPreferredCCSID(); serverDatastreamLevel_ = rep.getDataStreamLevel(); - setConverter(ConverterImplRemote.getConverter(preferredServerCCSID_, - system_)); - if (DEBUG) { - System.out.println("DEBUG: IFSFileDescriptorImplRemote.exchangeServerAttributes(): " + - "preferredServerCCSID_ == " + preferredServerCCSID_); - int[] list = rep.getPreferredCCSIDs(); - for (int i=0; i
+ * This method is not supported for files in the following file systems: + *
- This method is not supported for files in the following file systems: -
- * The directory argument cannot be null. The constructed - * IFSJavaFile instance uses the following settings taken from - * directory: - *
+ * The directory argument cannot be null. The constructed IFSJavaFile instance uses the following settings taken + * from directory:
+ * The following examples demonstrate the use of this method: + * + *
+ * In this example, returnCode would be less than 0
because the path of file
is less than
+ * the path of file2
.
+ *
+ *
+ * IFSJavaFile file = new IFSJavaFile(new AS400("enterprise"), path); + * IFSJavaFile file2 = new IFSJavaFile(new AS400("enterprise"), path + "\\extra"); + *+ * + *
+ * int returnCode = file.compareTo(file2); + *
+ * In this example, returnCode would be greater than 0
because the path of file
is greater
+ * than the path of file2
.
+ *
+ *
+ * IFSJavaFile file = new IFSJavaFile(new AS400("enterprise"), path + "\\extra"); + * IFSJavaFile file2 = new IFSJavaFile(new AS400("enterprise"), path); + *+ * + *
+ * int returnCode = file.compareTo(file2); + *
+ * In this example, returnCode would be less than 0
because the path of file
is less than
+ * the path of file2
.
+ *
+ *
+ * IFSJavaFile file = new IFSJavaFile(new AS400("enterprise"), "\\QSYS.LIB\\herlib"); + * IFSJavaFile file2 = new IFSJavaFile(new AS400("enterprise"), "\\QSYS.LIB\\hislib"); + *+ * + *
+ * int returnCode = file.compareTo(file2); + *
+ * Note:
+ * The comparison is case sensitive.
+ *
+ * @param file The IFSJavaFile to be compared.
+ *
+ * @return 0
if this IFSJavaFile path equals file
's path; a value less than 0
+ * if this IFSJavaFile path is less than the file
's path; and a value greater than
+ * 0
if this IFSJavaFile path is greater than the file's
path.
+ *
+ * @since JDK1.2
+ **/
+ public int compareTo(IFSJavaFile file) {
+ return getPath().compareTo(file.getPath());
+ }
+
+ /**
+ * Compares the path of IFSJavaFile with a File
's path.
+ *
+ *
+ * Note:
+ * The comparison is case sensitive.
+ *
+ * @param file The File
to be compared.
+ *
+ * @return 0
if this IFSJavaFile path equals the argument's path; a value less than 0
if
+ * this IFSJavaFile path is less than the argument's path; and a value greater than 0
if this
+ * IFSJavaFile path is greater than the argument's path.
+ *
+ * @since JDK1.2
+ **/
+ @Override
+ public int compareTo(File file) {
+ return getPath().compareTo(file.getPath());
+ }
+
+ /**
+ * Compares the path of IFSJavaFile with a IFSFile
's path.
+ *
+ *
+ * Note:
+ * The comparison is case sensitive.
+ *
+ * @param file The IFSFile
to be compared.
+ *
+ * @return 0
if this IFSJavaFile path equals the argument's path; a value less than 0
if
+ * this IFSJavaFile path is less than the argument's path; and a value greater than 0
if this
+ * IFSJavaFile path is greater than the argument's path.
+ *
+ * @since JDK1.2
+ **/
+ public int compareTo(IFSFile file) {
+ return getPath().compareTo(file.getPath());
}
- }
-
-/**
- * Compares the paths of two IFSJavaFiles.
- *
- * The following examples demonstrate the use of this method: - * - *
- * In this example, returnCode would be less than 0
because the
- * path of file
is less than the path of file2
.
- *
- * IFSJavaFile file = new IFSJavaFile(new AS400("enterprise"), path); - * IFSJavaFile file2 = new IFSJavaFile(new AS400("enterprise"), path + "\\extra"); - *- * - *
- * int returnCode = file.compareTo(file2); - *
- * In this example, returnCode would be greater than 0
because the
- * path of file
is greater than the path of file2
.
- *
- * IFSJavaFile file = new IFSJavaFile(new AS400("enterprise"), path + "\\extra"); - * IFSJavaFile file2 = new IFSJavaFile(new AS400("enterprise"), path); - *- * - *
- * int returnCode = file.compareTo(file2); - *
- * In this example, returnCode would be less than 0
because the
- * path of file
is less than the path of file2
.
- *
- * IFSJavaFile file = new IFSJavaFile(new AS400("enterprise"), "\\QSYS.LIB\\herlib"); - * IFSJavaFile file2 = new IFSJavaFile(new AS400("enterprise"), "\\QSYS.LIB\\hislib"); - *- * - *
- * int returnCode = file.compareTo(file2); - *
Note:
The comparison is case sensitive.
- *
- * @param file The IFSJavaFile to be compared.
- *
- * @return 0
if this IFSJavaFile path equals file
's path;
- * a value less than 0
if this IFSJavaFile path is less than the file
's
- * path; and a value greater than 0
if this IFSJavaFile path is greater
- * than the file's
path.
- *
- * @since JDK1.2
-**/
- public int compareTo(IFSJavaFile file)
- {
- return getPath().compareTo(file.getPath());
- }
-
-// @A7a
-/**
- * Compares the path of IFSJavaFile with a File
's path.
- *
- *
Note:
The comparison is case sensitive.
- *
- * @param file The File
to be compared.
- *
- * @return 0
if this IFSJavaFile path equals the argument's path;
- * a value less than 0
if this IFSJavaFile path is less than the argument's
- * path; and a value greater than 0
if this IFSJavaFile path is greater
- * than the argument's path.
- *
- * @since JDK1.2
-**/
- public int compareTo(File file)
- {
- return getPath().compareTo(file.getPath());
- }
-
-// @A8a
-/**
- * Compares the path of IFSJavaFile with a IFSFile
's path.
- *
- *
Note:
The comparison is case sensitive.
- *
- * @param file The IFSFile
to be compared.
- *
- * @return 0
if this IFSJavaFile path equals the argument's path;
- * a value less than 0
if this IFSJavaFile path is less than the argument's
- * path; and a value greater than 0
if this IFSJavaFile path is greater
- * than the argument's path.
- *
- * @since JDK1.2
-**/
- public int compareTo(IFSFile file)
- {
- return getPath().compareTo(file.getPath());
- }
// Note: The JDK 6.0 compiler doesn't like the following method signature.
@@ -497,1663 +492,1458 @@ public int compareTo(IFSFile file)
// }
// }
-
- /**
- * Atomically create a new, empty file. The file is
- * created if and only if the file does not yet exist. The
- * check for existence and the file creation is a
- * single atomic operation.
- * @return true if the file is created, false otherwise.
- * @exception IOException If an I/O error occurs while communicating with the IBM i system.
- **/
- public boolean createNewFile()
- throws IOException
- {
- return ifsFile_.createNewFile();
- }
-
-
-
-
-/**
- * Deletes the IFSJavaFile. If the target is
- * a directory, it must be empty for deletion to succeed.
- *
- * @return true
if the file is successfully deleted;
- * false
otherwise.
- * @exception SecurityException If the user is denied access to the file.
-**/
- public boolean delete()
- throws SecurityException
- {
- try
- {
- int returnCode = ifsFile_.delete0();
- if ((returnCode == IFSReturnCodeRep.ACCESS_DENIED_TO_DIR_ENTRY)
- || (returnCode == IFSReturnCodeRep.ACCESS_DENIED_TO_REQUEST))
- {
- throw new SecurityException(ResourceBundleLoader.getText(mapRC(returnCode)));
- }
- return (returnCode == IFSReturnCodeRep.SUCCESS);
- }
- catch (AS400SecurityException e)
- {
- Trace.log(Trace.ERROR, e);
- throw new SecurityException(e);
- }
- catch (IOException e)
- {
- if (Trace.traceOn_) Trace.log(Trace.ERROR, e);
- return false;
- }
- }
-
-/**
- * Compares this IFSJavaFile against the specified object.
- * Returns true
if and only if the argument is
- * not null and is an IFSJavaFile
- * object whose path name is equal to the path name of
- * this IFSJavaFile,
- * and system names of the objects are equal.
- *
- * @param obj The object to compare with.
- *
- * @return true
if the objects are the same;
- * false
otherwise.
-**/
- public boolean equals(Object obj)
- {
- if (obj == null || !(obj instanceof IFSJavaFile))
- return false;
-
- // return getPath().equals(((IFSJavaFile)obj).getPath()); // @A4D
-
- // @A4A:
- IFSFile otherIfsFile = ((IFSJavaFile)obj).getIfsFile();
- return (ifsFile_.equals(otherIfsFile));
- }
-
-/**
- * Indicates if the IFSJavaFile exists.
- *
- * @return true
if the file specified by this object
- * exists; false
otherwise.
- * @exception SecurityException If the user is denied read access to the file.
- * @exception SecurityException If the user is denied access to the file.
-**/
- public boolean exists()
- throws SecurityException
- {
- int returnCode = IFSReturnCodeRep.FILE_NOT_FOUND;
- try
- {
- returnCode = ifsFile_.exists0(); //@A5c
- if (returnCode == IFSReturnCodeRep.ACCESS_DENIED_TO_DIR_ENTRY
- || returnCode == IFSReturnCodeRep.ACCESS_DENIED_TO_REQUEST)
- {
- throw new SecurityException(ResourceBundleLoader.getText(mapRC(returnCode)));
- }
- }
- catch (AS400SecurityException e)
- {
- Trace.log(Trace.ERROR, e);
- throw new SecurityException(e);
- }
- catch (IOException e)
- {
- if (Trace.traceOn_) Trace.log(Trace.ERROR, e);
- return false;
- }
- return (returnCode == IFSReturnCodeRep.SUCCESS);
- }
-
-/**
- * Returns An IFSJavaFile object based on the absolute path name of the
- * current object. If the system property is set, it is copied to
- * the returned object.
- *
- * @return an IFSJavaFile object based on the absolute path name
- * of the current object.
- *
- * @see #getAbsolutePath()
-**/
- public File getAbsoluteFile()
- {
- if (getSystem() != null)
- return new IFSJavaFile(getSystem(), this.getAbsolutePath());
- else
- return new IFSJavaFile(this.getAbsolutePath());
- }
-
-
-/**
- * Returns the absolute path name of the IFSJavaFile.
- * This is the full path starting at the root directory.
- *
- * @return The absolute path name for this IFSJavaFile.
- * All paths are absolute paths in the integrated file system.
- *
- * @see #isAbsolute()
-**/
- public String getAbsolutePath()
- {
- String pathString = ifsFile_.getAbsolutePath();
- if (pathString != null && replace_) //@P2C
- {
- return pathString.replace(AS400_SEPARATOR, separatorChar);
- }
- return pathString;
- }
-
-
-/**
- * Returns An IFSJavaFile object based on the canonical path name of the
- * current object. If the system property is set, it is
- * copied to the returned object.
- *
- * @return an IFSJavaFile object based on the canonical path name
- * of the current object.
- *
- * @exception IOException If an I/O error occurs while communicating with the IBM i system.
- * @see #getCanonicalPath
-**/
- public File getCanonicalFile() throws IOException
- {
- if (getSystem() != null)
- return new IFSJavaFile(getSystem(), this.getCanonicalPath());
- else
- return new IFSJavaFile(this.getCanonicalPath());
- }
-
-/**
- * Returns the path name in canonical form of IFSJavaFile path.
- * This is the full path starting at the root directory.
- *
- * @return The canonical path name for this IFSJavaFile.
- *
- * @exception IOException If an I/O error occurs while communicating with the IBM i system.
-**/
- public String getCanonicalPath() throws IOException
- {
- String pathString = ifsFile_.getCanonicalPath();
- if (pathString != null && replace_) //@P2C
- {
- return pathString.replace(AS400_SEPARATOR, separatorChar);
- }
- return pathString;
- }
-
-
- /**
- Returns the number of unallocated bytes in the partition named by this abstract path name.
-
- The returned number of unallocated bytes is a hint, but not a guarantee, that it is possible to use most or any of these bytes. The number of unallocated bytes is most likely to be accurate immediately after this call. It is likely to be made inaccurate by any external I/O operations including those made on the system outside of this virtual machine. This method makes no guarantee that write operations to this file system will succeed. - - @return The number of unallocated bytes on the partition; or 0L if the abstract pathname does not name a partition. This value will be less than or equal to the total file system size returned by getTotalSpace(). - @exception SecurityException If the user is denied access to the file. - **/ - public long getFreeSpace() - throws SecurityException - { - try - { - return ifsFile_.getAvailableSpace(false); - } - catch (AS400SecurityException e) - { - Trace.log(Trace.ERROR, e); - throw new SecurityException(e); - } - catch (IOException e) - { - if (Trace.traceOn_) Trace.log(Trace.ERROR, e); - return 0L; - } - } - - - /** - Returns the size of the partition named by this abstract pathname. - - @return The size, in bytes, of the partition; or 0L if this abstract pathname does not name a partition. - @exception SecurityException If the user is denied access to the file. - **/ - public long getTotalSpace() - throws SecurityException - { - try - { - return ifsFile_.getTotalSpace(false); - } - catch (AS400SecurityException e) - { - Trace.log(Trace.ERROR, e); - throw new SecurityException(e); - } - catch (IOException e) - { - if (Trace.traceOn_) Trace.log(Trace.ERROR, e); - return 0L; - } - } - - - /** - Returns the number of bytes available to this virtual machine on the partition named by this abstract pathname. When possible, this method checks for write permissions and other operating system restrictions and will therefore usually provide a more accurate estimate of how much new data can actually be written than getFreeSpace(). -
- The returned number of available bytes is a hint, but not a guarantee, that it is possible to use most or any of these bytes. The number of unallocated bytes is most likely to be accurate immediately after this call. It is likely to be made inaccurate by any external I/O operations including those made on the system outside of this virtual machine. This method makes no guarantee that write operations to this file system will succeed. -
- Note: If the user profile has a "maximum storage allowed" setting of *NOMAX, then getUsableSpace() returns the same value as {@link #getFreeSpace getFreeSpace()}. - - @return The number of available bytes on the partition; or 0L if the abstract pathname does not name a partition. - @exception SecurityException If the user is denied access to the file. - **/ - public long getUsableSpace() - throws SecurityException - { - try - { - return ifsFile_.getAvailableSpace(true); - } - catch (AS400SecurityException e) - { - Trace.log(Trace.ERROR, e); - throw new SecurityException(e); - } - catch (IOException e) - { - if (Trace.traceOn_) Trace.log(Trace.ERROR, e); - return 0L; - } - } - - -/** - * Returns the IFSFile object contained within this IFSJavaFile. - * - * @return The IFSFile object contained within this IFSJavaFile. -**/ - IFSFile getIfsFile() - { - return ifsFile_; - } - - -/** - * Returns the name of the IFSJavaFile. The name - * is everything in the path name after the last occurrence of the - * separator character. - *
- * The following example demonstrates the use of this method: - *
- * In this example, fileName would equal "file.dat". - *
- * String path = "\\path\\file.dat"; - * IFSJavaFile file = new IFSJavaFile(new AS400("enterprise"), path); - *- * - * @return The name (without any directory components) of this IFSJavaFile. -**/ - public String getName() - { - return ifsFile_.getName(); - } - -/** - * Returns the parent directory of the IFSJavaFile. The parent directory is everything in - * the path name before the last occurrence of the separator - * character, or null if the separator character does not appear in - * the path name. - *
- * String fileName = file.getName(); - *
- * The following example demonstrates the use of this method: - *
- * In this example, parentPath would equal "\test". - *
- * String path = "\\test\\path"; - * IFSJavaFile file = new IFSJavaFile(new AS400("enterprise"), path); - *- * - * @return The parent directory if one exists; null otherwise. - * @see #getParentFile() -**/ - public String getParent() - { - String parentString = ifsFile_.getParent(); - if (parentString != null && replace_) //@P2C - { - return parentString.replace(AS400_SEPARATOR, separatorChar); - } - return parentString; - } - -/** - * Returns an IFSJavaFile object that represents the parent of - * the current object. The parent is the path name before the - * last occurrence of the separator character. Null is returned - * if the separator character does not appear in the path - * or the current object is the file system root. - * If the system property is set, it is also copied to the returned object. - * - * @return an IFSJavaFile object representing the - * parent directory if one exists; null otherwise. - * - * @see #getParent() -**/ - public File getParentFile() - { - if (getParent() == null) - return null; - if (getSystem() != null) - return new IFSJavaFile(getSystem(), this.getParent()); - else - return new IFSJavaFile(this.getParent()); - } - - - -/** - * Returns the path name of the IFSJavaFile. - *
- * String parentPath = file.getParent(); - *
- * The following example demonstrates the use of this method: - *
- * In this example, thePath would equal "\test\path" the same value as path. - *
- * String path = "\\test\\path"; - * IFSJavaFile file = new IFSJavaFile(new AS400("enterprise"), path); - *- * - * @return The file path name. -**/ - public String getPath() - { - String pathString = ifsFile_.getPath(); - if (pathString != null && replace_) //@P2C - { - return pathString.replace(AS400_SEPARATOR, separatorChar); - } - return pathString; - } - - - /** - Returns the pattern-matching behavior used when files are listed by any of the list() or listFiles() methods. The default is PATTERN_POSIX. - @return Either {@link IFSFile#PATTERN_POSIX PATTERN_POSIX}, {@link IFSFile#PATTERN_POSIX_ALL PATTERN_POSIX_ALL}, or {@link IFSFile#PATTERN_OS2 PATTERN_OS2} - * @throws IOException If an error occurs while communicating with the system. - **/ - public int getPatternMatching() - throws IOException - { - return ifsFile_.getPatternMatching(); - } - -/** - * Returns the system that this object references. - * - * @return The system object. -**/ - public AS400 getSystem() - { - return ifsFile_.getSystem(); - } - -/** - * Computes a hashcode for this object. - * - * @return A hash code value for this object. -**/ - public int hashCode() - { - return ifsFile_.hashCode(); - } - -/** - * Indicates if the path name of this IFSJavaFile is an - * absolute path name. - * - * @return
- * String thePath = file.getPath(); - *
true
if the path name specification is absolute; false
otherwise.
-**/
- public boolean isAbsolute()
- {
- // Formerly, this method always reported true, since IFSFile.isAbsolute always reports true.
- // In order for JFileChooser to work properly (when used in combination with IFSFileSystemView), instances of IFSJavaFile must remember whether they were created with an absolute path. The underlying IFSFile instance assumes it was created with an absolute path, so we can't rely on the IFSFile to keep track of that for us.
- // More details: There is logic in javax.swing.plaf.basic.BasicFileChooserUI#ApproveSelectionAction.actionPerformed() that calls File.isAbsolute(). If not absolute, BasicFileChooserUI prepends the directory path and creates a new (absolute) File object. For that reason, each instance of IFSJavaFile needs to remember whether it was created with an absolute path or not.
-
- //return ifsFile_.isAbsolute();
- return absolute_;
- }
-
-
- // Utility method for determining whether a path is absolute.
- static boolean isAbsolutePath(String path) {
- if (path != null && path.length() != 0 && path.charAt(0) == separatorChar) {
- return true;
+ /**
+ * Atomically create a new, empty file. The file is created if and only if the file does not yet exist. The check
+ * for existence and the file creation is a single atomic operation.
+ *
+ * @return true if the file is created, false otherwise.
+ * @exception IOException If an I/O error occurs while communicating with the IBM i system.
+ **/
+ @Override
+ public boolean createNewFile() throws IOException {
+ return ifsFile_.createNewFile();
+ }
+
+ /**
+ * Deletes the IFSJavaFile. If the target is a directory, it must be empty for deletion to succeed.
+ *
+ * @return true
if the file is successfully deleted; false
otherwise.
+ * @exception SecurityException If the user is denied access to the file.
+ **/
+ @Override
+ public boolean delete() throws SecurityException
+ {
+ try
+ {
+ int returnCode = ifsFile_.delete0();
+ if ((returnCode == IFSReturnCodeRep.ACCESS_DENIED_TO_DIR_ENTRY)
+ || (returnCode == IFSReturnCodeRep.ACCESS_DENIED_TO_REQUEST))
+ throw new SecurityException(ResourceBundleLoader.getText(mapRC(returnCode)));
+
+ return (returnCode == IFSReturnCodeRep.SUCCESS);
+ }
+ catch (AS400SecurityException e) {
+ Trace.log(Trace.ERROR, e);
+ throw new SecurityException(e);
+ }
+ catch (IOException e) {
+ if (Trace.traceOn_) Trace.log(Trace.ERROR, e);
+ return false;
+ }
+ }
+
+ /**
+ * Compares this IFSJavaFile against the specified object. Returns true
if and only if the argument is
+ * not null and is an IFSJavaFile object whose path name is equal to the path name of this IFSJavaFile, and system
+ * names of the objects are equal.
+ *
+ * @param obj The object to compare with.
+ *
+ * @return true
if the objects are the same; false
otherwise.
+ **/
+ @Override
+ public boolean equals(Object obj)
+ {
+ if (obj == null || !(obj instanceof IFSJavaFile))
+ return false;
+
+ IFSFile otherIfsFile = ((IFSJavaFile) obj).getIfsFile();
+ return (ifsFile_.equals(otherIfsFile));
+ }
+
+ /**
+ * Indicates if the IFSJavaFile exists.
+ *
+ * @return true
if the file specified by this object exists; false
otherwise.
+ * @exception SecurityException If the user is denied read access to the file.
+ * @exception SecurityException If the user is denied access to the file.
+ **/
+ @Override
+ public boolean exists() throws SecurityException
+ {
+ int returnCode = IFSReturnCodeRep.FILE_NOT_FOUND;
+ try
+ {
+ returnCode = ifsFile_.exists0(); // @A5c
+ if (returnCode == IFSReturnCodeRep.ACCESS_DENIED_TO_DIR_ENTRY
+ || returnCode == IFSReturnCodeRep.ACCESS_DENIED_TO_REQUEST)
+ throw new SecurityException(ResourceBundleLoader.getText(mapRC(returnCode)));
+ }
+ catch (AS400SecurityException e) {
+ Trace.log(Trace.ERROR, e);
+ throw new SecurityException(e);
+ }
+ catch (IOException e) {
+ if (Trace.traceOn_) Trace.log(Trace.ERROR, e);
+ return false;
+ }
+
+ return (returnCode == IFSReturnCodeRep.SUCCESS);
+ }
+
+ /**
+ * Returns An IFSJavaFile object based on the absolute path name of the current object. If the system
+ * property is set, it is copied to the returned object.
+ *
+ * @return an IFSJavaFile object based on the absolute path name of the current object.
+ *
+ * @see #getAbsolutePath()
+ **/
+ @Override
+ public File getAbsoluteFile()
+ {
+ if (getSystem() != null)
+ return new IFSJavaFile(getSystem(), this.getAbsolutePath());
+
+ return new IFSJavaFile(this.getAbsolutePath());
+ }
+
+ /**
+ * Returns the absolute path name of the IFSJavaFile. This is the full path starting at the root directory.
+ *
+ * @return The absolute path name for this IFSJavaFile. All paths are absolute paths in the integrated file system.
+ *
+ * @see #isAbsolute()
+ **/
+ @Override
+ public String getAbsolutePath()
+ {
+ String pathString = ifsFile_.getAbsolutePath();
+ if (pathString != null && replace_)
+ return pathString.replace(AS400_SEPARATOR, separatorChar);
+
+ return pathString;
+ }
+
+ /**
+ * Returns An IFSJavaFile object based on the canonical path name of the current object. If the system
+ * property is set, it is copied to the returned object.
+ *
+ * @return an IFSJavaFile object based on the canonical path name of the current object.
+ *
+ * @exception IOException If an I/O error occurs while communicating with the IBM i system.
+ * @see #getCanonicalPath
+ **/
+ @Override
+ public File getCanonicalFile() throws IOException
+ {
+ if (getSystem() != null)
+ return new IFSJavaFile(getSystem(), this.getCanonicalPath());
+
+ return new IFSJavaFile(this.getCanonicalPath());
+ }
+
+ /**
+ * Returns the path name in canonical form of IFSJavaFile path. This is the full path starting at the root
+ * directory.
+ *
+ * @return The canonical path name for this IFSJavaFile.
+ *
+ * @exception IOException If an I/O error occurs while communicating with the IBM i system.
+ **/
+ @Override
+ public String getCanonicalPath() throws IOException
+ {
+ String pathString = ifsFile_.getCanonicalPath();
+ if (pathString != null && replace_) // @P2C
+ return pathString.replace(AS400_SEPARATOR, separatorChar);
+
+ return pathString;
+ }
+
+ /**
+ * Returns the number of unallocated bytes in the partition named by this abstract path name.
+ * + * The returned number of unallocated bytes is a hint, but not a guarantee, that it is possible to use most or any + * of these bytes. The number of unallocated bytes is most likely to be accurate immediately after this call. It is + * likely to be made inaccurate by any external I/O operations including those made on the system outside of this + * virtual machine. This method makes no guarantee that write operations to this file system will succeed. + * + * @return The number of unallocated bytes on the partition; or 0L if the abstract pathname does not name a + * partition. This value will be less than or equal to the total file system size returned by + * getTotalSpace(). + * @exception SecurityException If the user is denied access to the file. + **/ + @Override + public long getFreeSpace() throws SecurityException + { + try { + return ifsFile_.getAvailableSpace(false); + } + catch (AS400SecurityException e) { + Trace.log(Trace.ERROR, e); + throw new SecurityException(e); + } + catch (IOException e) { + if (Trace.traceOn_) Trace.log(Trace.ERROR, e); + return 0L; + } + } + + /** + * Returns the size of the partition named by this abstract pathname. + * + * @return The size, in bytes, of the partition; or 0L if this abstract pathname does not name a partition. + * @exception SecurityException If the user is denied access to the file. + **/ + @Override + public long getTotalSpace() throws SecurityException + { + try { + return ifsFile_.getTotalSpace(false); + } + catch (AS400SecurityException e) { + Trace.log(Trace.ERROR, e); + throw new SecurityException(e); + } + catch (IOException e) { + if (Trace.traceOn_) Trace.log(Trace.ERROR, e); + return 0L; + } + } + + /** + * Returns the number of bytes available to this virtual machine on the partition named by this abstract pathname. + * When possible, this method checks for write permissions and other operating system restrictions and will + * therefore usually provide a more accurate estimate of how much new data can actually be written than + * getFreeSpace(). + *
+ * The returned number of available bytes is a hint, but not a guarantee, that it is possible to use most or any of + * these bytes. The number of unallocated bytes is most likely to be accurate immediately after this call. It is + * likely to be made inaccurate by any external I/O operations including those made on the system outside of this + * virtual machine. This method makes no guarantee that write operations to this file system will succeed. + *
+ * Note: If the user profile has a "maximum storage allowed" setting of *NOMAX, then getUsableSpace() returns the + * same value as {@link #getFreeSpace getFreeSpace()}. + * + * @return The number of available bytes on the partition; or 0L if the abstract pathname does not name a partition. + * @exception SecurityException If the user is denied access to the file. + **/ + @Override + public long getUsableSpace() throws SecurityException + { + try { + return ifsFile_.getAvailableSpace(true); + } + catch (AS400SecurityException e) { + Trace.log(Trace.ERROR, e); + throw new SecurityException(e); + } + catch (IOException e) { + if (Trace.traceOn_) Trace.log(Trace.ERROR, e); + return 0L; + } + } + + /** + * Returns the IFSFile object contained within this IFSJavaFile. + * + * @return The IFSFile object contained within this IFSJavaFile. + **/ + IFSFile getIfsFile() { + return ifsFile_; + } + + /** + * Returns the name of the IFSJavaFile. The name is everything in the path name after the last occurrence of the + * separator character. + *
+ * The following example demonstrates the use of this method: + *
+ * In this example, fileName would equal "file.dat". + * + *
+ * String path = "\\path\\file.dat"; + * IFSJavaFile file = new IFSJavaFile(new AS400("enterprise"), path); + *+ * + * @return The name (without any directory components) of this IFSJavaFile. + **/ + @Override + public String getName() { + return ifsFile_.getName(); + } + + /** + * Returns the parent directory of the IFSJavaFile. The parent directory is everything in the path name before the + * last occurrence of the separator character, or null if the separator character does not appear in the path name. + *
+ * String fileName = file.getName(); + *
+ * The following example demonstrates the use of this method: + *
+ * In this example, parentPath would equal "\test". + * + *
+ * String path = "\\test\\path"; + * IFSJavaFile file = new IFSJavaFile(new AS400("enterprise"), path); + *+ * + * @return The parent directory if one exists; null otherwise. + * @see #getParentFile() + **/ + @Override + public String getParent() + { + String parentString = ifsFile_.getParent(); + if (parentString != null && replace_) + return parentString.replace(AS400_SEPARATOR, separatorChar); + + return parentString; + } + + /** + * Returns an IFSJavaFile object that represents the parent of the current object. The parent is the path name + * before the last occurrence of the separator character. Null is returned if the separator character does not + * appear in the path or the current object is the file system root. If the system property is set, it is + * also copied to the returned object. + * + * @return an IFSJavaFile object representing the parent directory if one exists; null otherwise. + * + * @see #getParent() + **/ + @Override + public File getParentFile() + { + if (getParent() == null) + return null; + + if (getSystem() != null) + return new IFSJavaFile(getSystem(), this.getParent()); + + return new IFSJavaFile(this.getParent()); + } + + /** + * Returns the path name of the IFSJavaFile. + *
+ * String parentPath = file.getParent(); + *
+ * The following example demonstrates the use of this method: + *
+ * In this example, thePath would equal "\test\path" the same value as path. + * + *
+ * String path = "\\test\\path"; + * IFSJavaFile file = new IFSJavaFile(new AS400("enterprise"), path); + *+ * + * @return The file path name. + **/ + @Override + public String getPath() + { + String pathString = ifsFile_.getPath(); + if (pathString != null && replace_) + return pathString.replace(AS400_SEPARATOR, separatorChar); + + return pathString; + } + + /** + * Returns the pattern-matching behavior used when files are listed by any of the list() or + * listFiles() methods. The default is PATTERN_POSIX. + * + * @return Either {@link IFSFile#PATTERN_POSIX PATTERN_POSIX}, {@link IFSFile#PATTERN_POSIX_ALL PATTERN_POSIX_ALL}, + * or {@link IFSFile#PATTERN_OS2 PATTERN_OS2} + * @throws IOException If an error occurs while communicating with the system. + **/ + public int getPatternMatching() throws IOException { + return ifsFile_.getPatternMatching(); + } + + /** + * Returns the system that this object references. + * + * @return The system object. + **/ + public AS400 getSystem() { + return ifsFile_.getSystem(); + } + + /** + * Computes a hashcode for this object. + * + * @return A hash code value for this object. + **/ + @Override + public int hashCode() { + return ifsFile_.hashCode(); + } + + /** + * Indicates if the path name of this IFSJavaFile is an absolute path name. + * + * @return
+ * String thePath = file.getPath(); + *
true
if the path name specification is absolute; false
otherwise.
+ **/
+ @Override
+ public boolean isAbsolute()
+ {
+ // Formerly, this method always reported true, since IFSFile.isAbsolute always reports true.
+ // In order for JFileChooser to work properly (when used in combination with IFSFileSystemView), instances of
+ // IFSJavaFile must remember whether they were created with an absolute path. The underlying IFSFile instance
+ // assumes it was created with an absolute path, so we can't rely on the IFSFile to keep track of that for us.
+ // More details: There is logic in
+ // javax.swing.plaf.basic.BasicFileChooserUI#ApproveSelectionAction.actionPerformed() that calls
+ // File.isAbsolute(). If not absolute, BasicFileChooserUI prepends the directory path and creates a new
+ // (absolute) File object. For that reason, each instance of IFSJavaFile needs to remember whether it was
+ // created with an absolute path or not.
+
+ return absolute_;
+ }
+
+ // Utility method for determining whether a path is absolute.
+ static boolean isAbsolutePath(String path) {
+ return (path != null && path.length() != 0 && path.charAt(0) == separatorChar);
+ }
+
+ /**
+ * Indicates if the IFSJavaFile is a directory.
+ *
+ * @return true
if the IFSJavaFile exists and is a directory; false
otherwise.
+ * @exception SecurityException If the user is denied access to the file.
+ **/
+ @Override
+ public boolean isDirectory() throws SecurityException
+ {
+ int returnCode = IFSReturnCodeRep.FILE_NOT_FOUND;
+ try
+ {
+ returnCode = ifsFile_.isDirectory0();
+ if (returnCode == IFSReturnCodeRep.ACCESS_DENIED_TO_DIR_ENTRY
+ || returnCode == IFSReturnCodeRep.ACCESS_DENIED_TO_REQUEST)
+ throw new SecurityException(ResourceBundleLoader.getText(mapRC(returnCode)));
+ }
+ catch (AS400SecurityException e) {
+ Trace.log(Trace.ERROR, e);
+ throw new SecurityException(e);
+ }
+ catch (IOException e) {
+ if (Trace.traceOn_) Trace.log(Trace.ERROR, e);
+ return false;
+ }
+
+ return (returnCode == IFSReturnCodeRep.SUCCESS);
+ }
+
+ /**
+ * Indicates if the IFSJavaFile is a "normal" file.true
if the specified file exists and is a "normal" file; false
otherwise.
+ * @exception SecurityException If the user is denied access to the file.
+ **/
+ @Override
+ public boolean isFile() throws SecurityException
+ {
+ int returnCode = IFSReturnCodeRep.FILE_NOT_FOUND;
+ try
+ {
+ returnCode = ifsFile_.isFile0();
+ if (returnCode == IFSReturnCodeRep.ACCESS_DENIED_TO_DIR_ENTRY
+ || returnCode == IFSReturnCodeRep.ACCESS_DENIED_TO_REQUEST)
+ throw new SecurityException(ResourceBundleLoader.getText(mapRC(returnCode)));
+ }
+ catch (AS400SecurityException e) {
+ Trace.log(Trace.ERROR, e);
+ throw new SecurityException(e);
+ }
+ catch (IOException e) {
+ if (Trace.traceOn_) Trace.log(Trace.ERROR, e);
+ return false;
+ }
+
+ return (returnCode == IFSReturnCodeRep.SUCCESS);
+ }
+
+ /**
+ * Indicates if the IFSJavaFile is hidden. On the IBM i system, a file is hidden if its hidden attribute is set.
+ *
+ * @return true
if the file is hidden; false
otherwise.
+ * @exception SecurityException If the user is denied access to the file.
+ **/
+ @Override
+ public boolean isHidden() throws SecurityException
+ {
+ try {
+ return ifsFile_.isHidden();
+ }
+ catch (AS400SecurityException e) {
+ throw new SecurityException(e);
+ }
+ catch (IOException e) {
+ if (Trace.traceOn_) Trace.log(Trace.ERROR, e);
+ return false;
+ }
+ }
+
+ /**
+ * Indicates the time that the IFSJavaFile was last modified.
+ *
+ * @return The time (measured in milliseconds since 01/01/1970 00:00:00 GMT) that the IFSJavaFile was last modified,
+ * or 0
if it does not exist.
+ * @exception SecurityException If the user is denied access to the file.
+ **/
+ @Override
+ public long lastModified() throws SecurityException
+ {
+ try {
+ return ifsFile_.lastModified0();
+ }
+ catch (AS400SecurityException e) {
+ Trace.log(Trace.ERROR, e);
+ throw new SecurityException(e);
+ }
+ catch (IOException e) {
+ if (Trace.traceOn_) Trace.log(Trace.ERROR, e);
+ return 0L;
+ }
+ }
+
+ /**
+ * Indicates the length of this IFSJavaFile.
+ *
+ * @return The length, in bytes, of the IFSJavaFile, or 0
((IFSJavaFile) if it does not exist.
+ * @exception SecurityException If the user is denied access to the file.
+ **/
+ @Override
+ public long length() throws SecurityException
+ {
+ try
+ {
+ // For the listFiles() methods, the IFS File Server reports the length of
+ // a symbolic link rather than the length of the target object. Circumvention
+ // is to clear the ifsFile cache and re-retrieve the attributes from the IFS
+ // File Server. When not using wild-cards the IFS File Server always follows
+ // symlnk objects and returns the attributes of the target object.
+ if (ifsFile_.isSymbolicLink())
+ ifsFile_.clearCachedAttributes();
+ return ifsFile_.length0();
+ }
+ catch (AS400SecurityException e) {
+ Trace.log(Trace.ERROR, e);
+ throw new SecurityException(e);
+ }
+ catch (IOException e) {
+ if (Trace.traceOn_) Trace.log(Trace.ERROR, e);
+ return 0L;
+ }
+ }
+
+ /**
+ * Lists the files in this IFSJavaFile directory.
+ *
+ * @return An array of object names in the directory. This list does not include the current directory or the parent
+ * directory. If this IFSJavaFile is not a directory, null is returned. If this IFSJavaFile is an empty
+ * directory, an empty string array is returned.
+ * @see #listFiles()
+ * @exception SecurityException If the user is denied access to the file.
+ **/
+ @Override
+ public String[] list() throws SecurityException
+ {
+ try {
+ return ifsFile_.list0(null, "*");
+ }
+ catch (AS400SecurityException e) {
+ Trace.log(Trace.ERROR, e);
+ throw new SecurityException(e);
+ }
+ catch (IOException e) {
+ if (Trace.traceOn_) Trace.log(Trace.ERROR, e);
+ return new String[0];
+ }
+ }
+
+ /**
+ * Lists the files in this IFSJavaFile directory that satisfy filter.
+ *
+ * @param filter The file name filter.
+ *
+ * @return An array of object names in the directory that satisfy the file name filter. This list does not include
+ * the current directory or the parent directory. If this IFSJavaFile is not a directory, null is returned.
+ * If this IFSJavaFile is an empty directory, or the file name filter does not match any files, an empty
+ * string array is returned. The IFSJavaFile object passed to the file name filter object have cached file
+ * attribute information. Maintaining references to these IFSJavaFile objects after the list operation
+ * increases the chances that their file attribute information will not be valid.
+ * + * The following example demonstrates the use of this method: + * + *
+ * class AcceptClass implements java.io.FilenameFilter + * { + * public boolean accept(java.io.File dir, java.lang.String name) + * { + * if (name.startsWith("IFS")) + * return true; + * return false; + * } + * } + *+ * + * @exception SecurityException If the user is denied access to the file. + * @see #listFiles(FilenameFilter) + **/ + @Override + public String[] list(FilenameFilter filter) throws SecurityException + { + String names[] = null; + + try { + names = ifsFile_.list0(null, "*"); + } + catch (AS400SecurityException e) { + Trace.log(Trace.ERROR, e); + throw new SecurityException(e); + } + catch (IOException e) { + if (Trace.traceOn_) Trace.log(Trace.ERROR, e); + return null; + } + + if (names == null) + return null; + + // Fill in the Vector + Vector v = new Vector(); + for (int i = 0; i < names.length; i++) + { + if ((filter == null) || filter.accept(this, names[i])) + v.addElement(names[i]); + } + + // Create the array + String files[] = new String[v.size()]; + v.copyInto(files); + + return files; + } + + /** + * Lists the files in the IFSJavaFile directory that satisfy file name filter. + * + * @param filter The file name filter. + * + * @return An array of object names in the directory that satisfy the file name filter. This list does not include + * the current directory or the parent directory. If this IFSJavaFile is not a directory, null is returned. + * If this IFSJavaFile is an empty directory, or the file name filter does not match any files, an empty + * string array is returned. The IFSFile object passed to the file name filter object have cached file + * attribute information. Maintaining references to these IFSFile objects after the list operation increases + * the chances that their file attribute information will not be valid. + *
+ * IFSJavaFile file = new IFSJavaFile(new AS400("enterprise"), path); + * AcceptClass ac = new AcceptClass(); + * file.list(ac); + *
+ * The following example demonstrates the use of this method: + * + *
+ * class AcceptClass implements IFSFileFilter + * { + * public boolean accept(IFSFile file) + * { + * if (file.getName().startsWith("IFS")) + * return true; + * return false; + * } + * } + *+ * + * @exception SecurityException If the user is denied access to the file. + * @see #listFiles(IFSFileFilter) + **/ + public String[] list(IFSFileFilter filter) throws SecurityException + { + try { + return ifsFile_.list0(filter, "*"); + } + catch (AS400SecurityException e) { + Trace.log(Trace.ERROR, e); + throw new SecurityException(e); + } + catch (IOException e) { + if (Trace.traceOn_) Trace.log(Trace.ERROR, e); + return new String[0]; + } + } + + /** + * Lists the files in this IFSJavaFile directory that satisfy filter and pattern. + * + *
+ * IFSJavaFile file = new IFSJavaFile(new AS400("enterprise"), path); + * AcceptClass ac = new AcceptClass(); + * file.list(ac); + * + *
+ * Note:
+ * If the file does not match pattern, it will not be processed by filter.
+ *
+ * @param filter The file name filter.
+ * @param pattern The pattern that all filenames must match. Acceptable characters are wildcards (* - matches
+ * multiple characters) and question marks (? - matches one character). Pattern must not be null.
+ *
+ * @return An array of object names in the directory that satisfy the file name filter and pattern. This list does
+ * not include the current directory or the parent directory. If this IFSJavaFile is not a directory, null
+ * is returned. If this IFSJavaFile is an empty directory, or the file name filter or pattern does not match
+ * any files, an empty string array is returned. The IFSFile object passed to the file name filter object
+ * have cached file attribute information. Maintaining references to these IFSFile objects after the list
+ * operation increases the chances that their file attribute information will not be valid.
+ * @exception SecurityException If the user is denied access to the file.
+ * @see #listFiles(IFSFileFilter,String)
+ **/
+ public String[] list(IFSFileFilter filter, String pattern) throws SecurityException
+ {
+ if (pattern == null)
+ throw new NullPointerException("pattern");
+
+ try {
+ return ifsFile_.list0(filter, pattern);
+ }
+ catch (AS400SecurityException e) {
+ Trace.log(Trace.ERROR, e);
+ throw new SecurityException(e);
+ }
+ catch (IOException e) {
+ if (Trace.traceOn_) Trace.log(Trace.ERROR, e);
+ return new String[0];
+ }
+ }
+
+ /**
+ * Lists the files in this IFSJavaFile directory that match pattern.
+ *
+ * @param pattern The pattern that all filenames must match. Acceptable characters are wildcards (* - matches
+ * multiple characters) and question marks (? - matches one character).
+ *
+ * @return An array of object names in the directory that match the pattern. This list does not include the current
+ * directory or the parent directory. If this IFSJavaFile is not a directory, null is returned. If this
+ * IFSJavaFile is an empty directory, or the pattern does not match any files, an empty string array is
+ * returned.
+ * @exception SecurityException If the user is denied access to the file.
+ * @see #listFiles(String)
+ **/
+ public String[] list(String pattern) throws SecurityException
+ {
+ if (pattern == null)
+ throw new NullPointerException("pattern");
+
+ try {
+ return ifsFile_.list0(null, pattern);
+ }
+ catch (AS400SecurityException e) {
+ Trace.log(Trace.ERROR, e);
+ throw new SecurityException(e);
+ }
+ catch (IOException e) {
+ if (Trace.traceOn_) Trace.log(Trace.ERROR, e);
+ return new String[0];
+ }
+ }
+
+ /**
+ * Lists the files in this IFSJavaFile directory. With the use of this function, attribute information is cached and
+ * will not be refreshed from the IBM i system. This means attribute information may become inconsistent with the
+ * IBM i system.
+ *
+ * @return An array of objects in the directory. This list does not include the current directory or the parent
+ * directory. If this IFSJavaFile is not a directory, null is returned. If this IFSJavaFile is an empty
+ * directory, an empty object array is returned.
+ * @exception SecurityException If the user is denied access to the file.
+ * @see #list()
+ **/
+ @Override
+ public File[] listFiles() throws SecurityException {
+ return listFiles(null, "*");
+ }
+
+ /**
+ * Lists the files in this IFSJavaFile directory that satisfy filter. With the use of this function,
+ * attribute information is cached and will not be refreshed from the IBM i system. This means attribute information
+ * may become inconsistent with the IBM i system.
+ *
+ * @param filter The file name filter.
+ *
+ * @return An array of objects in the directory that satisfy the file name filter. This list does not include the
+ * current directory or the parent directory. If this IFSJavaFile is not a directory, null is returned. If
+ * this IFSJavaFile is an empty directory, or the file name filter does not match any files, an empty object
+ * array is returned. The IFSJavaFile object passed to the file name filter object has cached file attribute
+ * information. Maintaining references to these IFSJavaFile objects after the list operation increases the
+ * chances that their file attribute information will not be valid.
+ *
+ * The following example demonstrates the use of this method: + * + *
+ * class AcceptClass implements java.io.FilenameFilter + * { + * public boolean accept(java.io.File dir, java.lang.String name) + * { + * if (name.startsWith("IFS")) + * return true; + * return false; + * } + * } + *+ * + * @exception SecurityException If the user is denied access to the file. + * @see #list(FilenameFilter) + **/ + @Override + public File[] listFiles(FilenameFilter filter) throws SecurityException + { + IFSFile[] files = null; + try { + files = ifsFile_.listFiles0(null, "*"); + } + catch (AS400SecurityException e) { + Trace.log(Trace.ERROR, e); + throw new SecurityException(e); + } + catch (IOException e) { + if (Trace.traceOn_) Trace.log(Trace.ERROR, e); + return null; + } + + if (files == null) + return null; + + // Fill in the Vector + Vector v = new Vector(); + for (int i = 0; i < files.length; i++) { + if ((filter == null) || filter.accept(this, files[i].getName())) + v.addElement(new IFSJavaFile(files[i])); + } + + // Create the array + IFSJavaFile newFiles[] = new IFSJavaFile[v.size()]; + v.copyInto(newFiles); + + return newFiles; + } + + /** + * Lists the files in this IFSJavaFile directory that satisfy filter. With the use of this function, + * attribute information is cached and will not be refreshed from the IBM i system. This means attribute information + * may become inconsistent with the IBM i system. + * + * @param filter The file filter. + * + * @return An array of objects in the directory that satisfy the file filter. This list does not include the current + * directory or the parent directory. If this IFSJavaFile is not a directory, null is returned. If this + * IFSJavaFile is an empty directory, or the file filter does not match any files, an empty object array is + * returned. The IFSJavaFile object passed to the file filter object has cached file attribute information. + * Maintaining references to these IFSJavaFile objects after the list operation increases the chances that + * their file attribute information will not be valid. + *
+ * IFSJavaFile file = new IFSJavaFile(new AS400("enterprise"), path); + * AcceptClass ac = new AcceptClass(); + * file.listFiles(ac); + *
+ * The following example demonstrates the use of this method: + * + *
+ * class AcceptClass implements java.io.FileFilter + * { + * public boolean accept(java.io.File file) + * { + * if (file.getName().startsWith("IFS")) + * return true; + * return false; + * } + * } + *+ * + * @exception SecurityException If the user is denied access to the file. + **/ + @Override + public File[] listFiles(FileFilter filter) throws SecurityException + { + IFSFile[] files = null; + try { + files = ifsFile_.listFiles0(null, "*"); + } + catch (AS400SecurityException e) { + Trace.log(Trace.ERROR, e); + throw new SecurityException(e); + } + catch (IOException e) { + if (Trace.traceOn_) Trace.log(Trace.ERROR, e); + return null; + } + + if (files == null) + return null; + + // Fill in the Vector + Vector v = new Vector(); + for (int i = 0; i < files.length; i++) + { + IFSJavaFile file = new IFSJavaFile(files[i]); + if ((filter == null) || filter.accept(file)) + v.addElement(file); + } + + // Create the array + IFSJavaFile newFiles[] = new IFSJavaFile[v.size()]; + v.copyInto(newFiles); + + return newFiles; + } + + /** + * Lists the files in the IFSJavaFile directory that satisfy file name filter. With the use of this function, + * attribute information is cached and will not be refreshed from the IBM i system. This means attribute information + * may become inconsistent with the IBM i system. + * + * @param filter The file name filter. + * + * @return An array of objects in the directory that satisfy the file name filter. This list does not include the + * current directory or the parent directory. If this IFSJavaFile is not a directory, null is returned. If + * this IFSJavaFile is an empty directory, or the file name filter does not match any files, an empty object + * array is returned. The IFSFile object passed to the file name filter object has cached file attribute + * information. Maintaining references to these IFSFile objects after the list operation increases the + * chances that their file attribute information will not be valid. + *
+ * IFSJavaFile file = new IFSJavaFile(new AS400("enterprise"), path); + * AcceptClass ac = new AcceptClass(); + * file.listFiles(ac); + *
+ * The following example demonstrates the use of this method: + * + *
+ * class AcceptClass implements IFSFileFilter + * { + * public boolean accept(IFSFile file) + * { + * if (file.getName().startsWith("IFS")) + * return true; + * return false; + * } + * } + *+ * + * @exception SecurityException If the user is denied access to the file. + * @see #list(IFSFileFilter) + **/ + public File[] listFiles(IFSFileFilter filter) throws SecurityException { + return listFiles(filter, "*"); + } + + /** + * Lists the files in this IFSJavaFile directory that satisfy filter and pattern. With the use of this + * function, attribute information is cached and will not be refreshed from the IBM i system. This means attribute + * information may become inconsistent with the IBM i system. + * + *
+ * IFSJavaFile file = new IFSJavaFile(new AS400("enterprise"), path); + * AcceptClass ac = new AcceptClass(); + * file.listFiles(ac); + * + *
+ * Note:
+ * If the file does not match pattern, it will not be processed by filter.
+ *
+ * @param filter The file name filter.
+ * @param pattern The pattern that all filenames must match. Acceptable characters are wildcards (* - matches
+ * multiple characters) and question marks (? - matches one character). Pattern must not be null.
+ *
+ * @return An array of objects in the directory that satisfy the file name filter and pattern. This list does not
+ * include the current directory or the parent directory. If this IFSJavaFile is not a directory, null is
+ * returned. If this IFSJavaFile is an empty directory, or the file name filter or pattern does not match
+ * any files, an empty object array is returned. The IFSFile object passed to the file name filter object
+ * has cached file attribute information. Maintaining references to these IFSFile objects after the list
+ * operation increases the chances that their file attribute information will not be valid.
+ * @exception SecurityException If the user is denied access to the file.
+ * @see #list(IFSFileFilter,String)
+ **/
+ public File[] listFiles(IFSFileFilter filter, String pattern) throws SecurityException
+ {
+ if (pattern == null)
+ throw new NullPointerException("pattern");
+
+ try
+ {
+ IFSFile files[] = ifsFile_.listFiles0(filter, pattern);
+ IFSJavaFile newFiles[] = new IFSJavaFile[files.length];
+ for (int i = 0; i < files.length; i++) {
+ newFiles[i] = new IFSJavaFile(files[i]);
+ }
+
+ return newFiles;
+ }
+ catch (AS400SecurityException e) {
+ Trace.log(Trace.ERROR, e);
+ throw new SecurityException(e);
+ }
+ catch (IOException e) {
+ if (Trace.traceOn_) Trace.log(Trace.ERROR, e);
+ return new IFSJavaFile[0];
+ }
+ }
+
+ /**
+ * Lists the files in this IFSJavaFile directory that match pattern. With the use of this function, attribute
+ * information is cached and will not be refreshed from the IBM i system. This means attribute information may
+ * become inconsistent with the IBM i system.
+ *
+ * @param pattern The pattern that all filenames must match. Acceptable characters are wildcards (* - matches
+ * multiple characters) and question marks (? - matches one character).
+ *
+ * @return An array of object names in the directory that match the pattern. This list does not include the current
+ * directory or the parent directory. If this IFSJavaFile is not a directory, null is returned. If this
+ * IFSJavaFile is an empty directory, or the pattern does not match any files, an empty string array is
+ * returned.
+ * @exception SecurityException If the user is denied access to the file.
+ * @see #list(String)
+ **/
+ public File[] listFiles(String pattern) throws SecurityException
+ {
+ if (pattern == null)
+ throw new NullPointerException("pattern");
+
+ return listFiles(null, pattern);
+ }
+
+ /**
+ * Lists the file system roots for the integrated file system of the IBM i system. The IBM i integrated file system
+ * has only one root -- "/".
+ *
+ * @return An array of IFSJavaFile objects that represent the file system roots of the integrated file system of the
+ * IBM i system. Since the IBM i integrated file system has only one root, the returned array contains only
+ * one element.
+ **/
+ public static File[] listRoots()
+ {
+ IFSJavaFile[] roots = new IFSJavaFile[1];
+ roots[0] = new IFSJavaFile(File.separator);
+ return roots;
+ }
+
+ // convert return code to string for mri file
+ private String mapRC(int returnCode)
+ {
+ if (returnCode == IFSReturnCodeRep.ACCESS_DENIED_TO_DIR_ENTRY)
+ return "EXC_ACCESS_DENIED";
+ else if (returnCode == IFSReturnCodeRep.ACCESS_DENIED_TO_REQUEST)
+ return "EXC_REQUEST_DENIED";
+
+ return "EXC_UNKNOWN";
+ }
+
+ /**
+ * Creates a directory whose path name is specified by this IFSJavaFile.
+ *
+ *
+ * @return true
if the directory could be created; false
otherwise.
+ * @exception SecurityException If the user is denied access to the file.
+ **/
+ @Override
+ public boolean mkdir() throws SecurityException
+ {
+ int returnCode = IFSReturnCodeRep.FILE_NOT_FOUND;
+ try {
+ returnCode = ifsFile_.mkdir0(ifsFile_.getAbsolutePath());
+ }
+ catch (AS400SecurityException e) {
+ Trace.log(Trace.ERROR, e);
+ throw new SecurityException(e);
+ }
+ catch (IOException e) {
+ if (Trace.traceOn_) Trace.log(Trace.ERROR, e);
+ return false;
+ }
+
+ return (returnCode == IFSReturnCodeRep.SUCCESS);
+ }
+
+ /**
+ * Creates a directory whose path name is specified by this IFSJavaFile, including any necessary parent directories.
+ *
+ * @return true
if the directory (or directories) could be created; false
otherwise.
+ * @exception SecurityException If the user is denied access to the file.
+ **/
+ @Override
+ public boolean mkdirs() throws SecurityException
+ {
+ int returnCode = IFSReturnCodeRep.FILE_NOT_FOUND;
+ try {
+ returnCode = ifsFile_.mkdirs0();
+ }
+ catch (AS400SecurityException e) {
+ Trace.log(Trace.ERROR, e);
+ throw new SecurityException(e);
+ }
+ catch (IOException e) {
+ if (Trace.traceOn_) Trace.log(Trace.ERROR, e);
+ return false;
+ }
+
+ return (returnCode == IFSReturnCodeRep.SUCCESS);
+ }
+
+ /**
+ * Renames the IFSJavaFile to have the path name of dest. Wildcards are not permitted in this file name.
+ *
+ * @param dest The new filename.
+ *
+ * @return true
if the renaming succeeds; false
otherwise.
+ * @exception SecurityException If the user is denied access to the file.
+ **/
+ public boolean renameTo(IFSJavaFile dest) throws SecurityException
+ {
+ if (dest == null)
+ throw new NullPointerException("dest");
+
+ int returnCode = IFSReturnCodeRep.FILE_NOT_FOUND;
+ IFSFile lFile = new IFSFile();
+
+ try
+ {
+ lFile.setSystem(dest.getSystem());
+ String destPath = dest.getPath(); // @P2A
+ lFile.setPath(replace_ ? destPath.replace(separatorChar, AS400_SEPARATOR) : destPath);
+ returnCode = ifsFile_.renameTo0(lFile);
+ }
+ catch (AS400SecurityException e) {
+ Trace.log(Trace.ERROR, e);
+ throw new SecurityException(e);
+ }
+ catch (PropertyVetoException e) {
+ } // will never happen
+ catch (IOException e) {
+ if (Trace.traceOn_)
+ Trace.log(Trace.ERROR, e);
+ return false;
+ }
+
+ return (returnCode == IFSReturnCodeRep.SUCCESS);
+ }
+
+ /**
+ * Renames the IFSJavaFile to have the path name of dest. Wildcards are not permitted in this file name.
+ *
+ * @param dest An object specifying the new filename. If this object is not an IFSJavaFile, the rename will fail.
+ *
+ * @return true
if the renaming succeeds; false
otherwise.
+ * @exception SecurityException If the user is denied access to the file.
+ **/
+ @Override
+ public boolean renameTo(File dest) throws SecurityException
+ {
+ try {
+ return renameTo((IFSJavaFile) dest);
+ }
+ catch (ClassCastException e) {
+ Trace.log(Trace.ERROR, e);
+ return false;
+ }
+ }
+
+ /**
+ * Sets the last modified time of the file named by this IFSJavaFile object.
+ *
+ * @param time The new last modified time, measured in milliseconds since 00:00:00 GMT, January 1, 1970. If -1, sets
+ * the last modified time to the current system time.
+ * @return true
if the time is set; false
otherwise.
+ * @exception SecurityException If the user is denied access to the file.
+ **/
+ @Override
+ public boolean setLastModified(long time) throws SecurityException
+ {
+ try {
+ return ifsFile_.setLastModified0(time);
+ }
+ catch (AS400SecurityException e) {
+ Trace.log(Trace.ERROR, e);
+ throw new SecurityException(e);
+ }
+ catch (IOException e) {
+ if (Trace.traceOn_) Trace.log(Trace.ERROR, e);
+ return false;
+ }
+ }
+
+ /**
+ * Sets the length of the file named by this IFSJavaFile object. The file can be made larger or smaller. If the file
+ * is made larger, the contents of the new bytes of the file are undetermined.
+ *
+ * @param length The new length, in bytes.
+ * @return true if successful; false otherwise.
+ * @exception SecurityException If the user is denied access to the file.
+ **/
+ public boolean setLength(int length) throws SecurityException
+ {
+ try {
+ return ifsFile_.setLength0(length);
+ }
+ catch (AS400SecurityException e) {
+ Trace.log(Trace.ERROR, e);
+ throw new SecurityException(e);
+ }
+ catch (IOException e) {
+ if (Trace.traceOn_) Trace.log(Trace.ERROR, e);
+ return false;
+ }
+ }
+
+ /**
+ * Sets the path for this IFSJavaFile.
+ *
+ * @param path The absolute file path.
+ *
+ * @return true
if the path was set; false
otherwise.
+ **/
+ public boolean setPath(String path)
+ {
+ if (path == null)
+ throw new NullPointerException("path");
+
+ try {
+ ifsFile_.setPath(replace_ ? path.replace(separatorChar, AS400_SEPARATOR) : path);
+ absolute_ = isAbsolutePath(path);
+ }
+ catch (PropertyVetoException e) {
+ } // will never happen
+
+ return true;
+ }
+
+ /**
+ * Sets the pattern-matching behavior used when files are listed by any of the list() or
+ * listFiles() methods. The default is PATTERN_POSIX.
+ *
+ * @param patternMatching Either {@link IFSFile#PATTERN_POSIX PATTERN_POSIX}, {@link IFSFile#PATTERN_POSIX_ALL
+ * PATTERN_POSIX_ALL}, or {@link IFSFile#PATTERN_OS2 PATTERN_OS2}
+ * @throws IOException If an error occurs while communicating with the system.
+ *
+ * @exception ConnectionDroppedException If the connection is dropped unexpectedly.
+ * @exception ExtendedIOException If an error occurs while communicating with the system.
+ * @exception ServerStartupException If the host server cannot be started.
+ **/
+ public void setPatternMatching(int patternMatching) throws IOException {
+ ifsFile_.setPatternMatching(patternMatching);
+ }
+
+ /**
+ * Marks the file named by this IFSJavaFile object so that only read operations are allowed. On the IBM i system, a
+ * file is marked read only by setting the read only attribute of the file.
+ *
+ * @return true
if the read only attribute is set; false
otherwise.
+ * @exception SecurityException If the user is denied access to the file.
+ **/
+ @Override
+ public boolean setReadOnly() throws SecurityException
+ {
+ try {
+ return ifsFile_.setReadOnly0(true);
+ }
+ catch (AS400SecurityException e) {
+ Trace.log(Trace.ERROR, e);
+ throw new SecurityException(e);
+ }
+ catch (IOException e) {
+ if (Trace.traceOn_) Trace.log(Trace.ERROR, e);
+ return false;
+ }
+ }
+
+ /**
+ * Sets the system.
+ *
+ * @param system The system object.
+ *
+ * @return true
if the system was set; false
otherwise.
+ **/
+ public boolean setSystem(AS400 system)
+ {
+ if (system == null)
+ throw new NullPointerException("system");
+
+ try {
+ ifsFile_.setSystem(system);
+ }
+ catch (PropertyVetoException e) {
+ } // will never happen
+
+ return true;
+ }
+
+ /**
+ * A convenience method to set the owner's execute permission for this abstract pathname. This method is supported
+ * for IBM i V5R1 and higher. For older releases, it simply returns false.
+ *
+ * An invocation of this method of the form file.setExcutable(arg) behaves in exactly the same way as the + * invocation file.setExecutable(arg, true) + * + * @param executable If true, sets the access permission to allow execute operations; if false, to disallow execute + * operations. + * @return true if and only if the operation succeeded. The operation will fail if the user does not have permission + * to change the access permissions of this abstract pathname. + * @exception SecurityException If the user is denied access to the file. + **/ + @Override + public boolean setExecutable(boolean executable) throws SecurityException { + return setExecutable(executable, true); + } + + /** + * Sets the owner's or everybody's execute permission for this abstract pathname. This method is supported for IBM i + * V5R1 and higher. For older releases, it simply returns false. + * + * @param executable If true, sets the access permission to allow execute operations; if false, to disallow execute + * operations. + * @param ownerOnly If true, the execute permission applies only to the owner's execute permission; otherwise, it + * applies to everybody. + * @return true if and only if the operation succeeded. The operation will fail if the user does not have permission + * to change the access permissions of this abstract pathname. + * @exception SecurityException If the user is denied access to the file. + **/ + @Override + public boolean setExecutable(boolean executable, boolean ownerOnly) throws SecurityException + { + try { + return ifsFile_.setAccess(IFSFile.ACCESS_EXECUTE, executable, ownerOnly); + } + catch (AS400SecurityException e) { + Trace.log(Trace.ERROR, e); + throw new SecurityException(e); + } + catch (IOException e) { + if (Trace.traceOn_) Trace.log(Trace.ERROR, e); + return false; + } + } + + /** + * A convenience method to set the owner's read permission for this abstract pathname. This method is supported for + * IBM i V5R1 and higher. For older releases, it simply returns false. + *
+ * An invocation of this method of the form file.setReadable(arg) behaves in exactly the same way as the + * invocation file.setReadable(arg, true) + * + * @param readable If true, sets the access permission to allow read operations; if false, to disallow read + * operations. + * @return true if and only if the operation succeeded. The operation will fail if the user does not have permission + * to change the access permissions of this abstract pathname. + * @exception SecurityException If the user is denied access to the file. + **/ + @Override + public boolean setReadable(boolean readable) throws SecurityException { + return setReadable(readable, true); + } + + /** + * Sets the owner's or everybody's read permission for this abstract pathname. This method is supported for IBM i + * V5R1 and higher. For older releases, it simply returns false. + * + * @param readable If true, sets the access permission to allow read operations; if false, to disallow read + * operations. + * @param ownerOnly If true, the read permission applies only to the owner's read permission; otherwise, it applies + * to everybody. + * @return true if and only if the operation succeeded. The operation will fail if the user does not have permission + * to change the access permissions of this abstract pathname. + * @exception SecurityException If the user is denied access to the file. + **/ + @Override + public boolean setReadable(boolean readable, boolean ownerOnly) throws SecurityException + { + try { + return ifsFile_.setAccess(IFSFile.ACCESS_READ, readable, ownerOnly); + } + catch (AS400SecurityException e) { + Trace.log(Trace.ERROR, e); + throw new SecurityException(e); + } + catch (IOException e) { + if (Trace.traceOn_) Trace.log(Trace.ERROR, e); + return false; + } + } + + /** + * A convenience method to set the owner's write permission for this abstract pathname. This method is supported for + * IBM i V5R1 and higher. For older releases, it simply returns false. + *
+ * An invocation of this method of the form file.setWritable(arg) behaves in exactly the same way as the
+ * invocation file.setWritable(arg, true)
+ *
+ * @param writable If true, sets the access permission to allow write operations; if false to disallow write
+ * operations
+ * @return true if and only if the operation succeeded. The operation will fail if the user does not have permission
+ * to change the access permissions of this abstract pathname.
+ * @exception SecurityException If the user is denied access to the file.
+ **/
+ @Override
+ public boolean setWritable(boolean writable) throws SecurityException {
+ return setWritable(writable, true);
+ }
+
+ /**
+ * Sets the owner's or everybody's write permission for this abstract pathname. This method is supported for IBM i
+ * V5R1 and higher. For older releases, it simply returns false.
+ *
+ * @param writable If true, sets the access permission to allow write operations; if false, to disallow write
+ * operations.
+ * @param ownerOnly If true, the write permission applies only to the owner's write permission; otherwise, it
+ * applies to everybody.
+ * @return true if and only if the operation succeeded. The operation will fail if the user does not have permission
+ * to change the access permissions of this abstract pathname.
+ * @exception SecurityException If the user is denied access to the file.
+ **/
+ @Override
+ public boolean setWritable(boolean writable, boolean ownerOnly) throws SecurityException
+ {
+ try {
+ return ifsFile_.setAccess(IFSFile.ACCESS_WRITE, writable, ownerOnly);
+ }
+ catch (AS400SecurityException e) {
+ Trace.log(Trace.ERROR, e);
+ throw new SecurityException(e);
+ }
+ catch (IOException e) {
+ if (Trace.traceOn_) Trace.log(Trace.ERROR, e);
+ return false;
+ }
+ }
+
+ /**
+ * Returns a string representation of this object.
+ *
+ * @return A string giving the path name of this object.
+ **/
+ @Override
+ public String toString()
+ {
+ if (replace_)
+ return ifsFile_.toString().replace(AS400_SEPARATOR, separatorChar);
+
+ return ifsFile_.toString();
+ }
+
+ /**
+ * Converts the abstract path name into a file:
URL. The IBM i file/directory will be accessed and if
+ * it is a directory the resulting URL will end with the IBM i separator character (forward slash). The system name
+ * will be obtained from the AS400 object. If the path name or AS400 object has not been set, a NullPointerException
+ * will be thrown.
+ *
+ * @return The URL form of the abstract path name of this object.
+ *
+ * @exception MalformedURLException If the URL cannot be formed.
+ *
+ **/
+ @Override
+ public URL toURL() throws MalformedURLException
+ {
+ String objectName = null;
+
+ if (isDirectory())
+ objectName = getAbsolutePath() + separatorChar;
+ else
+ objectName = getAbsolutePath();
+
+ return new URL(URL_PROTOCOL, getSystem().getSystemName(), objectName);
}
- else return false;
- }
-
-/**
- * Indicates if the IFSJavaFile is a directory.
- *
- * @return true
if the IFSJavaFile exists and is a directory; false
otherwise.
- * @exception SecurityException If the user is denied access to the file.
-**/
- public boolean isDirectory()
- throws SecurityException
- {
- int returnCode = IFSReturnCodeRep.FILE_NOT_FOUND;
- try
- {
- returnCode = ifsFile_.isDirectory0();
- if (returnCode == IFSReturnCodeRep.ACCESS_DENIED_TO_DIR_ENTRY
- || returnCode == IFSReturnCodeRep.ACCESS_DENIED_TO_REQUEST)
- {
- throw new SecurityException(ResourceBundleLoader.getText(mapRC(returnCode)));
- }
- }
- catch (AS400SecurityException e)
- {
- Trace.log(Trace.ERROR, e);
- throw new SecurityException(e);
- }
- catch (IOException e)
- {
- if (Trace.traceOn_) Trace.log(Trace.ERROR, e);
- return false;
- }
- return (returnCode == IFSReturnCodeRep.SUCCESS);
- }
-
-/**
- * Indicates if the IFSJavaFile is a "normal" file.
- * A file is "normal" if it is not a directory or a container of other objects.
- *
- * @return true
if the specified file exists and is a "normal" file; false
otherwise.
- * @exception SecurityException If the user is denied access to the file.
-**/
- public boolean isFile()
- throws SecurityException
- {
- int returnCode = IFSReturnCodeRep.FILE_NOT_FOUND;
- try
- {
- returnCode = ifsFile_.isFile0();
- if (returnCode == IFSReturnCodeRep.ACCESS_DENIED_TO_DIR_ENTRY
- || returnCode == IFSReturnCodeRep.ACCESS_DENIED_TO_REQUEST)
- {
- throw new SecurityException(ResourceBundleLoader.getText(mapRC(returnCode)));
- }
- }
- catch (AS400SecurityException e)
- {
- Trace.log(Trace.ERROR, e);
- throw new SecurityException(e);
- }
- catch (IOException e)
- {
- if (Trace.traceOn_) Trace.log(Trace.ERROR, e);
- return false;
- }
- return (returnCode == IFSReturnCodeRep.SUCCESS);
- }
-
-
-/**
- * Indicates if the IFSJavaFile is hidden. On the IBM i system, a file is
- * hidden if its hidden attribute is set.
- *
- * @return true
if the file is hidden; false
otherwise.
- * @exception SecurityException If the user is denied access to the file.
-**/
- public boolean isHidden()
- throws SecurityException
- {
- try
- {
- return ifsFile_.isHidden();
- }
- catch (AS400SecurityException e)
- {
- throw new SecurityException(e);
- }
- catch (IOException e)
- {
- if (Trace.traceOn_) Trace.log(Trace.ERROR, e);
- return false;
- }
- }
-
-
-/**
- * Indicates the time that the IFSJavaFile was last modified.
- *
- * @return The time (measured in milliseconds since
- * 01/01/1970 00:00:00 GMT) that the IFSJavaFile was
- * last modified, or 0
if it does not exist.
- * @exception SecurityException If the user is denied access to the file.
-**/
- public long lastModified()
- throws SecurityException
- {
- try
- {
- return ifsFile_.lastModified0();
- }
- catch (AS400SecurityException e)
- {
- Trace.log(Trace.ERROR, e);
- throw new SecurityException(e);
- }
- catch (IOException e)
- {
- if (Trace.traceOn_) Trace.log(Trace.ERROR, e);
- return 0L;
- }
- }
-
-/**
- * Indicates the length of this IFSJavaFile.
- *
- * @return The length, in bytes, of the IFSJavaFile,
- * or 0
((IFSJavaFile) if it does not exist.
- * @exception SecurityException If the user is denied access to the file.
-**/
- public long length()
- throws SecurityException
- {
- try
- {
- // For the listFiles() methods, the IFS File Server reports the length of
- // a symbolic link rather than the length of the target object. Circumvention
- // is to clear the ifsFile cache and re-retrieve the attributes from the IFS
- // File Server. When not using wild-cards the IFS File Server always follows
- // symlnk objects and returns the attributes of the target object.
- if (ifsFile_.isSymbolicLink()) //@B1A
- ifsFile_.clearCachedAttributes(); //@B1A
- return ifsFile_.length0();
- }
- catch (AS400SecurityException e)
- {
- Trace.log(Trace.ERROR, e);
- throw new SecurityException(e);
- }
- catch (IOException e)
- {
- if (Trace.traceOn_) Trace.log(Trace.ERROR, e);
- return 0L;
- }
- }
-
-/**
- * Lists the files in this IFSJavaFile directory.
- *
- * @return An array of object names in the directory.
- * This list does not include the current directory
- * or the parent directory. If this IFSJavaFile is not
- * a directory, null is returned.
- * If this IFSJavaFile is an empty directory,
- * an empty string array is returned.
- * @see #listFiles()
- * @exception SecurityException If the user is denied access to the file.
-**/
- public String[] list()
- throws SecurityException
- {
- try
- {
- return ifsFile_.list0(null, "*");
- }
- catch (AS400SecurityException e)
- {
- Trace.log(Trace.ERROR, e);
- throw new SecurityException(e);
- }
- catch (IOException e)
- {
- if (Trace.traceOn_) Trace.log(Trace.ERROR, e);
- return new String[0];
- }
- }
-
-/**
- * Lists the files in this IFSJavaFile directory that satisfy filter.
- *
- * @param filter The file name filter.
- *
- * @return An array of object names in the directory that satisfy
- * the file name filter. This list does not include the current
- * directory or the parent directory. If this IFSJavaFile is not
- * a directory, null is returned. If this IFSJavaFile is an empty
- * directory, or the file name filter does
- * not match any files, an empty string array is returned.
- * The IFSJavaFile object passed to the file name filter object have cached
- * file attribute information. Maintaining references to these
- * IFSJavaFile objects after the list operation increases the
- * chances that their file attribute information will not be valid.
- *
- * The following example demonstrates the use of this method: - *
- * class AcceptClass implements java.io.FilenameFilter - * { - * public boolean accept(java.io.File dir, java.lang.String name) - * { - * if (name.startsWith("IFS")) - * return true; - * return false; - * } - * } - *- * @exception SecurityException If the user is denied access to the file. - * @see #listFiles(FilenameFilter) -**/ - public String[] list(FilenameFilter filter) - throws SecurityException - { - String names[] = null; - - try - { - names = ifsFile_.list0(null, "*"); - } - catch (AS400SecurityException e) - { - Trace.log(Trace.ERROR, e); - throw new SecurityException(e); - } - catch (IOException e) - { - if (Trace.traceOn_) Trace.log(Trace.ERROR, e); - return null; - } - - if (names == null) - { - return null; - } - - // Fill in the Vector - Vector v = new Vector(); - for (int i = 0 ; i < names.length ; i++) - { - if ((filter == null) || filter.accept(this, names[i])) - { - v.addElement(names[i]); - } - } - - // Create the array - String files[] = new String[v.size()]; - v.copyInto(files); - - return files; - } - -/** - * Lists the files in the IFSJavaFile directory that satisfy file name filter. - * - * @param filter The file name filter. - * - * @return An array of object names in the directory that - * satisfy the file name filter. This list does not include the current - * directory or the parent directory. - * If this IFSJavaFile is not a directory, null is - * returned. If this IFSJavaFile is an empty directory, or - * the file name filter does not match any files, an empty string array - * is returned. The IFSFile object passed to the file name filter object - * have cached file attribute information. Maintaining - * references to these IFSFile objects after the list operation - * increases the chances that their file attribute information - * will not be valid. - *
- * IFSJavaFile file = new IFSJavaFile(new AS400("enterprise"), path); - * AcceptClass ac = new AcceptClass(); - * file.list(ac); - *
- * The following example demonstrates the use of this method: - *
- * class AcceptClass implements IFSFileFilter - * { - * public boolean accept(IFSFile file) - * { - * if (file.getName().startsWith("IFS")) - * return true; - * return false; - * } - * } - *- * @exception SecurityException If the user is denied access to the file. - * @see #listFiles(IFSFileFilter) -**/ - public String[] list(IFSFileFilter filter) - throws SecurityException - { - try - { - return ifsFile_.list0(filter,"*"); - } - catch (AS400SecurityException e) - { - Trace.log(Trace.ERROR, e); - throw new SecurityException(e); - } - catch (IOException e) - { - if (Trace.traceOn_) Trace.log(Trace.ERROR, e); - return new String[0]; - } - } - -/** - * Lists the files in this IFSJavaFile directory that satisfy filter and pattern. - * - *
- * IFSJavaFile file = new IFSJavaFile(new AS400("enterprise"), path); - * AcceptClass ac = new AcceptClass(); - * file.list(ac); - * - *
Note:
If the file does not match pattern, it will not be processed by filter.
- *
- * @param filter The file name filter.
- * @param pattern The pattern that all filenames must match. Acceptable characters are
- * wildcards (* - matches multiple characters) and question marks (? - matches
- * one character). Pattern must not be null.
- *
- * @return An array of object names in the directory that satisfy the file name filter
- * and pattern. This list does not include the current directory or the parent
- * directory. If this IFSJavaFile is not a directory, null is returned. If this
- * IFSJavaFile is an empty directory, or the file name filter or pattern does not
- * match any files, an empty string array is returned. The IFSFile object passed
- * to the file name filter object have cached file attribute information.
- * Maintaining references to these IFSFile objects after the list operation
- * increases the chances that their file attribute information will not be valid.
- * @exception SecurityException If the user is denied access to the file.
- * @see #listFiles(IFSFileFilter,String)
-**/
- public String[] list(IFSFileFilter filter, String pattern)
- throws SecurityException
- {
- if (pattern == null)
- throw new NullPointerException("pattern");
-
- try
- {
- return ifsFile_.list0(filter, pattern);
- }
- catch (AS400SecurityException e)
- {
- Trace.log(Trace.ERROR, e);
- throw new SecurityException(e);
- }
- catch (IOException e)
- {
- if (Trace.traceOn_) Trace.log(Trace.ERROR, e);
- return new String[0];
- }
- }
-
-/**
- * Lists the files in this IFSJavaFile directory that match pattern.
- *
- * @param pattern The pattern that all filenames must match.
- * Acceptable characters are wildcards (* - matches
- * multiple characters) and question marks (? - matches
- * one character).
- *
- * @return An array of object names in the directory that match
- * the pattern. This list does not include the current
- * directory or the parent directory. If this IFSJavaFile
- * is not a directory, null is returned. If this IFSJavaFile
- * is an empty directory, or the pattern does not match any
- * files, an empty string array is returned.
- * @exception SecurityException If the user is denied access to the file.
- * @see #listFiles(String)
-**/
- public String[] list(String pattern)
- throws SecurityException
- {
- if (pattern == null)
- throw new NullPointerException("pattern");
-
- try
- {
- return ifsFile_.list0(null,pattern);
- }
- catch (AS400SecurityException e)
- {
- Trace.log(Trace.ERROR, e);
- throw new SecurityException(e);
- }
- catch (IOException e)
- {
- if (Trace.traceOn_) Trace.log(Trace.ERROR, e);
- return new String[0];
- }
- }
-
-
-//@A3A Added support for IFSFile.listFiles().
-/**
- * Lists the files in this IFSJavaFile directory.
- * With the use of this function, attribute information is cached and
- * will not be refreshed from the IBM i system. This means attribute information may
- * become inconsistent with the IBM i system.
- * @return An array of objects in the directory.
- * This list does not include the current directory
- * or the parent directory. If this IFSJavaFile is not
- * a directory, null is returned.
- * If this IFSJavaFile is an empty directory,
- * an empty object array is returned.
- * @exception SecurityException If the user is denied access to the file.
- * @see #list()
-**/
- public File[] listFiles()
- throws SecurityException
- {
- return listFiles(null,"*");
- }
-
-//@A3A Added support for IFSFile.listFiles().
-/**
- * Lists the files in this IFSJavaFile directory that satisfy filter.
- * With the use of this function, attribute information is cached and
- * will not be refreshed from the IBM i system. This means attribute information may
- * become inconsistent with the IBM i system.
- *
- * @param filter The file name filter.
- *
- * @return An array of objects in the directory that satisfy
- * the file name filter. This list does not include the current
- * directory or the parent directory. If this IFSJavaFile is not
- * a directory, null is returned. If this IFSJavaFile is an empty
- * directory, or the file name filter does
- * not match any files, an empty object array is returned.
- * The IFSJavaFile object passed to the file name filter object has cached
- * file attribute information. Maintaining references to these
- * IFSJavaFile objects after the list operation increases the
- * chances that their file attribute information will not be valid.
- *
- * The following example demonstrates the use of this method: - *
- * class AcceptClass implements java.io.FilenameFilter - * { - * public boolean accept(java.io.File dir, java.lang.String name) - * { - * if (name.startsWith("IFS")) - * return true; - * return false; - * } - * } - *- * @exception SecurityException If the user is denied access to the file. - * @see #list(FilenameFilter) -**/ - public File[] listFiles(FilenameFilter filter) - throws SecurityException - { - IFSFile[] files = null; - try - { - files = ifsFile_.listFiles0(null, "*"); // @D2C @C3C - } - catch (AS400SecurityException e) - { - Trace.log(Trace.ERROR, e); - throw new SecurityException(e); - } - catch (IOException e) - { - if (Trace.traceOn_) Trace.log(Trace.ERROR, e); - return null; - } - - if (files == null) - { - return null; - } - - // Fill in the Vector - Vector v = new Vector(); - for (int i = 0 ; i < files.length ; i++) - { - if ((filter == null) || filter.accept(this, files[i].getName())) - { - //v.addElement(files[i]); // @A6d - v.addElement(new IFSJavaFile(files[i])); // @A6a - } - } - - // Create the array - IFSJavaFile newFiles[] = new IFSJavaFile[v.size()]; // @A6c -/* @A6d - for (int i = 0; i < files.length; i++) - { - newFiles[i] = new IFSJavaFile(files[i]); - } -*/ - v.copyInto(newFiles); // @A6a - - return newFiles; - } - -// @A7a -/** - * Lists the files in this IFSJavaFile directory that satisfy filter. - * With the use of this function, attribute information is cached and - * will not be refreshed from the IBM i system. This means attribute information may - * become inconsistent with the IBM i system. - * - * @param filter The file filter. - * - * @return An array of objects in the directory that satisfy - * the file filter. This list does not include the current - * directory or the parent directory. If this IFSJavaFile is not - * a directory, null is returned. If this IFSJavaFile is an empty - * directory, or the file filter does - * not match any files, an empty object array is returned. - * The IFSJavaFile object passed to the file filter object has cached - * file attribute information. Maintaining references to these - * IFSJavaFile objects after the list operation increases the - * chances that their file attribute information will not be valid. - *
- * IFSJavaFile file = new IFSJavaFile(new AS400("enterprise"), path); - * AcceptClass ac = new AcceptClass(); - * file.listFiles(ac); - *
- * The following example demonstrates the use of this method: - *
- * class AcceptClass implements java.io.FileFilter - * { - * public boolean accept(java.io.File file) - * { - * if (file.getName().startsWith("IFS")) - * return true; - * return false; - * } - * } - *- * @exception SecurityException If the user is denied access to the file. -**/ - public File[] listFiles(FileFilter filter) - throws SecurityException - { - IFSFile[] files = null; - try - { - files = ifsFile_.listFiles0(null, "*"); // @C3C - } - catch (AS400SecurityException e) - { - Trace.log(Trace.ERROR, e); - throw new SecurityException(e); - } - catch (IOException e) - { - if (Trace.traceOn_) Trace.log(Trace.ERROR, e); - return null; - } - - if (files == null) - { - return null; - } - - // Fill in the Vector - Vector v = new Vector(); - for (int i = 0 ; i < files.length ; i++) - { - IFSJavaFile file = new IFSJavaFile(files[i]); - if ((filter == null) || filter.accept(file)) - { - v.addElement(file); - } - } - - // Create the array - IFSJavaFile newFiles[] = new IFSJavaFile[v.size()]; - v.copyInto(newFiles); - - return newFiles; - } - -//@A3A Added support for IFSFile.listFiles(). -/** - * Lists the files in the IFSJavaFile directory that satisfy file name filter. - * With the use of this function, attribute information is cached and - * will not be refreshed from the IBM i system. This means attribute information may - * become inconsistent with the IBM i system. - * @param filter The file name filter. - * - * @return An array of objects in the directory that - * satisfy the file name filter. This list does not include the current - * directory or the parent directory. - * If this IFSJavaFile is not a directory, null is - * returned. If this IFSJavaFile is an empty directory, or - * the file name filter does not match any files, an empty object array - * is returned. The IFSFile object passed to the file name filter object - * has cached file attribute information. Maintaining - * references to these IFSFile objects after the list operation - * increases the chances that their file attribute information - * will not be valid. - *
- * IFSJavaFile file = new IFSJavaFile(new AS400("enterprise"), path); - * AcceptClass ac = new AcceptClass(); - * file.listFiles(ac); - *
- * The following example demonstrates the use of this method: - *
- * class AcceptClass implements IFSFileFilter - * { - * public boolean accept(IFSFile file) - * { - * if (file.getName().startsWith("IFS")) - * return true; - * return false; - * } - * } - *- * @exception SecurityException If the user is denied access to the file. - * @see #list(IFSFileFilter) -**/ - public File[] listFiles(IFSFileFilter filter) - throws SecurityException - { - return listFiles(filter,"*"); - } - -//@A3A Added support for IFSFile.listFiles(). -/** - * Lists the files in this IFSJavaFile directory that satisfy filter and - * pattern. With the use of this function, attribute information is cached and - * will not be refreshed from the IBM i system. This means attribute information may - * become inconsistent with the IBM i system. - * - *
- * IFSJavaFile file = new IFSJavaFile(new AS400("enterprise"), path); - * AcceptClass ac = new AcceptClass(); - * file.listFiles(ac); - * - *
Note:
If the file does not match pattern, it will not be processed by filter.
- *
- * @param filter The file name filter.
- * @param pattern The pattern that all filenames must match. Acceptable characters are
- * wildcards (* - matches multiple characters) and question marks (? - matches
- * one character). Pattern must not be null.
- *
- * @return An array of objects in the directory that satisfy the file name filter
- * and pattern. This list does not include the current directory or the parent
- * directory. If this IFSJavaFile is not a directory, null is returned. If this
- * IFSJavaFile is an empty directory, or the file name filter or pattern does not
- * match any files, an empty object array is returned. The IFSFile object passed
- * to the file name filter object has cached file attribute information.
- * Maintaining references to these IFSFile objects after the list operation
- * increases the chances that their file attribute information will not be valid.
- * @exception SecurityException If the user is denied access to the file.
- * @see #list(IFSFileFilter,String)
-**/
- public File[] listFiles(IFSFileFilter filter, String pattern)
- throws SecurityException
- {
- if (pattern == null)
- throw new NullPointerException("pattern");
-
- try
- {
- IFSFile files[] = ifsFile_.listFiles0(filter,pattern); // @D2C @C3C
- IFSJavaFile newFiles[] = new IFSJavaFile[files.length];
- for (int i = 0; i < files.length; i++)
- {
- newFiles[i] = new IFSJavaFile(files[i]);
- }
- return newFiles;
- }
- catch (AS400SecurityException e)
- {
- Trace.log(Trace.ERROR, e);
- throw new SecurityException(e);
- }
- catch (IOException e)
- {
- if (Trace.traceOn_) Trace.log(Trace.ERROR, e);
- return new IFSJavaFile[0];
- }
- }
-
-//@A3A Added support for IFSFile.listFiles().
-/**
- * Lists the files in this IFSJavaFile directory that match pattern.
- * With the use of this function, attribute information is cached and
- * will not be refreshed from the IBM i system. This means attribute information may
- * become inconsistent with the IBM i system.
- *
- * @param pattern The pattern that all filenames must match.
- * Acceptable characters are wildcards (* - matches
- * multiple characters) and question marks (? - matches
- * one character).
- *
- * @return An array of object names in the directory that match
- * the pattern. This list does not include the current
- * directory or the parent directory. If this IFSJavaFile
- * is not a directory, null is returned. If this IFSJavaFile
- * is an empty directory, or the pattern does not match any
- * files, an empty string array is returned.
- * @exception SecurityException If the user is denied access to the file.
- * @see #list(String)
-**/
- public File[] listFiles(String pattern)
- throws SecurityException
- {
- if (pattern == null)
- throw new NullPointerException("pattern");
-
- return listFiles(null, pattern);
- }
-
-
-/**
- * Lists the file system roots for the integrated file system
- * of the IBM i system. The IBM i integrated file system has
- * only one root -- "/".
- *
- * @return An array of IFSJavaFile objects that represent the
- * file system roots of the integrated file system
- * of the IBM i system. Since the IBM i integrated file system
- * has only one root, the returned
- * array contains only one element.
-**/
- public static File[] listRoots()
- {
- IFSJavaFile[] roots = new IFSJavaFile[1];
- //roots[0] = new IFSJavaFile(IFSFile.separator); // @A6d
- roots[0] = new IFSJavaFile(File.separator); // @A6c
- return roots;
- }
-
-
-
-// convert return code to string for mri file
- private String mapRC(int returnCode)
- {
- if (returnCode== IFSReturnCodeRep.ACCESS_DENIED_TO_DIR_ENTRY)
- {
- return "EXC_ACCESS_DENIED";
- } else
- if (returnCode == IFSReturnCodeRep.ACCESS_DENIED_TO_REQUEST)
- {
- return "EXC_REQUEST_DENIED";
- }
- return "EXC_UNKNOWN"; // Bad return code was provided.
- }
-
-/**
- * Creates a directory whose path name
- * is specified by this IFSJavaFile.
-
- *
- * @return true
if the directory could be created;
- * false
otherwise.
- * @exception SecurityException If the user is denied access to the file.
-**/
- public boolean mkdir()
- throws SecurityException
- {
- int returnCode = IFSReturnCodeRep.FILE_NOT_FOUND;
- try
- {
- returnCode = ifsFile_.mkdir0(ifsFile_.getAbsolutePath());
- }
- catch (AS400SecurityException e)
- {
- Trace.log(Trace.ERROR, e);
- throw new SecurityException(e);
- }
- catch (IOException e)
- {
- if (Trace.traceOn_) Trace.log(Trace.ERROR, e);
- return false;
- }
- return (returnCode == IFSReturnCodeRep.SUCCESS);
- }
-
-/**
- * Creates a directory whose path name is
- * specified by this IFSJavaFile, including any necessary
- * parent directories.
- *
- * @return true
if the directory (or directories) could be
- * created; false
otherwise.
- * @exception SecurityException If the user is denied access to the file.
-**/
- public boolean mkdirs()
- throws SecurityException
- {
- int returnCode = IFSReturnCodeRep.FILE_NOT_FOUND;
- try
- {
- returnCode = ifsFile_.mkdirs0();
- }
- catch (AS400SecurityException e)
- {
- Trace.log(Trace.ERROR, e);
- throw new SecurityException(e);
- }
- catch (IOException e)
- {
- if (Trace.traceOn_) Trace.log(Trace.ERROR, e);
- return false;
- }
- return (returnCode == IFSReturnCodeRep.SUCCESS);
- }
-
-/**
- * Renames the IFSJavaFile to have the path name of dest.
- * Wildcards are not permitted in this file name.
- *
- * @param dest The new filename.
- *
- * @return true
if the renaming succeeds;
- * false
otherwise.
- * @exception SecurityException If the user is denied access to the file.
-**/
- public boolean renameTo(IFSJavaFile dest)
- throws SecurityException
- {
- if (dest == null)
- throw new NullPointerException("dest");
-
- int returnCode = IFSReturnCodeRep.FILE_NOT_FOUND;
- IFSFile lFile = new IFSFile();
-
- try
- {
- lFile.setSystem(dest.getSystem());
- String destPath = dest.getPath(); //@P2A
- lFile.setPath(replace_ ? destPath.replace(separatorChar, AS400_SEPARATOR) : destPath); //@P2C
- returnCode = ifsFile_.renameTo0(lFile);
- }
- catch (AS400SecurityException e)
- {
- Trace.log(Trace.ERROR, e);
- throw new SecurityException(e);
- }
- catch (PropertyVetoException e) {} // will never happen
- catch (IOException e)
- {
- if (Trace.traceOn_) Trace.log(Trace.ERROR, e);
- return false;
- }
- return (returnCode == IFSReturnCodeRep.SUCCESS);
- }
-
-// @A7a
-/**
- * Renames the IFSJavaFile to have the path name of dest.
- * Wildcards are not permitted in this file name.
- *
- * @param dest An object specifying the new filename.
- * If this object is not an IFSJavaFile, the rename will fail.
- *
- * @return true
if the renaming succeeds;
- * false
otherwise.
- * @exception SecurityException If the user is denied access to the file.
-**/
- public boolean renameTo(File dest)
- throws SecurityException
- {
- try {
- return renameTo((IFSJavaFile)dest);
- }
- catch (ClassCastException e) {
- Trace.log(Trace.ERROR, e);
- return false;
- }
- }
-
-
-/**
- * Sets the last modified time of the file named by this
- * IFSJavaFile object.
- *
- * @param time The new last modified time, measured in milliseconds since
- * 00:00:00 GMT, January 1, 1970.
- * If -1, sets the last modified time to the current system time.
- * @return true
if the time is set; false
otherwise.
- * @exception SecurityException If the user is denied access to the file.
-**/
- public boolean setLastModified(long time)
- throws SecurityException
- {
- try
- {
- return ifsFile_.setLastModified0(time);
- }
- catch (AS400SecurityException e)
- {
- Trace.log(Trace.ERROR, e);
- throw new SecurityException(e);
- }
- catch (IOException e)
- {
- if (Trace.traceOn_) Trace.log(Trace.ERROR, e);
- return false;
- }
- }
-
- // @B8a
- /**
- * Sets the length of the file named by this
- * IFSJavaFile object. The file can be made larger or smaller.
- * If the file is made larger, the contents of the new bytes
- * of the file are undetermined.
- * @param length The new length, in bytes.
- * @return true if successful; false otherwise.
- * @exception SecurityException If the user is denied access to the file.
- **/
- public boolean setLength(int length)
- throws SecurityException
- {
- try
- {
- return ifsFile_.setLength0(length);
- }
- catch (AS400SecurityException e)
- {
- Trace.log(Trace.ERROR, e);
- throw new SecurityException(e);
- }
- catch (IOException e)
- {
- if (Trace.traceOn_) Trace.log(Trace.ERROR, e);
- return false;
- }
- }
-
-
-/**
- * Sets the path for this IFSJavaFile.
- *
- * @param path The absolute file path.
- *
- * @return true
if the path was set;
- * false
otherwise.
-**/
- public boolean setPath(String path)
- {
- if (path == null)
- {
- throw new NullPointerException("path");
- }
-
- try
- {
- ifsFile_.setPath(replace_ ? path.replace(separatorChar, AS400_SEPARATOR) : path); //@P2C
- absolute_ = isAbsolutePath(path);
- }
- catch (PropertyVetoException e) {} // will never happen
- return true;
- }
-
-
- /**
- Sets the pattern-matching behavior used when files are listed by any of the list() or listFiles() methods. The default is PATTERN_POSIX.
- @param patternMatching Either {@link IFSFile#PATTERN_POSIX PATTERN_POSIX}, {@link IFSFile#PATTERN_POSIX_ALL PATTERN_POSIX_ALL}, or {@link IFSFile#PATTERN_OS2 PATTERN_OS2}
- * @throws IOException If an error occurs while communicating with the system.
-
- @exception ConnectionDroppedException If the connection is dropped unexpectedly.
- @exception ExtendedIOException If an error occurs while communicating with the system.
- @exception ServerStartupException If the host server cannot be started.
- **/
- public void setPatternMatching(int patternMatching)
- throws IOException
- {
- ifsFile_.setPatternMatching(patternMatching);
- }
-
-
-/**
- * Marks the file named by this IFSJavaFile object so that only
- * read operations are allowed. On the IBM i system, a file is marked
- * read only by setting the read only attribute of the file.
- *
- * @return true
if the read only attribute is set; false
otherwise.
- * @exception SecurityException If the user is denied access to the file.
-**/
- public boolean setReadOnly()
- throws SecurityException
- {
- try
- {
- return ifsFile_.setReadOnly0(true);
- }
- catch (AS400SecurityException e)
- {
- Trace.log(Trace.ERROR, e);
- throw new SecurityException(e);
- }
- catch (IOException e)
- {
- if (Trace.traceOn_) Trace.log(Trace.ERROR, e);
- return false;
- }
- }
-
-
-
-/**
- * Sets the system.
- *
- * @param system The system object.
- *
- * @return true
if the system was set;
- * false
otherwise.
-**/
- public boolean setSystem(AS400 system)
- {
- if (system == null)
- {
- throw new NullPointerException("system");
- }
-
- try
- {
- ifsFile_.setSystem(system);
- }
- catch (PropertyVetoException e) {} // will never happen
- return true;
- }
-
-
- /**
- A convenience method to set the owner's execute permission for this abstract pathname.
- This method is supported for IBM i V5R1 and higher. For older releases, it simply returns false.
-
- An invocation of this method of the form file.setExcutable(arg) behaves in exactly the same way as the invocation file.setExecutable(arg, true) - - @param executable If true, sets the access permission to allow execute operations; if false, to disallow execute operations. - @return true if and only if the operation succeeded. The operation will fail if the user does not have permission to change the access permissions of this abstract pathname. - @exception SecurityException If the user is denied access to the file. - **/ - public boolean setExecutable(boolean executable) - throws SecurityException - { - return setExecutable(executable, true); - } - - - /** - Sets the owner's or everybody's execute permission for this abstract pathname. - This method is supported for IBM i V5R1 and higher. For older releases, it simply returns false. - - @param executable If true, sets the access permission to allow execute operations; if false, to disallow execute operations. - @param ownerOnly If true, the execute permission applies only to the owner's execute permission; otherwise, it applies to everybody. - @return true if and only if the operation succeeded. The operation will fail if the user does not have permission to change the access permissions of this abstract pathname. - @exception SecurityException If the user is denied access to the file. - **/ - public boolean setExecutable(boolean executable, - boolean ownerOnly) - throws SecurityException - { - try - { - return ifsFile_.setAccess(IFSFile.ACCESS_EXECUTE, executable, ownerOnly); - } - catch (AS400SecurityException e) - { - Trace.log(Trace.ERROR, e); - throw new SecurityException(e); - } - catch (IOException e) - { - if (Trace.traceOn_) Trace.log(Trace.ERROR, e); - return false; - } - } - - - /** - A convenience method to set the owner's read permission for this abstract pathname. - This method is supported for IBM i V5R1 and higher. For older releases, it simply returns false. -
- An invocation of this method of the form file.setReadable(arg) behaves in exactly the same way as the invocation file.setReadable(arg, true) - - @param readable If true, sets the access permission to allow read operations; if false, to disallow read operations. - @return true if and only if the operation succeeded. The operation will fail if the user does not have permission to change the access permissions of this abstract pathname. - @exception SecurityException If the user is denied access to the file. - **/ - public boolean setReadable(boolean readable) - throws SecurityException - { - return setReadable(readable, true); - } - - - /** - Sets the owner's or everybody's read permission for this abstract pathname. - This method is supported for IBM i V5R1 and higher. For older releases, it simply returns false. - - @param readable If true, sets the access permission to allow read operations; if false, to disallow read operations. - @param ownerOnly If true, the read permission applies only to the owner's read permission; otherwise, it applies to everybody. - @return true if and only if the operation succeeded. The operation will fail if the user does not have permission to change the access permissions of this abstract pathname. - @exception SecurityException If the user is denied access to the file. - **/ - public boolean setReadable(boolean readable, - boolean ownerOnly) - throws SecurityException - { - try - { - return ifsFile_.setAccess(IFSFile.ACCESS_READ, readable, ownerOnly); - } - catch (AS400SecurityException e) - { - Trace.log(Trace.ERROR, e); - throw new SecurityException(e); - } - catch (IOException e) - { - if (Trace.traceOn_) Trace.log(Trace.ERROR, e); - return false; - } - } - - - /** - A convenience method to set the owner's write permission for this abstract pathname. - This method is supported for IBM i V5R1 and higher. For older releases, it simply returns false. -
- An invocation of this method of the form file.setWritable(arg) behaves in exactly the same way as the invocation file.setWritable(arg, true)
-
- @param writable If true, sets the access permission to allow write operations; if false to disallow write operations
- @return true if and only if the operation succeeded. The operation will fail if the user does not have permission to change the access permissions of this abstract pathname.
- @exception SecurityException If the user is denied access to the file.
- **/
- public boolean setWritable(boolean writable)
- throws SecurityException
- {
- return setWritable(writable, true);
- }
-
-
- /**
- Sets the owner's or everybody's write permission for this abstract pathname.
- This method is supported for IBM i V5R1 and higher. For older releases, it simply returns false.
-
- @param writable If true, sets the access permission to allow write operations; if false, to disallow write operations.
- @param ownerOnly If true, the write permission applies only to the owner's write permission; otherwise, it applies to everybody.
- @return true if and only if the operation succeeded. The operation will fail if the user does not have permission to change the access permissions of this abstract pathname.
- @exception SecurityException If the user is denied access to the file.
- **/
- public boolean setWritable(boolean writable,
- boolean ownerOnly)
- throws SecurityException
- {
- try
- {
- return ifsFile_.setAccess(IFSFile.ACCESS_WRITE, writable, ownerOnly);
- }
- catch (AS400SecurityException e)
- {
- Trace.log(Trace.ERROR, e);
- throw new SecurityException(e);
- }
- catch (IOException e)
- {
- if (Trace.traceOn_) Trace.log(Trace.ERROR, e);
- return false;
- }
- }
-
-
-
-/**
- * Returns a string representation of this object.
- *
- * @return A string giving the path name of this object.
-**/
- public String toString()
- {
- if (replace_)
- {
- return ifsFile_.toString().replace(AS400_SEPARATOR, separatorChar);
- }
- else {
- return ifsFile_.toString();
- }
-
-// return replace_ ? ifsFile_.toString().replace(AS400_SEPARATOR, separatorChar) : ifsFile_.toString(); //@P2C
- }
-
-
-/**
- * Converts the abstract path name into a file:
URL.
- * The IBM i file/directory will be accessed and if it is a directory the
- * resulting URL will end with the IBM i separator character
- * (forward slash). The system name will be obtained from
- * the AS400 object. If the path name or AS400 object has
- * not been set, a NullPointerException will be thrown.
- *
- * @return The URL form of the abstract path name of this object.
- *
- * @exception MalformedURLException If the URL cannot be formed.
- *
-**/
- public URL toURL() throws MalformedURLException
- {
- String objectName = null;
-
- if (isDirectory())
- objectName = getAbsolutePath() + separatorChar;
- else
- objectName = getAbsolutePath();
-
- return new URL(URL_PROTOCOL, getSystem().getSystemName(), objectName);
- }
-
-
-
}
diff --git a/src/main/java/com/ibm/as400/access/IFSListAttrsRep.java b/src/main/java/com/ibm/as400/access/IFSListAttrsRep.java
index 87c25b17..2f2231d1 100644
--- a/src/main/java/com/ibm/as400/access/IFSListAttrsRep.java
+++ b/src/main/java/com/ibm/as400/access/IFSListAttrsRep.java
@@ -18,448 +18,455 @@
/**
-List file attributes reply.
-**/
+ * List file attributes reply.
+ **/
class IFSListAttrsRep extends IFSDataStream
{
- // Used for debugging only. This should always be false for production.
- // When this is false, all debug code will theoretically compile out. @A3a
- private static final boolean DEBUG = false;
-
- static final int FILE = 1;
- static final int DIRECTORY = 2;
- static final int SYMBOLIC_LINK = 3;
- static final int AS400_OBJECT = 4;
- static final int DEVICE_FIFO = 5;
- static final int DEVICE_CHAR = 6;
- static final int DEVICE_BLOCK = 7;
- static final int SOCKET = 8;
-
- static final int FA_READONLY = 0x01; //@D1a
- static final int FA_HIDDEN = 0x02; //@D1a
- static final int FA_SYSTEM = 0x04; //@D1a
- static final int FA_DIRECTORY = 0x10;
- static final int FA_ARCHIVE = 0x20; //@D1a
-
- static final int OA_NONE = IFSListAttrsReq.OA_NONE;
- static final int OA1 = IFSListAttrsReq.OA1;
- static final int OA2 = IFSListAttrsReq.OA2;
-
- private static final int TEMPLATE_LENGTH_OFFSET = 16;
-
- private static final int HEADER_LENGTH = 20;
- private static final int LLCP_LENGTH = 6;
-
- // Note: The following offsets are valid only if template length >= 61.
- private static final int CREATE_DATE_OFFSET = 22;
- private static final int MODIFY_DATE_OFFSET = 30;
- private static final int ACCESS_DATE_OFFSET = 38;
- private static final int FILE_SIZE_OFFSET = 46;
- private static final int FIXED_ATTRS_OFFSET = 50;
- private static final int OBJECT_TYPE_OFFSET = 54;
- private static final int NUM_EXT_ATTRS_OFFSET = 56;
- private static final int BYTES_EA_NAMES_OFFSET = 58;
- private static final int BYTES_EA_VALUES_OFFSET = 62;
- private static final int VERSION_NUMBER_OFFSET = 66;
- private static final int AMOUNT_ACCESSED_OFFSET = 70;
- private static final int ACCESS_HISTORY_OFFSET = 72;
- private static final int NAME_CCSID_OFFSET = 73; // CCSID of the file/path name
- private static final int CHECKOUT_CCSID_OFFSET = 75;
- private static final int RESTART_ID_OFFSET = 77;
-
- // Additional fields if datastreamLevel >= 8:
- private static final int LARGE_FILE_SIZE_OFFSET = 81;
- private static final int SYMBOLIC_LINK_OFFSET = 91;
-
- //@AC7
- private static final int FILE_SYSTEM_TYPE_OFFSET = 89;
- private static final int UNINITIALIZED = -1;
+ // Used for debugging only. This should always be false for production.
+ private static final boolean DEBUG = false;
+
+ static final int FILE = 1;
+ static final int DIRECTORY = 2;
+ static final int SYMBOLIC_LINK = 3;
+ static final int AS400_OBJECT = 4;
+ static final int DEVICE_FIFO = 5;
+ static final int DEVICE_CHAR = 6;
+ static final int DEVICE_BLOCK = 7;
+ static final int SOCKET = 8;
+
+ static final int FA_READONLY = 0x01;
+ static final int FA_HIDDEN = 0x02;
+ static final int FA_SYSTEM = 0x04;
+ static final int FA_DIRECTORY = 0x10;
+ static final int FA_ARCHIVE = 0x20;
+
+ static final int OA_NONE = IFSListAttrsReq.OA_NONE;
+ static final int OA1 = IFSListAttrsReq.OA1;
+ static final int OA2 = IFSListAttrsReq.OA2;
+
+ private static final int TEMPLATE_LENGTH_OFFSET = 16;
+
+ private static final int HEADER_LENGTH = 20;
+ private static final int LLCP_LENGTH = 6;
+
+ // Note: The following offsets are valid only if template length >= 61.
+ private static final int CREATE_DATE_OFFSET = 22;
+ private static final int MODIFY_DATE_OFFSET = 30;
+ private static final int ACCESS_DATE_OFFSET = 38;
+ private static final int FILE_SIZE_OFFSET = 46;
+ private static final int FIXED_ATTRS_OFFSET = 50;
+ private static final int OBJECT_TYPE_OFFSET = 54;
+ private static final int NUM_EXT_ATTRS_OFFSET = 56;
+ private static final int BYTES_EA_NAMES_OFFSET = 58;
+ private static final int BYTES_EA_VALUES_OFFSET = 62;
+ private static final int VERSION_NUMBER_OFFSET = 66;
+ private static final int AMOUNT_ACCESSED_OFFSET = 70;
+ private static final int ACCESS_HISTORY_OFFSET = 72;
+ private static final int NAME_CCSID_OFFSET = 73; // CCSID of the file/path name
+ private static final int CHECKOUT_CCSID_OFFSET = 75;
+ private static final int RESTART_ID_OFFSET = 77;
+
+ // Additional fields if datastreamLevel >= 8:
+ private static final int LARGE_FILE_SIZE_OFFSET = 81;
+ private static final int SYMBOLIC_LINK_OFFSET = 91;
+
+ private static final int FILE_SYSTEM_TYPE_OFFSET = 89;
+ private static final int UNINITIALIZED = -1;
+
+ /**
+ * Construct a list file attributes reply.
+ **/
+ IFSListAttrsRep()
+ {
+ }
+ /**
+ * Generate a new instance of this type.
+ *
+ * @return a reference to the new instance
+ **/
+ public Object getNewDataStream() {
+ return new IFSListAttrsRep();
+ }
-/**
-Construct a list file attributes reply.
-**/
- IFSListAttrsRep()
- {
- }
+ /**
+ * Get the date/time that the file was last accessed.
+ *
+ * @return the date/time (measured as milliseconds since midnight January 1, 1970) of the last access
+ **/
+ long getAccessDate() {
+ return getDate(ACCESS_DATE_OFFSET);
+ }
-/**
-Generate a new instance of this type.
-@return a reference to the new instance
-**/
- public Object getNewDataStream()
- {
- return new IFSListAttrsRep();
- }
+ /**
+ * Get the CCSID value for the IFS file on the server.
+ *
+ * @return the CCSID value for the IFS file on the server
+ **/
+ int getCCSID(int datastreamLevel) {
+ // Get the 'CCSID of the object' field from the OA2 structure in the reply.
+ return getObjAttrs2().getCCSID(datastreamLevel);
+ }
-/**
-Get the date/time that the file was last accessed.
-@return the date/time (measured as milliseconds since midnight January 1, 1970) of the last access
-**/
- long getAccessDate()
- {
- return getDate(ACCESS_DATE_OFFSET);
- }
-
-
- /**
- Get the CCSID value for the IFS file on the server.
- @return the CCSID value for the IFS file on the server
- **/
- int getCCSID(int datastreamLevel) // @A1A
- {
- // Get the 'CCSID of the object' field from the OA2 structure in the reply.
- return getObjAttrs2().getCCSID(datastreamLevel);
- }
+ /**
+ * Get the date/time that the file was created.
+ *
+ * @return the date/time (measured as milliseconds since midnight January 1, 1970) of creation
+ **/
+ long getCreationDate() {
+ return getDate(CREATE_DATE_OFFSET);
+ }
-/**
-Get the date/time that the file was created.
-@return the date/time (measured as milliseconds since midnight January 1, 1970) of creation
-**/
- long getCreationDate()
- {
- return getDate(CREATE_DATE_OFFSET);
- }
+ /**
+ * Get the extended attribute values, as a hashtable.
+ *
+ * @return The extended attribute values.
+ **/
+ Hashtable getExtendedAttributeValues()
+ {
+ Hashtable results = new Hashtable();
+
+ // The offset to the start of the "optional/variable section" depends on the datastream level.
+ int optionalSectionOffset = HEADER_LENGTH + get16bit(TEMPLATE_LENGTH_OFFSET);
+
+ // Step through the optional fields, looking for the "EA list" field (code point 0x0009).
+
+ int curLL_offset = optionalSectionOffset;
+ int curLL = get32bit(curLL_offset); // list length
+ int curCP = get16bit(curLL_offset + 4); // code point
+ int eaListOffset; // offset to start of Extended Attr list
+
+ while (curCP != 0x0009 && (curLL_offset + curLL + 6 <= data_.length))
+ {
+ curLL_offset += curLL;
+ curLL = get32bit(curLL_offset);
+ curCP = get16bit(curLL_offset + 4);
+ }
+
+ if (curCP == 0x0009)
+ {
+ // We found the start of the Extended Attributes list.
+ eaListOffset = curLL_offset; // offset to "EA List Length" field
+ }
+ else
+ {
+ if (Trace.isTraceOn()) Trace.log(Trace.DIAGNOSTIC, "No Extended Attributes were returned.");
+ return results;
+ }
+
+ byte[] eaVal = null;
+ int eaCount = get16bit(eaListOffset + 6); // number of EA structures returned
+
+ if (DEBUG) System.out.println("DEBUG Number of EA structures returned: " + eaCount);
+ // Advance the offset, to point to the start of first repeating EA struct.
+ int offset = eaListOffset + 8;
-/**
-Get the extended attribute values, as a hashtable.
-@return The extended attribute values.
-**/
- Hashtable getExtendedAttributeValues()
- {
- Hashtable results = new Hashtable();
-
- // The offset to the start of the "optional/variable section" depends on the datastream level.
- int optionalSectionOffset = HEADER_LENGTH + get16bit(TEMPLATE_LENGTH_OFFSET);
-
- // Step through the optional fields, looking for the "EA list" field (code point 0x0009).
-
- int curLL_offset = optionalSectionOffset;
- int curLL = get32bit(curLL_offset); // list length
- int curCP = get16bit(curLL_offset+4); // code point
- int eaListOffset; // offset to start of Extended Attr list
- while (curCP != 0x0009 && (curLL_offset+curLL+6 <= data_.length))
- {
- curLL_offset += curLL;
- curLL = get32bit(curLL_offset);
- curCP = get16bit(curLL_offset+4);
- }
+ for (int i = 0; i < eaCount; i++)
+ {
+ int eaCcsid = get16bit(offset); // The 2-byte CCSID for the EA name.
+ int eaNameLL = get16bit(offset + 2); // The 2-byte length of the EA name.
+ // Note: eaNameLL does *not* include length of the LL field itself.
+ // int eaFlags = get16bit(offset+4); // The flags for the EA.
+ int eaValLL = get32bit(offset + 6); // The 4-byte length of the EA value.
+ // Note: eaValLL includes the 4 "mystery bytes" that precede the name.
+ byte[] eaName = new byte[eaNameLL]; // The EA name.
+ System.arraycopy(data_, offset + 10, eaName, 0, eaNameLL);
+ if (eaValLL <= 4)
+ {
+ if (DEBUG) System.out.println("DEBUG Warning: eaValLL<=4: " + eaValLL);
+ }
+ else
+ {
+ eaVal = new byte[eaValLL - 4]; // omit the 4 leading mystery bytes
+ System.arraycopy(data_, offset + 10 + eaNameLL + 4, eaVal, 0, eaValLL - 4);
+ try
+ {
+ String eaNameString = CharConverter.byteArrayToString(eaCcsid, eaName);
+ results.put(eaNameString, eaVal);
+
+ if (Trace.isTraceOn()) Trace.log(Trace.DIAGNOSTIC, "Extended Attribute returned: " + eaNameString, eaVal);
+ }
+ catch (java.io.UnsupportedEncodingException e) {
+ Trace.log(Trace.ERROR, e);
+ }
+ }
+
+ // Advance the offset, to point to the start of next EA struct.
+ offset += (10 + eaNameLL + eaValLL);
+ }
- if (curCP == 0x0009)
- {
- // We found the start of the Extended Attributes list.
- eaListOffset = curLL_offset; // offset to "EA List Length" field
+ return results;
}
- else
- {
- if (Trace.isTraceOn()) Trace.log(Trace.DIAGNOSTIC, "No Extended Attributes were returned.");
- return results; // empty hashtable
- }
- byte[] eaVal = null;
- int eaCount = get16bit(eaListOffset+6); // number of EA structures returned
- if (DEBUG) System.out.println("DEBUG Number of EA structures returned: " + eaCount);
+ /**
+ * Get the fixed attributes.
+ *
+ * @return fixed attributes
+ **/
+ int getFixedAttributes() {
+ return (get32bit(FIXED_ATTRS_OFFSET));
+ }
- // Advance the offset, to point to the start of first repeating EA struct.
- int offset = eaListOffset+8;
+ /**
+ * Get the date/time that the file was last modified.
+ *
+ * @return the date/time (measured as milliseconds since midnight January 1, 1970) of the last modification
+ **/
+ long getModificationDate() {
+ return getDate(MODIFY_DATE_OFFSET);
+ }
- for (int i=0; i