You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by ad...@apache.org on 2003/02/23 01:40:39 UTC
cvs commit: jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/tasks AbstractSyncTask.java ShowFileTask.java
adammurdoch 2003/02/22 16:40:39
Modified: vfs/src/test/org/apache/commons/vfs/provider/test
JunctionProviderConfig.java
vfs/src/test/org/apache/commons/vfs/test ContentTests.java
ProviderReadTests.java ProviderTestSuite.java
UrlTests.java
vfs/src/java/org/apache/commons/vfs FileObject.java
FileType.java Resources.properties
vfs/src/java/org/apache/commons/vfs/provider
AbstractFileObject.java DefaultFileContent.java
DelegateFileObject.java
vfs/src/java/org/apache/commons/vfs/provider/ftp
FtpFileObject.java
vfs/src/java/org/apache/commons/vfs/provider/local
LocalFile.java
vfs/src/java/org/apache/commons/vfs/provider/sftp
SftpFileObject.java
vfs/src/java/org/apache/commons/vfs/provider/smb
SmbFileObject.java
vfs/src/java/org/apache/commons/vfs/provider/url
UrlFileObject.java
vfs/src/java/org/apache/commons/vfs/provider/webdav
WebdavFileObject.java
vfs/src/java/org/apache/commons/vfs/provider/zip
ZipFileObject.java
vfs/src/java/org/apache/commons/vfs/tasks
AbstractSyncTask.java ShowFileTask.java
Log:
- FileObject.getType() no longer throws an exception if the file does not exist.
Instead, it returns FileType.IMAGINARY.
- Added a bunch of capabilities discovery methods to FileType.
- Tidied up some error methods.
Revision Changes Path
1.5 +1 -2 jakarta-commons-sandbox/vfs/src/test/org/apache/commons/vfs/provider/test/JunctionProviderConfig.java
Index: JunctionProviderConfig.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/vfs/src/test/org/apache/commons/vfs/provider/test/JunctionProviderConfig.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- JunctionProviderConfig.java 12 Feb 2003 07:56:19 -0000 1.4
+++ JunctionProviderConfig.java 23 Feb 2003 00:40:37 -0000 1.5
@@ -97,7 +97,6 @@
final FileSystem newFs = manager.createFileSystem( "vfs:" ).getFileSystem();
final String junctionPoint = "/some/dir";
newFs.addJunction( junctionPoint, baseFolder );
- newFs.addJunction( junctionPoint + "/write-tests", baseFolder.resolveFile( "write-tests/subdir" ) );
return newFs.resolveFile( junctionPoint );
}
1.4 +6 -6 jakarta-commons-sandbox/vfs/src/test/org/apache/commons/vfs/test/ContentTests.java
Index: ContentTests.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/vfs/src/test/org/apache/commons/vfs/test/ContentTests.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- ContentTests.java 13 Feb 2003 04:28:46 -0000 1.3
+++ ContentTests.java 23 Feb 2003 00:40:37 -0000 1.4
@@ -200,9 +200,9 @@
file.getChildren();
fail();
}
- catch ( FileSystemException e )
+ catch ( final FileSystemException e )
{
- assertSameMessage( "vfs.provider/list-children-no-exist.error", file, e );
+ assertSameMessage( "vfs.provider/list-children-not-folder.error", file, e );
}
// Should be able to get child by name
@@ -240,16 +240,16 @@
}
catch ( FileSystemException e )
{
- assertSameMessage( "vfs.provider/read-no-exist.error", unknownFile, e );
+ assertSameMessage( "vfs.provider/read-not-file.error", unknownFile, e );
}
try
{
content.getSize();
fail();
}
- catch ( FileSystemException e )
+ catch ( final FileSystemException e )
{
- assertSameMessage( "vfs.provider/get-size-no-exist.error", unknownFile, e );
+ assertSameMessage( "vfs.provider/get-size-not-file.error", unknownFile, e );
}
}
1.9 +4 -12 jakarta-commons-sandbox/vfs/src/test/org/apache/commons/vfs/test/ProviderReadTests.java
Index: ProviderReadTests.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/vfs/src/test/org/apache/commons/vfs/test/ProviderReadTests.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- ProviderReadTests.java 12 Feb 2003 07:56:19 -0000 1.8
+++ ProviderReadTests.java 23 Feb 2003 00:40:37 -0000 1.9
@@ -118,7 +118,7 @@
final FileInfo info = (FileInfo)queueExpected.remove( 0 );
// Check the type is correct
- assertSame( file.getType(), info.type );
+ assertSame( info.type, file.getType() );
if ( info.type == FileType.FILE )
{
@@ -163,15 +163,7 @@
// Test an unknown file
file = getReadFolder().resolveFile( "unknown-child" );
- try
- {
- file.getType();
- fail();
- }
- catch ( FileSystemException e )
- {
- assertSameMessage( "vfs.provider/get-type-no-exist.error", file, e );
- }
+ assertSame( FileType.IMAGINARY, file.getType() );
}
/**
@@ -188,7 +180,7 @@
}
catch ( FileSystemException e )
{
- assertSameMessage( "vfs.provider/read-folder.error", folder, e );
+ assertSameMessage( "vfs.provider/read-not-file.error", folder, e );
}
}
1.11 +15 -10 jakarta-commons-sandbox/vfs/src/test/org/apache/commons/vfs/test/ProviderTestSuite.java
Index: ProviderTestSuite.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/vfs/src/test/org/apache/commons/vfs/test/ProviderTestSuite.java,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- ProviderTestSuite.java 21 Feb 2003 13:18:18 -0000 1.10
+++ ProviderTestSuite.java 23 Feb 2003 00:40:37 -0000 1.11
@@ -55,20 +55,21 @@
*/
package org.apache.commons.vfs.test;
+import java.io.File;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
-import java.io.File;
import java.util.Enumeration;
import junit.extensions.TestSetup;
+import junit.framework.Test;
import junit.framework.TestSuite;
-import org.apache.commons.vfs.impl.test.VfsClassLoaderTests;
-import org.apache.commons.vfs.impl.DefaultFileSystemManager;
+import org.apache.commons.AbstractVfsTestCase;
+import org.apache.commons.vfs.FileName;
+import org.apache.commons.vfs.FileObject;
import org.apache.commons.vfs.impl.DefaultFileReplicator;
+import org.apache.commons.vfs.impl.DefaultFileSystemManager;
import org.apache.commons.vfs.impl.PrivilegedFileReplicator;
+import org.apache.commons.vfs.impl.test.VfsClassLoaderTests;
import org.apache.commons.vfs.provider.local.DefaultLocalFileProvider;
-import org.apache.commons.vfs.FileName;
-import org.apache.commons.vfs.FileObject;
-import org.apache.commons.AbstractVfsTestCase;
/**
* The suite of tests for a file system.
@@ -112,7 +113,7 @@
// Add nested tests
// TODO - move nested jar and zip tests here
// TODO - enable this again
- //addTest( new ProviderTestSuite( new JunctionProviderConfig( providerConfig ), "junction.", true ));
+ //testSuite.addTest( new ProviderTestSuite( new JunctionProviderConfig( providerConfig ), "junction.", true ));
}
}
@@ -201,8 +202,12 @@
final Enumeration tests = testSuite.tests();
while ( tests.hasMoreElements() )
{
- final AbstractProviderTestCase test = (AbstractProviderTestCase)tests.nextElement();
- test.setConfig( manager, baseFolder, readFolder, writeFolder );
+ final Test test = (Test)tests.nextElement();
+ if ( test instanceof AbstractProviderTestCase )
+ {
+ final AbstractProviderTestCase providerTestCase = (AbstractProviderTestCase)test;
+ providerTestCase.setConfig( manager, baseFolder, readFolder, writeFolder );
+ }
}
}
1.6 +2 -2 jakarta-commons-sandbox/vfs/src/test/org/apache/commons/vfs/test/UrlTests.java
Index: UrlTests.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/vfs/src/test/org/apache/commons/vfs/test/UrlTests.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- UrlTests.java 12 Feb 2003 07:56:19 -0000 1.5
+++ UrlTests.java 23 Feb 2003 00:40:38 -0000 1.6
@@ -137,7 +137,7 @@
}
catch ( final IOException e )
{
- assertSameMessage( "vfs.provider/read-no-exist.error", unknownFile, e );
+ assertSameMessage( "vfs.provider/read-not-file.error", unknownFile, e );
}
assertEquals( -1, connection.getContentLength() );
}
1.17 +3 -5 jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/FileObject.java
Index: FileObject.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/FileObject.java,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -r1.16 -r1.17
--- FileObject.java 12 Feb 2003 07:56:09 -0000 1.16
+++ FileObject.java 23 Feb 2003 00:40:38 -0000 1.17
@@ -55,7 +55,6 @@
*/
package org.apache.commons.vfs;
-import java.net.MalformedURLException;
import java.net.URL;
/**
@@ -132,7 +131,7 @@
boolean exists() throws FileSystemException;
/**
- * Determines if this file can be read (only files that exist can be read).
+ * Determines if this file can be read.
*
* @return
* <code>true</code> if this file is readable, <code>false</code> if not.
@@ -157,11 +156,10 @@
* Returns this file's type.
*
* @return
- * Either {@link FileType#FILE} or {@link FileType#FOLDER}. Never
- * returns null.
+ * One of the {@link FileType} constants. Never returns null.
*
* @throws FileSystemException
- * If the file does not exist, or on error determining the file's type.
+ * On error determining the file's type.
*/
FileType getType() throws FileSystemException;
1.7 +53 -9 jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/FileType.java
Index: FileType.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/FileType.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- FileType.java 12 Feb 2003 07:56:09 -0000 1.6
+++ FileType.java 23 Feb 2003 00:40:38 -0000 1.7
@@ -56,7 +56,7 @@
package org.apache.commons.vfs;
/**
- * An enumeration that represents a file's type.
+ * An enumerated type that represents a file's type.
*
* @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a>
* @version $Revision$ $Date$
@@ -64,32 +64,76 @@
public final class FileType
{
/**
- * A folder, which can contain other files, but does not have any data
- * content.
+ * A folder. May contain other files, and have attributes, but does not
+ * have any data content.
*/
- public static final FileType FOLDER = new FileType( "folder" );
+ public static final FileType FOLDER = new FileType( "folder", true, false, true );
/**
- * A regular file, which has data content, but cannot contain other files.
+ * A regular file. May have data content and attributes, but cannot
+ * contain other files.
*/
- public static final FileType FILE = new FileType( "file" );
+ public static final FileType FILE = new FileType( "file", false, true, true );
+
+ /**
+ * A file that does not exist. May not have data content, attributes,
+ * or contain other files.
+ */
+ public static final FileType IMAGINARY = new FileType( "imaginary", false, false, false );
private final String name;
+ private final boolean hasChildren;
+ private final boolean hasContent;
+ private final boolean hasAttrs;
- private FileType( final String name )
+ private FileType( final String name,
+ final boolean hasChildren,
+ final boolean hasContent,
+ final boolean hasAttrs )
{
this.name = name;
+ this.hasChildren = hasChildren;
+ this.hasContent = hasContent;
+ this.hasAttrs = hasAttrs;
}
- /** Returns the name of the type. */
+ /**
+ * Returns the name of this type.
+ */
public String toString()
{
return name;
}
- /** Returns the name of the type. */
+ /**
+ * Returns the name of this type.
+ */
public String getName()
{
return name;
+ }
+
+ /**
+ * Returns true if files of this type may contain other files.
+ */
+ public boolean hasChildren()
+ {
+ return hasChildren;
+ }
+
+ /**
+ * Returns true if files of this type may have data content.
+ */
+ public boolean hasContent()
+ {
+ return hasContent;
+ }
+
+ /**
+ * Returns true if files of this type may have attributes.
+ */
+ public boolean hasAttributes()
+ {
+ return hasAttrs;
}
}
1.21 +5 -8 jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/Resources.properties
Index: Resources.properties
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/Resources.properties,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -r1.20 -r1.21
--- Resources.properties 21 Feb 2003 13:08:59 -0000 1.20
+++ Resources.properties 23 Feb 2003 00:40:38 -0000 1.21
@@ -9,9 +9,7 @@
vfs.provider/set-attribute-not-supported.error=This file type does not support setting attributes.
vfs.provider/get-attribute-not-supported.error=This file type does not support getting attributes.
vfs.provider/write-not-supported.error=This file type cannot be written to.
-vfs.provider/get-type-no-exist.error=Could not determine the type of file "{0}" because it does not exist.
vfs.provider/get-type.error=Could not determine the type of file "{0}".
-vfs.provider/list-children-no-exist.error=Could not list the contents of folder "{0}" because it does not exist.
vfs.provider/list-children-not-folder.error=Could not list the contents of "{0}" because it is not a folder.
vfs.provider/list-children.error=Could not list the contents of folder "{0}".
vfs.provider/delete-read-only.error=Could not delete "{0}" because it is read-only.
@@ -21,7 +19,7 @@
vfs.provider/create-folder.error=Could not create folder "{0}".
vfs.provider/create-file.error=Could not create file "{0}".
vfs.provider/write-read-only.error=Could not write to "{0}" because it is read-only.
-vfs.provider/write-folder.error=Could not write to "{0}" because it is a folder.
+vfs.provider/write-not-file.error=Could not write to "{0}" because it is not a file.
vfs.provider/write.error=Could not write to "{0}".
vfs.provider/copy-file.error=Could not copy "{0}" to "{1}".
vfs.provider/copy-read-only.error=Could not copy {0} "{1}" to "{2}" because the destination file is read-only.
@@ -31,16 +29,15 @@
vfs.provider/check-is-readable.error=Could not determine if file "{0}" is readable.
vfs.provider/get-url.error=Could not create URL for "{0}".
vfs.provider/close.error=Could not close "{0}".
+vfs.provider/read.error=Could not read file "{0}".
+vfs.provider/read-not-readable.error=File "{0}" is not readable.
+vfs.provider/read-not-file.error=Could not read from "{0}" because it is a not a file.
# DefaultFileContent
-vfs.provider/get-size-folder.error=Could not determine the size of "{0}" because it is a folder.
-vfs.provider/get-size-no-exist.error=Could not determine the size of file "{0}" because it does not exist.
+vfs.provider/get-size-not-file.error=Could not determine the size of "{0}" because it is not a file.
vfs.provider/get-size-write.error=Could not determine the size of file "{0}" because it is being written to.
vfs.provider/get-size.error=Could not determine the size of file "{0}".
-vfs.provider/read-folder.error=Could not read from "{0}" because it is a folder.
-vfs.provider/read-no-exist.error=Could not read file "{0}" because it does not exist.
vfs.provider/read-in-use.error=Could not read file "{0}" because it is currently being written to.
-vfs.provider/read.error=Could not read file "{0}".
vfs.provider/write-in-use.error=Could not write to "{0}" because it is currently in use.
vfs.provider/get-last-modified-no-exist.error=Could not determine the last modified timestamp of "{0}" because it does not exist.
vfs.provider/get-last-modified.error=Could not determine the last modified timestamp of "{0}".
1.27 +57 -79 jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/provider/AbstractFileObject.java
Index: AbstractFileObject.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/provider/AbstractFileObject.java,v
retrieving revision 1.26
retrieving revision 1.27
diff -u -r1.26 -r1.27
--- AbstractFileObject.java 21 Feb 2003 13:16:39 -0000 1.26
+++ AbstractFileObject.java 23 Feb 2003 00:40:38 -0000 1.27
@@ -57,6 +57,7 @@
import java.io.InputStream;
import java.io.OutputStream;
+import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.security.AccessController;
@@ -74,6 +75,7 @@
import org.apache.commons.vfs.FileType;
import org.apache.commons.vfs.NameScope;
import org.apache.commons.vfs.Selectors;
+import org.apache.commons.vfs.FileUtil;
/**
* A partial file object implementation.
@@ -130,9 +132,8 @@
}
/**
- * Determines the type of this file, returns null if the file does not
- * exist. The return value of this method is cached, so the
- * implementation can be expensive.
+ * Determines the type of this file. Must not return null. The return
+ * value of this method is cached, so the implementation can be expensive.
*/
protected abstract FileType doGetType() throws Exception;
@@ -365,7 +366,7 @@
public boolean exists() throws FileSystemException
{
attach();
- return ( type != null );
+ return ( type != FileType.IMAGINARY );
}
/**
@@ -374,10 +375,6 @@
public FileType getType() throws FileSystemException
{
attach();
- if ( type == null )
- {
- throw new FileSystemException( "vfs.provider/get-type-no-exist.error", name );
- }
return type;
}
@@ -465,11 +462,7 @@
public FileObject[] getChildren() throws FileSystemException
{
attach();
- if ( type == null )
- {
- throw new FileSystemException( "vfs.provider/list-children-no-exist.error", name );
- }
- if ( type != FileType.FOLDER )
+ if ( !type.hasChildren() )
{
throw new FileSystemException( "vfs.provider/list-children-not-folder.error", name );
}
@@ -602,7 +595,7 @@
public void delete( final FileSelector selector ) throws FileSystemException
{
attach();
- if ( type == null )
+ if ( type == FileType.IMAGINARY )
{
// File does not exist
return;
@@ -664,7 +657,7 @@
// Already exists as correct type
return;
}
- if ( type != null )
+ if ( type != FileType.IMAGINARY )
{
throw new FileSystemException( "vfs.provider/create-folder-mismatched-type.error", name );
}
@@ -737,13 +730,20 @@
}
// Copy across
- if ( srcFile.getType() == FileType.FILE )
+ try
{
- copyContent( srcFile, destFile );
+ if ( srcFile.getType().hasContent() )
+ {
+ FileUtil.copyContent( srcFile, destFile );
+ }
+ else if ( srcFile.getType().hasChildren() )
+ {
+ destFile.createFolder();
+ }
}
- else
+ catch ( final IOException e )
{
- destFile.createFolder();
+ throw new FileSystemException( "vfs.provider/copy-file.error", new Object[]{srcFile, destFile}, e );
}
}
}
@@ -760,58 +760,6 @@
}
/**
- * Copies the content of another file to this file.
- */
- private static void copyContent( final FileObject srcFile,
- final FileObject destFile )
- throws FileSystemException
- {
- try
- {
- final InputStream instr = srcFile.getContent().getInputStream();
- try
- {
- // Create the output stream via getContent(), to pick up the
- // validation it does
- final OutputStream outstr = destFile.getContent().getOutputStream();
- try
- {
- final byte[] buffer = new byte[ 1024 * 4 ];
- int n = 0;
- while ( -1 != ( n = instr.read( buffer ) ) )
- {
- outstr.write( buffer, 0, n );
- }
- }
- finally
- {
- outstr.close();
- }
- }
- finally
- {
- instr.close();
- }
- }
- catch ( RuntimeException re )
- {
- throw re;
- }
- catch ( final Exception exc )
- {
- throw new FileSystemException( "vfs.provider/copy-file.error", new Object[]{srcFile, destFile}, exc );
- }
- }
-
- /**
- * Returns true if this is a Folder.
- */
- boolean isFolder()
- {
- return ( type == FileType.FOLDER );
- }
-
- /**
* Returns the file's content.
*/
public FileContent getContent() throws FileSystemException
@@ -861,6 +809,32 @@
}
/**
+ * Returns an input stream to use to read the content of the file.
+ */
+ public InputStream getInputStream() throws FileSystemException
+ {
+ attach();
+ if ( ! type.hasContent() )
+ {
+ throw new FileSystemException( "vfs.provider/read-not-file.error", name );
+ }
+ if ( !isReadable() )
+ {
+ throw new FileSystemException( "vfs.provider/read-not-readable.error", name );
+ }
+
+ // Get the raw input stream
+ try
+ {
+ return doGetInputStream();
+ }
+ catch ( final Exception exc )
+ {
+ throw new FileSystemException( "vfs.provider/read.error", name, exc );
+ }
+ }
+
+ /**
* Prepares this file for writing. Makes sure it is either a file,
* or its parent folder exists. Returns an output stream to use to
* write the content of the file to.
@@ -868,16 +842,16 @@
public OutputStream getOutputStream() throws FileSystemException
{
attach();
- if ( !isWriteable() )
+ if ( type != FileType.IMAGINARY && !type.hasContent() )
{
- throw new FileSystemException( "vfs.provider/write-read-only.error", name );
+ throw new FileSystemException( "vfs.provider/write-not-file.error", name );
}
- if ( type == FileType.FOLDER )
+ if ( !isWriteable() )
{
- throw new FileSystemException( "vfs.provider/write-folder.error", name );
+ throw new FileSystemException( "vfs.provider/write-read-only.error", name );
}
- if ( type == null )
+ if ( type == FileType.IMAGINARY )
{
// Does not exist - make sure parent does
FileObject parent = getParent();
@@ -939,6 +913,10 @@
doAttach();
attached = true;
type = doGetType();
+ if ( type == null )
+ {
+ type = FileType.IMAGINARY;
+ }
}
catch ( RuntimeException re )
{
@@ -955,7 +933,7 @@
*/
protected void endOutput() throws Exception
{
- if ( type == null )
+ if ( type == FileType.IMAGINARY )
{
// File was created
handleCreate( FileType.FILE );
@@ -999,7 +977,7 @@
if ( attached )
{
// Fix up state
- type = null;
+ type = FileType.IMAGINARY;
children = null;
// Notify subclass
@@ -1083,7 +1061,7 @@
final int index = selected.size();
// If the file is a folder, traverse it
- if ( file.getType() == FileType.FOLDER && selector.traverseDescendents( fileInfo ) )
+ if ( file.getType().hasChildren() && selector.traverseDescendents( fileInfo ) )
{
final int curDepth = fileInfo.getDepth();
fileInfo.setDepth( curDepth + 1 );
1.13 +9 -35 jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/provider/DefaultFileContent.java
Index: DefaultFileContent.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/provider/DefaultFileContent.java,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -r1.12 -r1.13
--- DefaultFileContent.java 13 Feb 2003 04:28:45 -0000 1.12
+++ DefaultFileContent.java 23 Feb 2003 00:40:38 -0000 1.13
@@ -102,15 +102,10 @@
*/
public long getSize() throws FileSystemException
{
- if ( file.isFolder() )
- {
- throw new FileSystemException( "vfs.provider/get-size-folder.error", file );
- }
-
// Do some checking
- if ( !file.exists() )
+ if ( !file.getType().hasContent() )
{
- throw new FileSystemException( "vfs.provider/get-size-no-exist.error", file );
+ throw new FileSystemException( "vfs.provider/get-size-not-file.error", file );
}
if ( state == STATE_WRITING )
{
@@ -133,7 +128,7 @@
*/
public long getLastModifiedTime() throws FileSystemException
{
- if ( !file.exists() )
+ if ( !file.getType().hasAttributes() )
{
throw new FileSystemException( "vfs.provider/get-last-modified-no-exist.error", file );
}
@@ -152,7 +147,7 @@
*/
public void setLastModifiedTime( long modTime ) throws FileSystemException
{
- if ( !file.exists() )
+ if ( !file.getType().hasAttributes() )
{
throw new FileSystemException( "vfs.provider/set-last-modified-no-exist.error", file );
}
@@ -223,34 +218,17 @@
*/
public InputStream getInputStream() throws FileSystemException
{
- if ( file.isFolder() )
- {
- throw new FileSystemException( "vfs.provider/read-folder.error", file );
- }
- if ( !file.exists() )
- {
- throw new FileSystemException( "vfs.provider/read-no-exist.error", file );
- }
if ( state == STATE_WRITING )
{
throw new FileSystemException( "vfs.provider/read-in-use.error", file );
}
// Get the raw input stream
- InputStream rawInstr;
- try
- {
- rawInstr = file.doGetInputStream();
- }
- catch ( final Exception exc )
- {
- throw new FileSystemException( "vfs.provider/read.error", new Object[]{file}, exc );
- }
-
- final FileContentInputStream instr = new FileContentInputStream( rawInstr );
- this.instrs.add( instr );
+ final InputStream instr = file.getInputStream();
+ final InputStream wrappedInstr = new FileContentInputStream( instr );
+ this.instrs.add( wrappedInstr );
state = STATE_READING;
- return instr;
+ return wrappedInstr;
}
/**
@@ -258,17 +236,13 @@
*/
public OutputStream getOutputStream() throws FileSystemException
{
- if ( file.isFolder() )
- {
- throw new FileSystemException( "vfs.provider/write-folder.error", file );
- }
if ( state != STATE_NONE )
{
throw new FileSystemException( "vfs.provider/write-in-use.error", file );
}
// Get the raw output stream
- OutputStream outstr = file.getOutputStream();
+ final OutputStream outstr = file.getOutputStream();
// Create wrapper
this.outstr = new FileContentOutputStream( outstr );
1.6 +12 -9 jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/provider/DelegateFileObject.java
Index: DelegateFileObject.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/provider/DelegateFileObject.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- DelegateFileObject.java 21 Feb 2003 13:16:39 -0000 1.5
+++ DelegateFileObject.java 23 Feb 2003 00:40:38 -0000 1.6
@@ -119,14 +119,18 @@
maybeTypeChanged( oldType );
}
+ /**
+ * Checks whether the file's type has changed, and fires the appropriate
+ * events.
+ */
private void maybeTypeChanged( final FileType oldType ) throws Exception
{
final FileType newType = doGetType();
- if ( oldType == null && newType != null )
+ if ( oldType == FileType.IMAGINARY && newType != FileType.IMAGINARY )
{
handleCreate( newType );
}
- else if ( oldType != null && newType == null )
+ else if ( oldType != FileType.IMAGINARY && newType == FileType.IMAGINARY )
{
handleDelete();
}
@@ -140,17 +144,16 @@
{
if ( file != null )
{
- if ( file.exists() )
- {
- return file.getType();
- }
+ return file.getType();
}
else if ( children.size() > 0 )
{
return FileType.FOLDER;
}
-
- return null;
+ else
+ {
+ return FileType.IMAGINARY;
+ }
}
/**
1.14 +3 -4 jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/provider/ftp/FtpFileObject.java
Index: FtpFileObject.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/provider/ftp/FtpFileObject.java,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- FtpFileObject.java 13 Feb 2003 04:28:45 -0000 1.13
+++ FtpFileObject.java 23 Feb 2003 00:40:38 -0000 1.14
@@ -208,14 +208,13 @@
{
if ( fileInfo == null )
{
- // Does not exist
- return null;
+ return FileType.IMAGINARY;
}
- if ( fileInfo.isDirectory() )
+ else if ( fileInfo.isDirectory() )
{
return FileType.FOLDER;
}
- if ( fileInfo.isFile() )
+ else if ( fileInfo.isFile() )
{
return FileType.FILE;
}
1.10 +3 -3 jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/provider/local/LocalFile.java
Index: LocalFile.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/provider/local/LocalFile.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- LocalFile.java 12 Feb 2003 07:56:15 -0000 1.9
+++ LocalFile.java 23 Feb 2003 00:40:38 -0000 1.10
@@ -118,13 +118,13 @@
{
if ( !file.exists() )
{
- return null;
+ return FileType.IMAGINARY;
}
- if ( file.isDirectory() )
+ else if ( file.isDirectory() )
{
return FileType.FOLDER;
}
- if ( file.isFile() )
+ else if ( file.isFile() )
{
return FileType.FILE;
}
1.2 +3 -2 jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/provider/sftp/SftpFileObject.java
Index: SftpFileObject.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/provider/sftp/SftpFileObject.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- SftpFileObject.java 20 Feb 2003 07:30:36 -0000 1.1
+++ SftpFileObject.java 23 Feb 2003 00:40:38 -0000 1.2
@@ -112,8 +112,9 @@
if ( attrs == null )
{
// TODO - not quite true, but ChannelSftp.stat() swallows exceptions
- return null;
+ return FileType.IMAGINARY;
}
+
if ( ( attrs.getFlags() & SftpATTRS.SSH_FILEXFER_ATTR_PERMISSIONS ) == 0 )
{
throw new FileSystemException( "vfs.provider.sftp/unknown-permissions.error" );
1.9 +4 -3 jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/provider/smb/SmbFileObject.java
Index: SmbFileObject.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/provider/smb/SmbFileObject.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- SmbFileObject.java 12 Feb 2003 07:56:16 -0000 1.8
+++ SmbFileObject.java 23 Feb 2003 00:40:39 -0000 1.9
@@ -106,16 +106,17 @@
{
if ( !file.exists() )
{
- return null;
+ return FileType.IMAGINARY;
}
- if ( file.isDirectory() )
+ else if ( file.isDirectory() )
{
return FileType.FOLDER;
}
- if ( file.isFile() )
+ else if ( file.isFile() )
{
return FileType.FILE;
}
+
throw new FileSystemException( "vfs.provider.smb/get-type.error", getName() );
}
1.6 +2 -2 jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/provider/url/UrlFileObject.java
Index: UrlFileObject.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/provider/url/UrlFileObject.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- UrlFileObject.java 12 Feb 2003 07:56:17 -0000 1.5
+++ UrlFileObject.java 23 Feb 2003 00:40:39 -0000 1.6
@@ -110,7 +110,7 @@
}
catch ( final FileNotFoundException e )
{
- return null;
+ return FileType.IMAGINARY;
}
return FileType.FILE;
1.5 +3 -3 jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/provider/webdav/WebdavFileObject.java
Index: WebdavFileObject.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/provider/webdav/WebdavFileObject.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- WebdavFileObject.java 21 Feb 2003 13:08:59 -0000 1.4
+++ WebdavFileObject.java 23 Feb 2003 00:40:39 -0000 1.5
@@ -116,7 +116,7 @@
final int status = fileSystem.getClient().executeMethod( optionsMethod );
if ( status < 200 || status > 299 )
{
- return null;
+ return FileType.IMAGINARY;
}
resource.getHttpURL().setPath( optionsMethod.getPath() );
@@ -132,7 +132,7 @@
}
if ( !exists )
{
- return null;
+ return FileType.IMAGINARY;
}
// Get the properties of the resource
1.12 +1 -1 jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/provider/zip/ZipFileObject.java
Index: ZipFileObject.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/provider/zip/ZipFileObject.java,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- ZipFileObject.java 12 Feb 2003 07:56:17 -0000 1.11
+++ ZipFileObject.java 23 Feb 2003 00:40:39 -0000 1.12
@@ -89,7 +89,7 @@
file = zipFile;
if ( file == null )
{
- type = null;
+ type = FileType.IMAGINARY;
}
}
1.8 +2 -2 jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/tasks/AbstractSyncTask.java
Index: AbstractSyncTask.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/tasks/AbstractSyncTask.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- AbstractSyncTask.java 12 Feb 2003 07:56:17 -0000 1.7
+++ AbstractSyncTask.java 23 Feb 2003 00:40:39 -0000 1.8
@@ -300,7 +300,7 @@
}
final SourceInfo src = (SourceInfo)srcFiles.get( 0 );
final FileObject srcFile = resolveFile( src.file );
- if ( !srcFile.exists() || srcFile.getType() != FileType.FILE )
+ if ( srcFile.getType() != FileType.FILE )
{
final String message =
Messages.getString( "vfs.tasks/sync.source-not-file.error", srcFile );
1.7 +3 -4 jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/tasks/ShowFileTask.java
Index: ShowFileTask.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/tasks/ShowFileTask.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- ShowFileTask.java 12 Feb 2003 07:56:18 -0000 1.6
+++ ShowFileTask.java 23 Feb 2003 00:40:39 -0000 1.7
@@ -61,7 +61,6 @@
import java.util.Date;
import org.apache.commons.vfs.FileContent;
import org.apache.commons.vfs.FileObject;
-import org.apache.commons.vfs.FileType;
import org.apache.tools.ant.BuildException;
/**
@@ -143,7 +142,7 @@
if ( file.exists() )
{
final String newPrefix = prefix + INDENT;
- if ( file.getType() == FileType.FILE )
+ if ( file.getType().hasContent() )
{
final FileContent content = file.getContent();
log( newPrefix + "Content-Length: " + content.getSize() );
@@ -154,7 +153,7 @@
logContent( file, newPrefix );
}
}
- else
+ if ( file.getType().hasChildren() )
{
final FileObject[] children = file.getChildren();
for ( int i = 0; i < children.length; i++ )
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org