You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by se...@apache.org on 2010/10/19 03:59:40 UTC
svn commit: r1024089 [1/2] - in /commons/proper/vfs/trunk:
core/src/main/java/org/apache/commons/vfs/provider/ftp/
core/src/main/java/org/apache/commons/vfs/provider/ftps/
core/src/main/java/org/apache/commons/vfs/provider/sftp/
core/src/test/java/org/...
Author: sebb
Date: Tue Oct 19 01:59:39 2010
New Revision: 1024089
URL: http://svn.apache.org/viewvc?rev=1024089&view=rev
Log:
Tab police
Modified:
commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/provider/ftp/FTPClientWrapper.java
commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/provider/ftps/FtpsClientFactory.java
commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/provider/ftps/FtpsClientWrapper.java
commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/provider/ftps/FtpsFileProvider.java
commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/provider/sftp/SftpFileObject.java
commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/AbstractVfsTestCase.java
commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs/RunTest.java
commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs/perf/FileNamePerformance.java
commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs/provider/ram/test/CustomRamProviderTest.java
commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs/provider/ram/test/RamProviderTestCase.java
commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs/provider/test/JunctionProviderConfig.java
commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs/test/AbstractProviderTestCase.java
commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs/test/AbstractProviderTestConfig.java
commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs/test/ProviderCacheStrategyTests.java
commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs/test/ProviderTestConfig.java
commons/proper/vfs/trunk/examples/src/main/java/org/apache/commons/vfs/example/ChangeLastModificationTime.java
commons/proper/vfs/trunk/sandbox/src/main/java/org/apache/commons/vfs/RACRandomAccessFile.java
commons/proper/vfs/trunk/sandbox/src/main/java/org/apache/commons/vfs/provider/mime/MimeAttributesMap.java
commons/proper/vfs/trunk/sandbox/src/main/java/org/apache/commons/vfs/provider/mime/MimeFileContentInfoFactory.java
commons/proper/vfs/trunk/sandbox/src/main/java/org/apache/commons/vfs/provider/mime/MimeFileObject.java
commons/proper/vfs/trunk/sandbox/src/main/java/org/apache/commons/vfs/provider/mime/MimeFileProvider.java
commons/proper/vfs/trunk/sandbox/src/main/java/org/apache/commons/vfs/provider/mime/MimeFileSystem.java
commons/proper/vfs/trunk/sandbox/src/main/java/org/apache/commons/vfs/provider/smb/SmbFileObject.java
commons/proper/vfs/trunk/sandbox/src/main/java/org/apache/commons/vfs/provider/smb/SmbFileProvider.java
commons/proper/vfs/trunk/sandbox/src/main/java/org/apache/commons/vfs/provider/smb/SmbFileRandomAccessContent.java
commons/proper/vfs/trunk/sandbox/src/main/java/org/apache/commons/vfs/util/FileObjectDataSource.java
commons/proper/vfs/trunk/sandbox/src/main/java/org/apache/commons/vfs/util/SharedRandomContentInputStream.java
Modified: commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/provider/ftp/FTPClientWrapper.java
URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/provider/ftp/FTPClientWrapper.java?rev=1024089&r1=1024088&r2=1024089&view=diff
==============================================================================
--- commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/provider/ftp/FTPClientWrapper.java (original)
+++ commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/provider/ftp/FTPClientWrapper.java Tue Oct 19 01:59:39 2010
@@ -129,18 +129,18 @@ class FTPClientWrapper implements FtpCli
private FTPFile[] listFilesInDirectory(String relPath) throws IOException
{
- FTPFile[] files;
+ FTPFile[] files;
- // VFS-307: no check if we can simply list the files, this might fail if there are spaces in the path
- files = getFtpClient().listFiles(relPath);
- if (FTPReply.isPositiveCompletion(getFtpClient().getReplyCode()))
- {
- return files;
- }
-
- // VFS-307: now try the hard way by cd'ing into the directory, list and cd back
- // if VFS is required to fallback here the user might experience a real bad FTP performance
- // as then every list requires 4 ftp commands.
+ // VFS-307: no check if we can simply list the files, this might fail if there are spaces in the path
+ files = getFtpClient().listFiles(relPath);
+ if (FTPReply.isPositiveCompletion(getFtpClient().getReplyCode()))
+ {
+ return files;
+ }
+
+ // VFS-307: now try the hard way by cd'ing into the directory, list and cd back
+ // if VFS is required to fallback here the user might experience a real bad FTP performance
+ // as then every list requires 4 ftp commands.
String workingDirectory = null;
if (relPath != null)
{
Modified: commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/provider/ftps/FtpsClientFactory.java
URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/provider/ftps/FtpsClientFactory.java?rev=1024089&r1=1024088&r2=1024089&view=diff
==============================================================================
--- commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/provider/ftps/FtpsClientFactory.java (original)
+++ commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/provider/ftps/FtpsClientFactory.java Tue Oct 19 01:59:39 2010
@@ -70,44 +70,44 @@ public class FtpsClientFactory
String key = FtpsFileSystemConfigBuilder.getInstance().getEntryParser(fileSystemOptions);
if (key != null)
{
- FTPClientConfig config = new FTPClientConfig(key);
-
- String serverLanguageCode = FtpsFileSystemConfigBuilder.getInstance().getServerLanguageCode(fileSystemOptions);
- if (serverLanguageCode != null)
- {
- config.setServerLanguageCode(serverLanguageCode);
- }
- String defaultDateFormat = FtpsFileSystemConfigBuilder.getInstance().getDefaultDateFormat(fileSystemOptions);
- if (defaultDateFormat != null)
- {
- config.setDefaultDateFormatStr(defaultDateFormat);
- }
- String recentDateFormat = FtpsFileSystemConfigBuilder.getInstance().getRecentDateFormat(fileSystemOptions);
- if (recentDateFormat != null)
- {
- config.setRecentDateFormatStr(recentDateFormat);
- }
- String serverTimeZoneId = FtpsFileSystemConfigBuilder.getInstance().getServerTimeZoneId(fileSystemOptions);
- if (serverTimeZoneId != null)
- {
- config.setServerTimeZoneId(serverTimeZoneId);
- }
- String[] shortMonthNames = FtpsFileSystemConfigBuilder.getInstance().getShortMonthNames(fileSystemOptions);
- if (shortMonthNames != null)
- {
- StringBuffer shortMonthNamesStr = new StringBuffer(40);
- for (int i = 0; i<shortMonthNames.length; i++)
- {
- if (shortMonthNamesStr.length()>0)
- {
- shortMonthNamesStr.append("|");
- }
- shortMonthNamesStr.append(shortMonthNames[i]);
- }
- config.setShortMonthNames(shortMonthNamesStr.toString());
- }
-
- client.configure(config);
+ FTPClientConfig config = new FTPClientConfig(key);
+
+ String serverLanguageCode = FtpsFileSystemConfigBuilder.getInstance().getServerLanguageCode(fileSystemOptions);
+ if (serverLanguageCode != null)
+ {
+ config.setServerLanguageCode(serverLanguageCode);
+ }
+ String defaultDateFormat = FtpsFileSystemConfigBuilder.getInstance().getDefaultDateFormat(fileSystemOptions);
+ if (defaultDateFormat != null)
+ {
+ config.setDefaultDateFormatStr(defaultDateFormat);
+ }
+ String recentDateFormat = FtpsFileSystemConfigBuilder.getInstance().getRecentDateFormat(fileSystemOptions);
+ if (recentDateFormat != null)
+ {
+ config.setRecentDateFormatStr(recentDateFormat);
+ }
+ String serverTimeZoneId = FtpsFileSystemConfigBuilder.getInstance().getServerTimeZoneId(fileSystemOptions);
+ if (serverTimeZoneId != null)
+ {
+ config.setServerTimeZoneId(serverTimeZoneId);
+ }
+ String[] shortMonthNames = FtpsFileSystemConfigBuilder.getInstance().getShortMonthNames(fileSystemOptions);
+ if (shortMonthNames != null)
+ {
+ StringBuffer shortMonthNamesStr = new StringBuffer(40);
+ for (int i = 0; i<shortMonthNames.length; i++)
+ {
+ if (shortMonthNamesStr.length()>0)
+ {
+ shortMonthNamesStr.append("|");
+ }
+ shortMonthNamesStr.append(shortMonthNames[i]);
+ }
+ config.setShortMonthNames(shortMonthNamesStr.toString());
+ }
+
+ client.configure(config);
}
FTPFileEntryParserFactory myFactory = FtpsFileSystemConfigBuilder.getInstance().getEntryParserFactory(fileSystemOptions);
@@ -128,8 +128,8 @@ public class FtpsClientFactory
// Login
if (!client.login(
- UserAuthenticatorUtils.toString(username),
- UserAuthenticatorUtils.toString(password)))
+ UserAuthenticatorUtils.toString(username),
+ UserAuthenticatorUtils.toString(password)))
{
throw new FileSystemException("vfs.provider.ftp/login.error", new Object[]{hostname, UserAuthenticatorUtils.toString(username)}, null);
}
Modified: commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/provider/ftps/FtpsClientWrapper.java
URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/provider/ftps/FtpsClientWrapper.java?rev=1024089&r1=1024088&r2=1024089&view=diff
==============================================================================
--- commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/provider/ftps/FtpsClientWrapper.java (original)
+++ commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/provider/ftps/FtpsClientWrapper.java Tue Oct 19 01:59:39 2010
@@ -64,25 +64,25 @@ class FtpsClientWrapper implements FtpCl
{
final GenericFileName rootName = getRoot();
- UserAuthenticationData authData = null;
- try
- {
- authData = UserAuthenticatorUtils.authenticate(fileSystemOptions, FtpsFileProvider.AUTHENTICATOR_TYPES);
-
- return FtpsClientFactory.createConnection(rootName.getHostName(),
- rootName.getPort(),
- UserAuthenticatorUtils.getData(authData, UserAuthenticationData.USERNAME, UserAuthenticatorUtils.toChar(rootName.getUserName())),
- UserAuthenticatorUtils.getData(authData, UserAuthenticationData.PASSWORD, UserAuthenticatorUtils.toChar(rootName.getPassword())),
- rootName.getPath(),
- getFileSystemOptions());
- }
- finally
- {
- UserAuthenticatorUtils.cleanup(authData);
- }
- }
+ UserAuthenticationData authData = null;
+ try
+ {
+ authData = UserAuthenticatorUtils.authenticate(fileSystemOptions, FtpsFileProvider.AUTHENTICATOR_TYPES);
+
+ return FtpsClientFactory.createConnection(rootName.getHostName(),
+ rootName.getPort(),
+ UserAuthenticatorUtils.getData(authData, UserAuthenticationData.USERNAME, UserAuthenticatorUtils.toChar(rootName.getUserName())),
+ UserAuthenticatorUtils.getData(authData, UserAuthenticationData.PASSWORD, UserAuthenticatorUtils.toChar(rootName.getPassword())),
+ rootName.getPath(),
+ getFileSystemOptions());
+ }
+ finally
+ {
+ UserAuthenticatorUtils.cleanup(authData);
+ }
+ }
- private FTPSClient getFtpsClient() throws FileSystemException
+ private FTPSClient getFtpsClient() throws FileSystemException
{
if (ftpClient == null)
{
Modified: commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/provider/ftps/FtpsFileProvider.java
URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/provider/ftps/FtpsFileProvider.java?rev=1024089&r1=1024088&r2=1024089&view=diff
==============================================================================
--- commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/provider/ftps/FtpsFileProvider.java (original)
+++ commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/provider/ftps/FtpsFileProvider.java Tue Oct 19 01:59:39 2010
@@ -37,7 +37,7 @@ import org.apache.commons.vfs.provider.f
*/
public class FtpsFileProvider extends FtpFileProvider
{
- public FtpsFileProvider()
+ public FtpsFileProvider()
{
super();
}
Modified: commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/provider/sftp/SftpFileObject.java
URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/provider/sftp/SftpFileObject.java?rev=1024089&r1=1024088&r2=1024089&view=diff
==============================================================================
--- commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/provider/sftp/SftpFileObject.java (original)
+++ commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/provider/sftp/SftpFileObject.java Tue Oct 19 01:59:39 2010
@@ -291,56 +291,56 @@ public class SftpFileObject extends Abst
Vector vector = null;
final ChannelSftp channel = fileSystem.getChannel();
- try
- {
- // try the direct way to list the directory on the server to avoid too many roundtrips
- vector = channel.ls(relPath);
- }
- catch (SftpException e)
- {
- String workingDirectory = null;
- try
- {
- if (relPath != null)
- {
- workingDirectory = channel.pwd();
- channel.cd(relPath);
- }
- }
- catch (SftpException ex)
- {
- // VFS-210: seems not to be a directory
- return null;
- }
-
- SftpException lsEx = null;
- try
- {
- vector = channel.ls(".");
- }
- catch (SftpException ex)
- {
- lsEx = ex;
- }
- finally
- {
- try
- {
- if (relPath != null)
- {
- channel.cd(workingDirectory);
- }
- }
- catch (SftpException xe)
- {
- throw new FileSystemException("vfs.provider.sftp/change-work-directory-back.error", workingDirectory, lsEx);
- }
- }
-
- if (lsEx != null)
- {
- throw lsEx;
- }
+ try
+ {
+ // try the direct way to list the directory on the server to avoid too many roundtrips
+ vector = channel.ls(relPath);
+ }
+ catch (SftpException e)
+ {
+ String workingDirectory = null;
+ try
+ {
+ if (relPath != null)
+ {
+ workingDirectory = channel.pwd();
+ channel.cd(relPath);
+ }
+ }
+ catch (SftpException ex)
+ {
+ // VFS-210: seems not to be a directory
+ return null;
+ }
+
+ SftpException lsEx = null;
+ try
+ {
+ vector = channel.ls(".");
+ }
+ catch (SftpException ex)
+ {
+ lsEx = ex;
+ }
+ finally
+ {
+ try
+ {
+ if (relPath != null)
+ {
+ channel.cd(workingDirectory);
+ }
+ }
+ catch (SftpException xe)
+ {
+ throw new FileSystemException("vfs.provider.sftp/change-work-directory-back.error", workingDirectory, lsEx);
+ }
+ }
+
+ if (lsEx != null)
+ {
+ throw lsEx;
+ }
}
finally
{
Modified: commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/AbstractVfsTestCase.java
URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/AbstractVfsTestCase.java?rev=1024089&r1=1024088&r2=1024089&view=diff
==============================================================================
--- commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/AbstractVfsTestCase.java (original)
+++ commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/AbstractVfsTestCase.java Tue Oct 19 01:59:39 2010
@@ -124,7 +124,7 @@ public abstract class AbstractVfsTestCas
return System.getProperty("test.basedir.res", "test-data");
}
- /**
+ /**
* Locates a test directory, creating it if it does not exist.
*
* @param name path of the directory, relative to this test's base directory.
Modified: commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs/RunTest.java
URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs/RunTest.java?rev=1024089&r1=1024088&r2=1024089&view=diff
==============================================================================
--- commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs/RunTest.java (original)
+++ commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs/RunTest.java Tue Oct 19 01:59:39 2010
@@ -24,28 +24,28 @@ import junit.framework.TestResult;
public class RunTest
{
- public static void main(String[] args) throws Exception
- {
+ public static void main(String[] args) throws Exception
+ {
final String ip = "192.168.0.128";
Properties props = System.getProperties();
- props.setProperty("test.data.src", "src/test-data");
- props.setProperty("test.basedir", "core/target/test-classes/test-data");
- props.setProperty("test.basedir.res", "test-data");
- props.setProperty("test.policy", "src/test-data/test.policy");
- props.setProperty("test.secure", "false");
- props.setProperty("test.smb.uri",
- "smb://HOME\\vfsusr:vfs%2f%25\\te:st@" + ip + "/vfsusr/vfstest");
- props.setProperty("test.ftp.uri",
- "ftp://vfsusr:vfs%2f%25\\te:st@" + ip + "/vfstest");
- props.setProperty("test.http.uri", "http://" + ip + "/vfstest");
- props.setProperty("test.webdav.uri",
- "webdav://vfsusr:vfs%2f%25\\te:st@" + ip + "/vfstest");
- props.setProperty("test.sftp.uri",
- "sftp://vfsusr:vfs%2f%25\\te:st@" + ip + "/vfstest");
+ props.setProperty("test.data.src", "src/test-data");
+ props.setProperty("test.basedir", "core/target/test-classes/test-data");
+ props.setProperty("test.basedir.res", "test-data");
+ props.setProperty("test.policy", "src/test-data/test.policy");
+ props.setProperty("test.secure", "false");
+ props.setProperty("test.smb.uri",
+ "smb://HOME\\vfsusr:vfs%2f%25\\te:st@" + ip + "/vfsusr/vfstest");
+ props.setProperty("test.ftp.uri",
+ "ftp://vfsusr:vfs%2f%25\\te:st@" + ip + "/vfstest");
+ props.setProperty("test.http.uri", "http://" + ip + "/vfstest");
+ props.setProperty("test.webdav.uri",
+ "webdav://vfsusr:vfs%2f%25\\te:st@" + ip + "/vfstest");
+ props.setProperty("test.sftp.uri",
+ "sftp://vfsusr:vfs%2f%25\\te:st@" + ip + "/vfstest");
- Test tests[] = new Test[]
- {
+ Test tests[] = new Test[]
+ {
// LocalProviderTestCase.suite(),
// FtpProviderTestCase.suite(),
// UrlProviderHttpTestCase.suite(),
@@ -56,9 +56,9 @@ public class RunTest
// HttpProviderTestCase.suite(),
// SftpProviderTestCase.suite(),
// JarProviderTestCase.suite(),
-// NestedJarTestCase.suite(),
-// ZipProviderTestCase.suite(),
-// NestedZipTestCase.suite(),
+// NestedJarTestCase.suite(),
+// ZipProviderTestCase.suite(),
+// NestedZipTestCase.suite(),
// TarProviderTestCase.suite(),
// TgzProviderTestCase.suite(),
// Tbz2ProviderTestCase.suite(),
@@ -69,44 +69,44 @@ public class RunTest
// SmbProviderTestCase.suite(),
// WebdavProviderTestCase.suite(),
- };
+ };
- TestResult result = new TestResult()
- {
- public void startTest(Test test)
- {
- System.out.println("start " + test);
- System.out.flush();
- }
-
- public void endTest(Test test)
- {
- // System.err.println("end " + test);
- }
-
- public synchronized void addError(Test test, Throwable throwable)
- {
- // throw new RuntimeException(throwable.getMessage());
- throwable.printStackTrace();
- }
-
- public synchronized void addFailure(Test test,
- AssertionFailedError assertionFailedError)
- {
- // throw new RuntimeException(assertionFailedError.getMessage());
- assertionFailedError.printStackTrace();
- }
- };
-
- for (int i = 0; i < tests.length; i++)
- {
- System.out.println("start test#" + i);
- System.out.flush();
-
- Test test = tests[i];
- test.run(result);
-
- // break;
- }
- }
+ TestResult result = new TestResult()
+ {
+ public void startTest(Test test)
+ {
+ System.out.println("start " + test);
+ System.out.flush();
+ }
+
+ public void endTest(Test test)
+ {
+ // System.err.println("end " + test);
+ }
+
+ public synchronized void addError(Test test, Throwable throwable)
+ {
+ // throw new RuntimeException(throwable.getMessage());
+ throwable.printStackTrace();
+ }
+
+ public synchronized void addFailure(Test test,
+ AssertionFailedError assertionFailedError)
+ {
+ // throw new RuntimeException(assertionFailedError.getMessage());
+ assertionFailedError.printStackTrace();
+ }
+ };
+
+ for (int i = 0; i < tests.length; i++)
+ {
+ System.out.println("start test#" + i);
+ System.out.flush();
+
+ Test test = tests[i];
+ test.run(result);
+
+ // break;
+ }
+ }
}
Modified: commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs/perf/FileNamePerformance.java
URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs/perf/FileNamePerformance.java?rev=1024089&r1=1024088&r2=1024089&view=diff
==============================================================================
--- commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs/perf/FileNamePerformance.java (original)
+++ commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs/perf/FileNamePerformance.java Tue Oct 19 01:59:39 2010
@@ -24,79 +24,79 @@ import org.apache.commons.vfs.VFS;
public class FileNamePerformance
{
- private final static int NUOF_RESOLVES = 100000;
+ private final static int NUOF_RESOLVES = 100000;
- public static void main(String[] args) throws FileSystemException
- {
- FileSystemManager mgr = VFS.getManager();
-
- FileObject root = mgr
- .resolveFile("smb://HOME\\vfsusr:vfs%2f%25\\te:st@10.0.1.54/vfsusr");
- FileName rootName = root.getName();
-
- testNames(mgr, rootName);
-
- testChildren(root);
-
- testFiles(mgr);
- }
-
- private static void testFiles(FileSystemManager mgr) throws FileSystemException
- {
- for (int i = 0; i < 10; i++)
- {
- // warmup jvm
- mgr.resolveFile("smb://HOME\\vfsusr:vfs%2f%25\\te:st@10.0.1.54/vfsusr/many/path/elements/with%25esc/any%25where/to/file.txt");
- }
-
- long start = System.currentTimeMillis();
- for (int i = 0; i < NUOF_RESOLVES; i++)
- {
- mgr.resolveFile("smb://HOME\\vfsusr:vfs%2f%25\\te:st@10.0.1.54/vfsusr/many/path/elements/with%25esc/any%25where/to/file.txt");
- }
- long end = System.currentTimeMillis();
-
- System.err.println("time to resolve " + NUOF_RESOLVES + " files: "
- + (end - start) + "ms");
- }
-
- private static void testChildren(FileObject root) throws FileSystemException
- {
- for (int i = 0; i < 10; i++)
- {
- // warmup jvm
- root.resolveFile("/many/path/elements/with%25esc/any%25where/to/file.txt");
- }
-
- long start = System.currentTimeMillis();
- for (int i = 0; i < NUOF_RESOLVES; i++)
- {
- root.resolveFile("/many/path/elements/with%25esc/any%25where/to/file.txt");
- }
- long end = System.currentTimeMillis();
-
- System.err.println("time to resolve " + NUOF_RESOLVES + " childs: "
- + (end - start) + "ms");
- }
-
- private static void testNames(FileSystemManager mgr, FileName rootName) throws FileSystemException
- {
- for (int i = 0; i < 10; i++)
- {
- // warmup jvm
- mgr.resolveName(rootName,
- "/many/path/elements/with%25esc/any%25where/to/file.txt");
- }
-
- long start = System.currentTimeMillis();
- for (int i = 0; i < NUOF_RESOLVES; i++)
- {
- mgr.resolveName(rootName,
- "/many/path/elements/with%25esc/any%25where/to/file.txt");
- }
- long end = System.currentTimeMillis();
-
- System.err.println("time to resolve " + NUOF_RESOLVES + " names: "
- + (end - start) + "ms");
- }
+ public static void main(String[] args) throws FileSystemException
+ {
+ FileSystemManager mgr = VFS.getManager();
+
+ FileObject root = mgr
+ .resolveFile("smb://HOME\\vfsusr:vfs%2f%25\\te:st@10.0.1.54/vfsusr");
+ FileName rootName = root.getName();
+
+ testNames(mgr, rootName);
+
+ testChildren(root);
+
+ testFiles(mgr);
+ }
+
+ private static void testFiles(FileSystemManager mgr) throws FileSystemException
+ {
+ for (int i = 0; i < 10; i++)
+ {
+ // warmup jvm
+ mgr.resolveFile("smb://HOME\\vfsusr:vfs%2f%25\\te:st@10.0.1.54/vfsusr/many/path/elements/with%25esc/any%25where/to/file.txt");
+ }
+
+ long start = System.currentTimeMillis();
+ for (int i = 0; i < NUOF_RESOLVES; i++)
+ {
+ mgr.resolveFile("smb://HOME\\vfsusr:vfs%2f%25\\te:st@10.0.1.54/vfsusr/many/path/elements/with%25esc/any%25where/to/file.txt");
+ }
+ long end = System.currentTimeMillis();
+
+ System.err.println("time to resolve " + NUOF_RESOLVES + " files: "
+ + (end - start) + "ms");
+ }
+
+ private static void testChildren(FileObject root) throws FileSystemException
+ {
+ for (int i = 0; i < 10; i++)
+ {
+ // warmup jvm
+ root.resolveFile("/many/path/elements/with%25esc/any%25where/to/file.txt");
+ }
+
+ long start = System.currentTimeMillis();
+ for (int i = 0; i < NUOF_RESOLVES; i++)
+ {
+ root.resolveFile("/many/path/elements/with%25esc/any%25where/to/file.txt");
+ }
+ long end = System.currentTimeMillis();
+
+ System.err.println("time to resolve " + NUOF_RESOLVES + " childs: "
+ + (end - start) + "ms");
+ }
+
+ private static void testNames(FileSystemManager mgr, FileName rootName) throws FileSystemException
+ {
+ for (int i = 0; i < 10; i++)
+ {
+ // warmup jvm
+ mgr.resolveName(rootName,
+ "/many/path/elements/with%25esc/any%25where/to/file.txt");
+ }
+
+ long start = System.currentTimeMillis();
+ for (int i = 0; i < NUOF_RESOLVES; i++)
+ {
+ mgr.resolveName(rootName,
+ "/many/path/elements/with%25esc/any%25where/to/file.txt");
+ }
+ long end = System.currentTimeMillis();
+
+ System.err.println("time to resolve " + NUOF_RESOLVES + " names: "
+ + (end - start) + "ms");
+ }
}
Modified: commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs/provider/ram/test/CustomRamProviderTest.java
URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs/provider/ram/test/CustomRamProviderTest.java?rev=1024089&r1=1024088&r2=1024089&view=diff
==============================================================================
--- commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs/provider/ram/test/CustomRamProviderTest.java (original)
+++ commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs/provider/ram/test/CustomRamProviderTest.java Tue Oct 19 01:59:39 2010
@@ -36,75 +36,75 @@ import org.apache.commons.vfs.provider.r
*/
public class CustomRamProviderTest extends TestCase
{
- DefaultFileSystemManager manager;
+ DefaultFileSystemManager manager;
- FileSystemOptions zeroSized = new FileSystemOptions();
+ FileSystemOptions zeroSized = new FileSystemOptions();
- FileSystemOptions smallSized = new FileSystemOptions();
+ FileSystemOptions smallSized = new FileSystemOptions();
FileSystemOptions defaultRamFs = new FileSystemOptions();
protected void setUp() throws Exception
- {
- super.setUp();
+ {
+ super.setUp();
- manager = new DefaultFileSystemManager();
- manager.addProvider("ram", new RamFileProvider());
- manager.init();
-
- // File Systems Options
- RamFileSystemConfigBuilder.getInstance().setMaxSize(zeroSized, 0);
- RamFileSystemConfigBuilder.getInstance().setMaxSize(smallSized, 10);
- }
-
- protected void tearDown() throws Exception
- {
- super.tearDown();
- manager.close();
- }
-
- public void testSmallFS() throws Exception
- {
-
- // Default FS
- FileObject fo1 = manager.resolveFile("ram:/");
- FileObject fo2 = manager.resolveFile("ram:/");
- assertTrue("Both files should exist in the same fs instance.", fo1
- .getFileSystem() == fo2.getFileSystem());
-
- // Small FS
- FileObject fo3 = manager.resolveFile("ram:/fo3", smallSized);
- FileObject fo4 = manager.resolveFile("ram:/", smallSized);
- assertTrue("Both files should exist in different fs instances.", fo3
- .getFileSystem() == fo4.getFileSystem());
- assertTrue("These file shouldn't be in the same file system.", fo1
- .getFileSystem() != fo3.getFileSystem());
-
- fo3.createFile();
- try
- {
- OutputStream os = fo3.getContent().getOutputStream();
- os.write(new byte[10]);
- os.close();
- }
- catch (FileSystemException e)
- {
- fail("It shouldn't save such a small file");
- }
-
- try
- {
- OutputStream os = fo3.getContent().getOutputStream();
- os.write(new byte[11]);
- os.close();
- fail("It shouldn't save such a big file");
- }
- catch (FileSystemException e)
- {
- // exception awaited
- }
+ manager = new DefaultFileSystemManager();
+ manager.addProvider("ram", new RamFileProvider());
+ manager.init();
+
+ // File Systems Options
+ RamFileSystemConfigBuilder.getInstance().setMaxSize(zeroSized, 0);
+ RamFileSystemConfigBuilder.getInstance().setMaxSize(smallSized, 10);
+ }
+
+ protected void tearDown() throws Exception
+ {
+ super.tearDown();
+ manager.close();
+ }
- }
+ public void testSmallFS() throws Exception
+ {
+
+ // Default FS
+ FileObject fo1 = manager.resolveFile("ram:/");
+ FileObject fo2 = manager.resolveFile("ram:/");
+ assertTrue("Both files should exist in the same fs instance.", fo1
+ .getFileSystem() == fo2.getFileSystem());
+
+ // Small FS
+ FileObject fo3 = manager.resolveFile("ram:/fo3", smallSized);
+ FileObject fo4 = manager.resolveFile("ram:/", smallSized);
+ assertTrue("Both files should exist in different fs instances.", fo3
+ .getFileSystem() == fo4.getFileSystem());
+ assertTrue("These file shouldn't be in the same file system.", fo1
+ .getFileSystem() != fo3.getFileSystem());
+
+ fo3.createFile();
+ try
+ {
+ OutputStream os = fo3.getContent().getOutputStream();
+ os.write(new byte[10]);
+ os.close();
+ }
+ catch (FileSystemException e)
+ {
+ fail("It shouldn't save such a small file");
+ }
+
+ try
+ {
+ OutputStream os = fo3.getContent().getOutputStream();
+ os.write(new byte[11]);
+ os.close();
+ fail("It shouldn't save such a big file");
+ }
+ catch (FileSystemException e)
+ {
+ // exception awaited
+ }
+
+ }
/**
*
Modified: commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs/provider/ram/test/RamProviderTestCase.java
URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs/provider/ram/test/RamProviderTestCase.java?rev=1024089&r1=1024088&r2=1024089&view=diff
==============================================================================
--- commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs/provider/ram/test/RamProviderTestCase.java (original)
+++ commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs/provider/ram/test/RamProviderTestCase.java Tue Oct 19 01:59:39 2010
@@ -37,62 +37,62 @@ import org.apache.commons.AbstractVfsTes
* Tests for the RAM file system.
*/
public class RamProviderTestCase extends AbstractProviderTestConfig implements
- ProviderTestConfig
+ ProviderTestConfig
{
private boolean inited = false;
/** logger */
- private static Log log = LogFactory.getLog(RamProviderTestCase.class);
+ private static Log log = LogFactory.getLog(RamProviderTestCase.class);
- /**
- * Creates the test suite for the ram file system.
- */
- public static Test suite() throws Exception
- {
- return new ProviderTestSuite(new RamProviderTestCase());
- }
+ /**
+ * Creates the test suite for the ram file system.
+ */
+ public static Test suite() throws Exception
+ {
+ return new ProviderTestSuite(new RamProviderTestCase());
+ }
/**
- * Prepares the file system manager.
- *
- * Imports test data from the disk.
- *
- * @throws Exception
- *
- */
- public void prepare(final DefaultFileSystemManager manager)
- throws Exception
- {
- try
- {
- manager.addProvider("ram", new RamFileProvider());
- manager.addProvider("file", new DefaultLocalFileProvider());
- }
- catch (Exception e)
- {
- log.error(e);
- throw e;
- }
- }
+ * Prepares the file system manager.
+ *
+ * Imports test data from the disk.
+ *
+ * @throws Exception
+ *
+ */
+ public void prepare(final DefaultFileSystemManager manager)
+ throws Exception
+ {
+ try
+ {
+ manager.addProvider("ram", new RamFileProvider());
+ manager.addProvider("file", new DefaultLocalFileProvider());
+ }
+ catch (Exception e)
+ {
+ log.error(e);
+ throw e;
+ }
+ }
- /**
- * Returns the base folder for tests.
- */
- public FileObject getBaseTestFolder(final FileSystemManager manager)
- throws Exception
- {
+ /**
+ * Returns the base folder for tests.
+ */
+ public FileObject getBaseTestFolder(final FileSystemManager manager)
+ throws Exception
+ {
if (!inited)
{
// Import the test tree
FileObject fo = manager.resolveFile("ram:/");
- RamFileSystem fs = (RamFileSystem) fo.getFileSystem();
- fs.importTree(new File(AbstractVfsTestCase.getTestDirectory()));
- fo.close();
+ RamFileSystem fs = (RamFileSystem) fo.getFileSystem();
+ fs.importTree(new File(AbstractVfsTestCase.getTestDirectory()));
+ fo.close();
inited=true;
}
final String uri = "ram:/";
- return manager.resolveFile(uri);
- }
+ return manager.resolveFile(uri);
+ }
}
Modified: commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs/provider/test/JunctionProviderConfig.java
URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs/provider/test/JunctionProviderConfig.java?rev=1024089&r1=1024088&r2=1024089&view=diff
==============================================================================
--- commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs/provider/test/JunctionProviderConfig.java (original)
+++ commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs/provider/test/JunctionProviderConfig.java Tue Oct 19 01:59:39 2010
@@ -41,11 +41,11 @@ public class JunctionProviderConfig
}
/**
- * Returns a DefaultFileSystemManager instance (or subclass instance).
- */
- public DefaultFileSystemManager getDefaultFileSystemManager() {
- return config.getDefaultFileSystemManager();
- }
+ * Returns a DefaultFileSystemManager instance (or subclass instance).
+ */
+ public DefaultFileSystemManager getDefaultFileSystemManager() {
+ return config.getDefaultFileSystemManager();
+ }
public FilesCache getFilesCache()
{
Modified: commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs/test/AbstractProviderTestCase.java
URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs/test/AbstractProviderTestCase.java?rev=1024089&r1=1024088&r2=1024089&view=diff
==============================================================================
--- commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs/test/AbstractProviderTestCase.java (original)
+++ commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs/test/AbstractProviderTestCase.java Tue Oct 19 01:59:39 2010
@@ -77,7 +77,7 @@ public abstract class AbstractProviderTe
* Configures this test.
*/
public void setConfig(final DefaultFileSystemManager manager,
- final ProviderTestConfig providerConfig,
+ final ProviderTestConfig providerConfig,
final FileObject baseFolder,
final FileObject readFolder,
final FileObject writeFolder)
@@ -103,14 +103,14 @@ public abstract class AbstractProviderTe
*/
protected DefaultFileSystemManager createManager() throws Exception
{
- DefaultFileSystemManager fs = getProviderConfig().getDefaultFileSystemManager();
- fs.setFilesCache(getProviderConfig().getFilesCache());
- getProviderConfig().prepare(fs);
- if (!fs.hasProvider("file"))
- {
- fs.addProvider("file", new DefaultLocalFileProvider());
- }
- return fs;
+ DefaultFileSystemManager fs = getProviderConfig().getDefaultFileSystemManager();
+ fs.setFilesCache(getProviderConfig().getFilesCache());
+ getProviderConfig().prepare(fs);
+ if (!fs.hasProvider("file"))
+ {
+ fs.addProvider("file", new DefaultLocalFileProvider());
+ }
+ return fs;
}
/**
@@ -135,11 +135,11 @@ public abstract class AbstractProviderTe
* get the provider configuration
*/
public ProviderTestConfig getProviderConfig()
- {
- return providerConfig;
- }
+ {
+ return providerConfig;
+ }
- /**
+ /**
* Returns the read test folder.
*/
protected FileObject getReadFolder()
@@ -387,8 +387,8 @@ public abstract class AbstractProviderTe
{
protected void runTest()
{
- System.out.println(message);
- }
- };
- }
+ System.out.println(message);
+ }
+ };
+ }
}
Modified: commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs/test/AbstractProviderTestConfig.java
URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs/test/AbstractProviderTestConfig.java?rev=1024089&r1=1024088&r2=1024089&view=diff
==============================================================================
--- commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs/test/AbstractProviderTestConfig.java (original)
+++ commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs/test/AbstractProviderTestConfig.java Tue Oct 19 01:59:39 2010
@@ -32,11 +32,11 @@ public abstract class AbstractProviderTe
private FilesCache cache = null;
/**
- * Returns a DefaultFileSystemManager instance (or subclass instance).
- */
- public DefaultFileSystemManager getDefaultFileSystemManager() {
- return new DefaultFileSystemManager();
- }
+ * Returns a DefaultFileSystemManager instance (or subclass instance).
+ */
+ public DefaultFileSystemManager getDefaultFileSystemManager() {
+ return new DefaultFileSystemManager();
+ }
/**
* Prepares the file system manager. This implementation does nothing.
Modified: commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs/test/ProviderCacheStrategyTests.java
URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs/test/ProviderCacheStrategyTests.java?rev=1024089&r1=1024088&r2=1024089&view=diff
==============================================================================
--- commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs/test/ProviderCacheStrategyTests.java (original)
+++ commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs/test/ProviderCacheStrategyTests.java Tue Oct 19 01:59:39 2010
@@ -62,7 +62,7 @@ public class ProviderCacheStrategyTests
scratchFolder.delete(Selectors.EXCLUDE_SELF);
DefaultFileSystemManager fs = createManager();
- fs.setCacheStrategy(CacheStrategy.MANUAL);
+ fs.setCacheStrategy(CacheStrategy.MANUAL);
fs.init();
FileObject foBase2 = getBaseTestFolder(fs);
@@ -97,7 +97,7 @@ public class ProviderCacheStrategyTests
scratchFolder.delete(Selectors.EXCLUDE_SELF);
DefaultFileSystemManager fs = createManager();
- fs.setCacheStrategy(CacheStrategy.ON_RESOLVE);
+ fs.setCacheStrategy(CacheStrategy.ON_RESOLVE);
fs.init();
FileObject foBase2 = getBaseTestFolder(fs);
@@ -132,7 +132,7 @@ public class ProviderCacheStrategyTests
scratchFolder.delete(Selectors.EXCLUDE_SELF);
DefaultFileSystemManager fs = createManager();
- fs.setCacheStrategy(CacheStrategy.ON_CALL);
+ fs.setCacheStrategy(CacheStrategy.ON_CALL);
fs.init();
FileObject foBase2 = getBaseTestFolder(fs);
@@ -147,27 +147,27 @@ public class ProviderCacheStrategyTests
assertContains(fos, "file1.txt");
}
- public void assertContainsNot(FileObject[] fos, String string)
- {
- for (int i = 0; i<fos.length; i++)
- {
- if (string.equals(fos[i].getName().getBaseName()))
- {
- fail(string + " should not be seen");
- }
- }
- }
-
- public void assertContains(FileObject[] fos, String string)
- {
- for (int i = 0; i<fos.length; i++)
- {
- if (string.equals(fos[i].getName().getBaseName()))
- {
- return;
- }
- }
-
- fail(string + " should be seen");
- }
+ public void assertContainsNot(FileObject[] fos, String string)
+ {
+ for (int i = 0; i<fos.length; i++)
+ {
+ if (string.equals(fos[i].getName().getBaseName()))
+ {
+ fail(string + " should not be seen");
+ }
+ }
+ }
+
+ public void assertContains(FileObject[] fos, String string)
+ {
+ for (int i = 0; i<fos.length; i++)
+ {
+ if (string.equals(fos[i].getName().getBaseName()))
+ {
+ return;
+ }
+ }
+
+ fail(string + " should be seen");
+ }
}
Modified: commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs/test/ProviderTestConfig.java
URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs/test/ProviderTestConfig.java?rev=1024089&r1=1024088&r2=1024089&view=diff
==============================================================================
--- commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs/test/ProviderTestConfig.java (original)
+++ commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs/test/ProviderTestConfig.java Tue Oct 19 01:59:39 2010
@@ -29,11 +29,11 @@ import org.apache.commons.vfs.impl.Defau
*/
public interface ProviderTestConfig
{
- /**
- * Returns a DefaultFileSystemManager instance (or subclass instance).
- */
- public DefaultFileSystemManager getDefaultFileSystemManager();
-
+ /**
+ * Returns a DefaultFileSystemManager instance (or subclass instance).
+ */
+ public DefaultFileSystemManager getDefaultFileSystemManager();
+
/**
* Prepares the file system manager.
*/
Modified: commons/proper/vfs/trunk/examples/src/main/java/org/apache/commons/vfs/example/ChangeLastModificationTime.java
URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/examples/src/main/java/org/apache/commons/vfs/example/ChangeLastModificationTime.java?rev=1024089&r1=1024088&r2=1024089&view=diff
==============================================================================
--- commons/proper/vfs/trunk/examples/src/main/java/org/apache/commons/vfs/example/ChangeLastModificationTime.java (original)
+++ commons/proper/vfs/trunk/examples/src/main/java/org/apache/commons/vfs/example/ChangeLastModificationTime.java Tue Oct 19 01:59:39 2010
@@ -27,17 +27,17 @@ import org.apache.commons.vfs.VFS;
public class ChangeLastModificationTime
{
public static void main(String[] args) throws Exception
- {
+ {
if (args.length == 0)
{
System.err.println("Please pass the name of a file as parameter.");
return;
}
- FileObject fo = VFS.getManager().resolveFile(args[0]);
- long setTo = System.currentTimeMillis();
- System.err.println("set to: " + setTo);
- fo.getContent().setLastModifiedTime(setTo);
- System.err.println("after set: " + fo.getContent().getLastModifiedTime());
+ FileObject fo = VFS.getManager().resolveFile(args[0]);
+ long setTo = System.currentTimeMillis();
+ System.err.println("set to: " + setTo);
+ fo.getContent().setLastModifiedTime(setTo);
+ System.err.println("after set: " + fo.getContent().getLastModifiedTime());
}
}
Modified: commons/proper/vfs/trunk/sandbox/src/main/java/org/apache/commons/vfs/RACRandomAccessFile.java
URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/sandbox/src/main/java/org/apache/commons/vfs/RACRandomAccessFile.java?rev=1024089&r1=1024088&r2=1024089&view=diff
==============================================================================
--- commons/proper/vfs/trunk/sandbox/src/main/java/org/apache/commons/vfs/RACRandomAccessFile.java (original)
+++ commons/proper/vfs/trunk/sandbox/src/main/java/org/apache/commons/vfs/RACRandomAccessFile.java Tue Oct 19 01:59:39 2010
@@ -29,129 +29,129 @@ import java.io.RandomAccessFile;
*/
public class RACRandomAccessFile extends RandomAccessFile implements RandomAccessContent
{
- private RandomAccessContent rac;
- protected final byte[] singleByteBuf = new byte[1];
+ private RandomAccessContent rac;
+ protected final byte[] singleByteBuf = new byte[1];
- private static File createTempFile() throws IOException
- {
- return File.createTempFile("fraf", "");
- }
-
- private void deleteTempFile(File tempFile)
- {
- try
- {
- super.close();
- }
- catch (IOException ex)
- {
- throw new RuntimeException(ex);
- }
- finally
- {
- tempFile.delete();
- }
- }
-
- public RACRandomAccessFile(RandomAccessContent rac) throws IOException
- {
- this(createTempFile());
- this.rac = rac;
- }
-
- private RACRandomAccessFile(File tempFile) throws IOException
- {
- super(tempFile, "r");
- deleteTempFile(tempFile);
- }
-
- public long getFilePointer() throws IOException
- {
- return this.rac.getFilePointer();
- }
-
- public void seek(long pos) throws IOException
- {
- this.rac.seek(pos);
- }
-
- public int skipBytes(int n) throws IOException
- {
- return this.rac.skipBytes(n);
- }
-
- public long length() throws IOException
- {
- return this.rac.length();
- }
-
- /* (non-Javadoc)
- * @see org.ecc.base.io.FilterRandomAccessFile#setLength(long)
- */
- public void setLength(long newLength) throws IOException
- {
- throw new IOException("Underlying RandomAccessContent instance length cannot be modified.");
- }
-
- public InputStream getInputStream() throws IOException
- {
- return this.rac.getInputStream();
- }
-
- public void close() throws IOException
- {
- this.rac.close();
- }
-
-
- /**
- * @see java.io.RandomAccessFile#read(byte[])
- */
- public final int read(byte[] b) throws IOException
- {
- return read(b, 0, b.length);
- }
-
- /**
- * @see java.io.RandomAccessFile#read()
- */
- public final int read() throws IOException
- {
- final byte[] buf = this.singleByteBuf;
- int count = read(buf, 0, 1);
- return count < 0 ? -1 : (buf[0] & 0xFF);
- }
-
- public int read(byte[] b, int off, int len) throws IOException
- {
- this.rac.readFully(b, off, len);
- return len;
- }
-
- /**
- * @see java.io.RandomAccessFile#write(int)
- */
- public final void write(int b) throws IOException
- {
- final byte[] buf = this.singleByteBuf;
- buf[0] = (byte) b;
- write(buf, 0, 1);
- }
-
- /**
- * @see java.io.RandomAccessFile#write(byte[])
- */
- public final void write(byte[] b) throws IOException
- {
- write(b, 0, b.length);
- }
-
- /**
- * @see java.io.RandomAccessFile#write(byte[],int,int)
- */
- public void write(byte[] b, int off, int len) throws IOException
- {
- this.rac.write(b, off, len);
- }
+ private static File createTempFile() throws IOException
+ {
+ return File.createTempFile("fraf", "");
+ }
+
+ private void deleteTempFile(File tempFile)
+ {
+ try
+ {
+ super.close();
+ }
+ catch (IOException ex)
+ {
+ throw new RuntimeException(ex);
+ }
+ finally
+ {
+ tempFile.delete();
+ }
+ }
+
+ public RACRandomAccessFile(RandomAccessContent rac) throws IOException
+ {
+ this(createTempFile());
+ this.rac = rac;
+ }
+
+ private RACRandomAccessFile(File tempFile) throws IOException
+ {
+ super(tempFile, "r");
+ deleteTempFile(tempFile);
+ }
+
+ public long getFilePointer() throws IOException
+ {
+ return this.rac.getFilePointer();
+ }
+
+ public void seek(long pos) throws IOException
+ {
+ this.rac.seek(pos);
+ }
+
+ public int skipBytes(int n) throws IOException
+ {
+ return this.rac.skipBytes(n);
+ }
+
+ public long length() throws IOException
+ {
+ return this.rac.length();
+ }
+
+ /* (non-Javadoc)
+ * @see org.ecc.base.io.FilterRandomAccessFile#setLength(long)
+ */
+ public void setLength(long newLength) throws IOException
+ {
+ throw new IOException("Underlying RandomAccessContent instance length cannot be modified.");
+ }
+
+ public InputStream getInputStream() throws IOException
+ {
+ return this.rac.getInputStream();
+ }
+
+ public void close() throws IOException
+ {
+ this.rac.close();
+ }
+
+
+ /**
+ * @see java.io.RandomAccessFile#read(byte[])
+ */
+ public final int read(byte[] b) throws IOException
+ {
+ return read(b, 0, b.length);
+ }
+
+ /**
+ * @see java.io.RandomAccessFile#read()
+ */
+ public final int read() throws IOException
+ {
+ final byte[] buf = this.singleByteBuf;
+ int count = read(buf, 0, 1);
+ return count < 0 ? -1 : (buf[0] & 0xFF);
+ }
+
+ public int read(byte[] b, int off, int len) throws IOException
+ {
+ this.rac.readFully(b, off, len);
+ return len;
+ }
+
+ /**
+ * @see java.io.RandomAccessFile#write(int)
+ */
+ public final void write(int b) throws IOException
+ {
+ final byte[] buf = this.singleByteBuf;
+ buf[0] = (byte) b;
+ write(buf, 0, 1);
+ }
+
+ /**
+ * @see java.io.RandomAccessFile#write(byte[])
+ */
+ public final void write(byte[] b) throws IOException
+ {
+ write(b, 0, b.length);
+ }
+
+ /**
+ * @see java.io.RandomAccessFile#write(byte[],int,int)
+ */
+ public void write(byte[] b, int off, int len) throws IOException
+ {
+ this.rac.write(b, off, len);
+ }
}
Modified: commons/proper/vfs/trunk/sandbox/src/main/java/org/apache/commons/vfs/provider/mime/MimeAttributesMap.java
URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/sandbox/src/main/java/org/apache/commons/vfs/provider/mime/MimeAttributesMap.java?rev=1024089&r1=1024088&r2=1024089&view=diff
==============================================================================
--- commons/proper/vfs/trunk/sandbox/src/main/java/org/apache/commons/vfs/provider/mime/MimeAttributesMap.java (original)
+++ commons/proper/vfs/trunk/sandbox/src/main/java/org/apache/commons/vfs/provider/mime/MimeAttributesMap.java Tue Oct 19 01:59:39 2010
@@ -42,221 +42,221 @@ import java.util.TreeMap;
*/
public class MimeAttributesMap implements Map
{
- private Log log = LogFactory.getLog(MimeAttributesMap.class);
+ private Log log = LogFactory.getLog(MimeAttributesMap.class);
- private final static String OBJECT_PREFIX = "obj.";
+ private final static String OBJECT_PREFIX = "obj.";
- private final Part part;
- private Map backingMap;
+ private final Part part;
+ private Map backingMap;
- private final Map mimeMessageGetters = new TreeMap();
+ private final Map mimeMessageGetters = new TreeMap();
- public MimeAttributesMap(Part part)
- {
- this.part = part;
- addMimeMessageMethod(part.getClass().getMethods());
- addMimeMessageMethod(part.getClass().getDeclaredMethods());
- }
-
- private void addMimeMessageMethod(Method[] methods)
- {
- for (int i = 0; i < methods.length; i++)
- {
- Method method = methods[i];
- if (!Modifier.isPublic(method.getModifiers()))
- {
- continue;
- }
- if (method.getParameterTypes().length > 0)
- {
- continue;
- }
-
- if (method.getName().startsWith("get"))
- {
- mimeMessageGetters.put(method.getName().substring(3), method);
- }
- else if (method.getName().startsWith("is"))
- {
- mimeMessageGetters.put(method.getName().substring(2), method);
- }
- }
- }
-
- private Map getMap()
- {
- if (backingMap == null)
- {
- backingMap = createMap();
- }
-
- return backingMap;
- }
-
- private Map createMap()
- {
- Map ret = new TreeMap();
-
- Enumeration headers;
- try
- {
- headers = part.getAllHeaders();
- }
- catch (MessagingException e)
- {
- throw new RuntimeException(e);
- }
-
- // add all headers
- while (headers.hasMoreElements())
- {
- Header header = (Header) headers.nextElement();
- String headerName = header.getName();
-
- Object values = ret.get(headerName);
-
- if (values == null)
- {
- ret.put(headerName, header.getValue());
- }
- else if (values instanceof String)
- {
- List newValues = new ArrayList();
- newValues.add(values);
- newValues.add(header.getValue());
- ret.put(headerName, newValues);
- }
- else if (values instanceof List)
- {
- ((List) values).add(header.getValue());
- }
- }
-
- // add all simple get/is results (with obj. prefix)
- Iterator iterEntries = mimeMessageGetters.entrySet().iterator();
- while (iterEntries.hasNext())
- {
- Map.Entry entry = (Map.Entry) iterEntries.next();
- String name = (String) entry.getKey();
- Method method = (Method) entry.getValue();
-
- try
- {
- Object value = method.invoke(part, null);
- ret.put(OBJECT_PREFIX + name, value);
- }
- catch (IllegalAccessException e)
- {
- log.debug(e.getLocalizedMessage(), e);
- }
- catch (InvocationTargetException e)
- {
- log.debug(e.getLocalizedMessage(), e);
- }
- }
-
- // add extended fields (with obj. prefix too)
- if (part instanceof MimeMessage)
- {
- MimeMessage message = (MimeMessage) part;
- try
- {
- Address[] address = message.getRecipients(MimeMessage.RecipientType.BCC);
- ret.put(OBJECT_PREFIX + "Recipients.BCC", address);
- }
- catch (MessagingException e)
- {
- log.debug(e.getLocalizedMessage(), e);
- }
- try
- {
- Address[] address = message.getRecipients(MimeMessage.RecipientType.CC);
- ret.put(OBJECT_PREFIX + "Recipients.CC", address);
- }
- catch (MessagingException e)
- {
- log.debug(e.getLocalizedMessage(), e);
- }
- try
- {
- Address[] address = message.getRecipients(MimeMessage.RecipientType.TO);
- ret.put(OBJECT_PREFIX + "Recipients.TO", address);
- }
- catch (MessagingException e)
- {
- log.debug(e.getLocalizedMessage(), e);
- }
- try
- {
- Address[] address = message.getRecipients(MimeMessage.RecipientType.NEWSGROUPS);
- ret.put(OBJECT_PREFIX + "Recipients.NEWSGROUPS", address);
- }
- catch (MessagingException e)
- {
- log.debug(e.getLocalizedMessage(), e);
- }
- }
-
- return ret;
- }
-
- public int size()
- {
- return getMap().size();
- }
-
- public boolean isEmpty()
- {
- return getMap().size() < 1;
- }
-
- public boolean containsKey(Object key)
- {
- return getMap().containsKey(key);
- }
-
- public boolean containsValue(Object value)
- {
- return getMap().containsValue(value);
- }
-
- public Object get(Object key)
- {
- return getMap().get(key);
- }
-
- public Object put(Object key, Object value)
- {
- throw new UnsupportedOperationException();
- }
-
- public Object remove(Object key)
- {
- throw new UnsupportedOperationException();
- }
-
- public void putAll(Map t)
- {
- throw new UnsupportedOperationException();
- }
-
- public void clear()
- {
- throw new UnsupportedOperationException();
- }
-
- public Set keySet()
- {
- return Collections.unmodifiableSet(getMap().keySet());
- }
-
- public Collection values()
- {
- return Collections.unmodifiableCollection(getMap().values());
- }
-
- public Set entrySet()
- {
- return Collections.unmodifiableSet(getMap().entrySet());
- }
+ public MimeAttributesMap(Part part)
+ {
+ this.part = part;
+ addMimeMessageMethod(part.getClass().getMethods());
+ addMimeMessageMethod(part.getClass().getDeclaredMethods());
+ }
+
+ private void addMimeMessageMethod(Method[] methods)
+ {
+ for (int i = 0; i < methods.length; i++)
+ {
+ Method method = methods[i];
+ if (!Modifier.isPublic(method.getModifiers()))
+ {
+ continue;
+ }
+ if (method.getParameterTypes().length > 0)
+ {
+ continue;
+ }
+
+ if (method.getName().startsWith("get"))
+ {
+ mimeMessageGetters.put(method.getName().substring(3), method);
+ }
+ else if (method.getName().startsWith("is"))
+ {
+ mimeMessageGetters.put(method.getName().substring(2), method);
+ }
+ }
+ }
+
+ private Map getMap()
+ {
+ if (backingMap == null)
+ {
+ backingMap = createMap();
+ }
+
+ return backingMap;
+ }
+
+ private Map createMap()
+ {
+ Map ret = new TreeMap();
+
+ Enumeration headers;
+ try
+ {
+ headers = part.getAllHeaders();
+ }
+ catch (MessagingException e)
+ {
+ throw new RuntimeException(e);
+ }
+
+ // add all headers
+ while (headers.hasMoreElements())
+ {
+ Header header = (Header) headers.nextElement();
+ String headerName = header.getName();
+
+ Object values = ret.get(headerName);
+
+ if (values == null)
+ {
+ ret.put(headerName, header.getValue());
+ }
+ else if (values instanceof String)
+ {
+ List newValues = new ArrayList();
+ newValues.add(values);
+ newValues.add(header.getValue());
+ ret.put(headerName, newValues);
+ }
+ else if (values instanceof List)
+ {
+ ((List) values).add(header.getValue());
+ }
+ }
+
+ // add all simple get/is results (with obj. prefix)
+ Iterator iterEntries = mimeMessageGetters.entrySet().iterator();
+ while (iterEntries.hasNext())
+ {
+ Map.Entry entry = (Map.Entry) iterEntries.next();
+ String name = (String) entry.getKey();
+ Method method = (Method) entry.getValue();
+
+ try
+ {
+ Object value = method.invoke(part, null);
+ ret.put(OBJECT_PREFIX + name, value);
+ }
+ catch (IllegalAccessException e)
+ {
+ log.debug(e.getLocalizedMessage(), e);
+ }
+ catch (InvocationTargetException e)
+ {
+ log.debug(e.getLocalizedMessage(), e);
+ }
+ }
+
+ // add extended fields (with obj. prefix too)
+ if (part instanceof MimeMessage)
+ {
+ MimeMessage message = (MimeMessage) part;
+ try
+ {
+ Address[] address = message.getRecipients(MimeMessage.RecipientType.BCC);
+ ret.put(OBJECT_PREFIX + "Recipients.BCC", address);
+ }
+ catch (MessagingException e)
+ {
+ log.debug(e.getLocalizedMessage(), e);
+ }
+ try
+ {
+ Address[] address = message.getRecipients(MimeMessage.RecipientType.CC);
+ ret.put(OBJECT_PREFIX + "Recipients.CC", address);
+ }
+ catch (MessagingException e)
+ {
+ log.debug(e.getLocalizedMessage(), e);
+ }
+ try
+ {
+ Address[] address = message.getRecipients(MimeMessage.RecipientType.TO);
+ ret.put(OBJECT_PREFIX + "Recipients.TO", address);
+ }
+ catch (MessagingException e)
+ {
+ log.debug(e.getLocalizedMessage(), e);
+ }
+ try
+ {
+ Address[] address = message.getRecipients(MimeMessage.RecipientType.NEWSGROUPS);
+ ret.put(OBJECT_PREFIX + "Recipients.NEWSGROUPS", address);
+ }
+ catch (MessagingException e)
+ {
+ log.debug(e.getLocalizedMessage(), e);
+ }
+ }
+
+ return ret;
+ }
+
+ public int size()
+ {
+ return getMap().size();
+ }
+
+ public boolean isEmpty()
+ {
+ return getMap().size() < 1;
+ }
+
+ public boolean containsKey(Object key)
+ {
+ return getMap().containsKey(key);
+ }
+
+ public boolean containsValue(Object value)
+ {
+ return getMap().containsValue(value);
+ }
+
+ public Object get(Object key)
+ {
+ return getMap().get(key);
+ }
+
+ public Object put(Object key, Object value)
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public Object remove(Object key)
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public void putAll(Map t)
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public void clear()
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public Set keySet()
+ {
+ return Collections.unmodifiableSet(getMap().keySet());
+ }
+
+ public Collection values()
+ {
+ return Collections.unmodifiableCollection(getMap().values());
+ }
+
+ public Set entrySet()
+ {
+ return Collections.unmodifiableSet(getMap().entrySet());
+ }
}
Modified: commons/proper/vfs/trunk/sandbox/src/main/java/org/apache/commons/vfs/provider/mime/MimeFileContentInfoFactory.java
URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/sandbox/src/main/java/org/apache/commons/vfs/provider/mime/MimeFileContentInfoFactory.java?rev=1024089&r1=1024088&r2=1024089&view=diff
==============================================================================
--- commons/proper/vfs/trunk/sandbox/src/main/java/org/apache/commons/vfs/provider/mime/MimeFileContentInfoFactory.java (original)
+++ commons/proper/vfs/trunk/sandbox/src/main/java/org/apache/commons/vfs/provider/mime/MimeFileContentInfoFactory.java Tue Oct 19 01:59:39 2010
@@ -34,64 +34,64 @@ import javax.mail.internet.ContentType;
*/
public class MimeFileContentInfoFactory implements FileContentInfoFactory
{
- public FileContentInfo create(FileContent fileContent) throws FileSystemException
- {
- MimeFileObject mimeFile = (MimeFileObject) fileContent.getFile();
- Part part = mimeFile.getPart();
-
- String contentTypeString = null;
- String charset = null;
-
- try
- {
- // special handling for multipart
- if (mimeFile.isMultipart())
- {
- // get the original content type, but ...
- contentTypeString = part.getContentType();
-
- // .... we deliver the preamble instead of an inupt string
- // the preamble will be delivered in UTF-8 - fixed
- charset = MimeFileSystem.PREAMBLE_CHARSET;
- }
- }
- catch (MessagingException e)
- {
- throw new FileSystemException(e);
- }
-
- if (contentTypeString == null)
- {
- // normal message ... get the content type
- try
- {
- contentTypeString = part.getContentType();
- }
- catch (MessagingException e)
- {
- throw new FileSystemException(e);
- }
- }
-
- ContentType contentType;
- try
- {
- contentType = new ContentType(contentTypeString);
- }
- catch (MessagingException e)
- {
- throw new FileSystemException(e);
- }
-
- if (charset == null)
- {
- // charset might already be set by the multipart message stuff, else
- // extract it from the contentType now
- charset = contentType.getParameter("charset"); // NON-NLS
- }
-
- return new DefaultFileContentInfo(
- contentType.getBaseType(),
- charset);
- }
+ public FileContentInfo create(FileContent fileContent) throws FileSystemException
+ {
+ MimeFileObject mimeFile = (MimeFileObject) fileContent.getFile();
+ Part part = mimeFile.getPart();
+
+ String contentTypeString = null;
+ String charset = null;
+
+ try
+ {
+ // special handling for multipart
+ if (mimeFile.isMultipart())
+ {
+ // get the original content type, but ...
+ contentTypeString = part.getContentType();
+
+ // .... we deliver the preamble instead of an inupt string
+ // the preamble will be delivered in UTF-8 - fixed
+ charset = MimeFileSystem.PREAMBLE_CHARSET;
+ }
+ }
+ catch (MessagingException e)
+ {
+ throw new FileSystemException(e);
+ }
+
+ if (contentTypeString == null)
+ {
+ // normal message ... get the content type
+ try
+ {
+ contentTypeString = part.getContentType();
+ }
+ catch (MessagingException e)
+ {
+ throw new FileSystemException(e);
+ }
+ }
+
+ ContentType contentType;
+ try
+ {
+ contentType = new ContentType(contentTypeString);
+ }
+ catch (MessagingException e)
+ {
+ throw new FileSystemException(e);
+ }
+
+ if (charset == null)
+ {
+ // charset might already be set by the multipart message stuff, else
+ // extract it from the contentType now
+ charset = contentType.getParameter("charset"); // NON-NLS
+ }
+
+ return new DefaultFileContentInfo(
+ contentType.getBaseType(),
+ charset);
+ }
}
Modified: commons/proper/vfs/trunk/sandbox/src/main/java/org/apache/commons/vfs/provider/mime/MimeFileObject.java
URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/sandbox/src/main/java/org/apache/commons/vfs/provider/mime/MimeFileObject.java?rev=1024089&r1=1024088&r2=1024089&view=diff
==============================================================================
--- commons/proper/vfs/trunk/sandbox/src/main/java/org/apache/commons/vfs/provider/mime/MimeFileObject.java (original)
+++ commons/proper/vfs/trunk/sandbox/src/main/java/org/apache/commons/vfs/provider/mime/MimeFileObject.java Tue Oct 19 01:59:39 2010
@@ -48,74 +48,74 @@ import org.apache.commons.vfs.util.FileO
* @version $Revision$ $Date$
*/
public class MimeFileObject
- extends AbstractFileObject
- implements FileObject
+ extends AbstractFileObject
+ implements FileObject
{
- private Part part;
- private Map attributeMap;
+ private Part part;
+ private Map attributeMap;
- protected MimeFileObject(final FileName name,
- final Part part,
- final AbstractFileSystem fileSystem) throws FileSystemException
- {
- super(name, fileSystem);
- setPart(part);
- }
- /**
+ protected MimeFileObject(final FileName name,
+ final Part part,
+ final AbstractFileSystem fileSystem) throws FileSystemException
+ {
+ super(name, fileSystem);
+ setPart(part);
+ }
+ /**
* Attaches this file object to its file resource.
*/
protected void doAttach() throws Exception
{
- if (part == null)
- {
- if (!getName().equals(getFileSystem().getRootName()))
- {
- MimeFileObject foParent = (MimeFileObject) FileObjectUtils.getAbstractFileObject(getParent());
- setPart(foParent.findPart(getName().getBaseName()));
- return;
- }
-
- setPart(((MimeFileSystem) getFileSystem()).createCommunicationLink());
- }
- }
-
- private Part findPart(String partName) throws Exception
- {
- if (getType() == FileType.IMAGINARY)
- {
- // not existent
- return null;
- }
-
- if (isMultipart())
- {
- Multipart multipart = (Multipart) part.getContent();
- if (partName.startsWith(MimeFileSystem.NULL_BP_NAME))
- {
- int partNumber = Integer.parseInt(partName.substring(MimeFileSystem.NULL_BP_NAME.length()), 10);
- if (partNumber < 0 || partNumber+1 > multipart.getCount())
- {
- // non existent
- return null;
- }
-
- return multipart.getBodyPart(partNumber);
- }
-
- for (int i = 0; i<multipart.getCount(); i++)
- {
- Part childPart = multipart.getBodyPart(i);
- if (partName.equals(childPart.getFileName()))
- {
- return childPart;
- }
- }
- }
+ if (part == null)
+ {
+ if (!getName().equals(getFileSystem().getRootName()))
+ {
+ MimeFileObject foParent = (MimeFileObject) FileObjectUtils.getAbstractFileObject(getParent());
+ setPart(foParent.findPart(getName().getBaseName()));
+ return;
+ }
- return null;
- }
+ setPart(((MimeFileSystem) getFileSystem()).createCommunicationLink());
+ }
+ }
- protected void doDetach() throws Exception
+ private Part findPart(String partName) throws Exception
+ {
+ if (getType() == FileType.IMAGINARY)
+ {
+ // not existent
+ return null;
+ }
+
+ if (isMultipart())
+ {
+ Multipart multipart = (Multipart) part.getContent();
+ if (partName.startsWith(MimeFileSystem.NULL_BP_NAME))
+ {
+ int partNumber = Integer.parseInt(partName.substring(MimeFileSystem.NULL_BP_NAME.length()), 10);
+ if (partNumber < 0 || partNumber+1 > multipart.getCount())
+ {
+ // non existent
+ return null;
+ }
+
+ return multipart.getBodyPart(partNumber);
+ }
+
+ for (int i = 0; i<multipart.getCount(); i++)
+ {
+ Part childPart = multipart.getBodyPart(i);
+ if (partName.equals(childPart.getFileName()))
+ {
+ return childPart;
+ }
+ }
+ }
+
+ return null;
+ }
+
+ protected void doDetach() throws Exception
{
}
@@ -125,81 +125,81 @@ public class MimeFileObject
*/
protected FileType doGetType() throws Exception
{
- if (part == null)
- {
- return FileType.IMAGINARY;
- }
-
- if (isMultipart())
- {
- // we cant have children ...
- return FileType.FILE_OR_FOLDER;
- }
-
- return FileType.FILE;
- }
-
- protected String[] doListChildren() throws Exception
- {
- return null;
- }
-
- /**
- * Lists the children of the file. Is only called if {@link #doGetType}
- * returns {@link org.apache.commons.vfs.FileType#FOLDER}.
- */
- protected FileObject[] doListChildrenResolved() throws Exception
- {
- if (part == null)
- {
- return null;
- }
-
- List vfs = new ArrayList();
- if (isMultipart())
- {
- Object container = part.getContent();
- if (container instanceof Multipart)
- {
- Multipart multipart = (Multipart) container;
-
- for (int i = 0; i<multipart.getCount(); i++)
- {
- Part part = multipart.getBodyPart(i);
-
- String filename = UriParser.encode(part.getFileName());
- if (filename == null)
- {
- filename = MimeFileSystem.NULL_BP_NAME + i;
- }
-
- MimeFileObject fo = (MimeFileObject) FileObjectUtils.getAbstractFileObject(getFileSystem().resolveFile(
- getFileSystem().getFileSystemManager().resolveName(
- getName(),
- filename,
- NameScope.CHILD)));
- fo.setPart(part);
- vfs.add(fo);
- }
- }
- }
-
- return (MimeFileObject[]) vfs.toArray(new MimeFileObject[vfs.size()]);
- }
-
- private void setPart(Part part)
- {
- this.part = part;
- this.attributeMap = null;
- }
+ if (part == null)
+ {
+ return FileType.IMAGINARY;
+ }
+
+ if (isMultipart())
+ {
+ // we cant have children ...
+ return FileType.FILE_OR_FOLDER;
+ }
+
+ return FileType.FILE;
+ }
+
+ protected String[] doListChildren() throws Exception
+ {
+ return null;
+ }
- /**
+ /**
+ * Lists the children of the file. Is only called if {@link #doGetType}
+ * returns {@link org.apache.commons.vfs.FileType#FOLDER}.
+ */
+ protected FileObject[] doListChildrenResolved() throws Exception
+ {
+ if (part == null)
+ {
+ return null;
+ }
+
+ List vfs = new ArrayList();
+ if (isMultipart())
+ {
+ Object container = part.getContent();
+ if (container instanceof Multipart)
+ {
+ Multipart multipart = (Multipart) container;
+
+ for (int i = 0; i<multipart.getCount(); i++)
+ {
+ Part part = multipart.getBodyPart(i);
+
+ String filename = UriParser.encode(part.getFileName());
+ if (filename == null)
+ {
+ filename = MimeFileSystem.NULL_BP_NAME + i;
+ }
+
+ MimeFileObject fo = (MimeFileObject) FileObjectUtils.getAbstractFileObject(getFileSystem().resolveFile(
+ getFileSystem().getFileSystemManager().resolveName(
+ getName(),
+ filename,
+ NameScope.CHILD)));
+ fo.setPart(part);
+ vfs.add(fo);
+ }
+ }
+ }
+
+ return (MimeFileObject[]) vfs.toArray(new MimeFileObject[vfs.size()]);
+ }
+
+ private void setPart(Part part)
+ {
+ this.part = part;
+ this.attributeMap = null;
+ }
+
+ /**
* Returns the size of the file content (in bytes).
*/
protected long doGetContentSize() throws Exception
{
- return part.getSize();
- }
+ return part.getSize();
+ }
/**
* Returns the last modified time of this file.
@@ -207,95 +207,95 @@ public class MimeFileObject
protected long doGetLastModifiedTime()
throws Exception
{
- Message mm = getMessage();
- if (mm == null)
- {
- return -1;
- }
- if (mm.getSentDate() != null)
- {
- return mm.getSentDate().getTime();
- }
- if (mm.getReceivedDate() != null)
- {
- mm.getReceivedDate();
- }
- return 0;
- }
-
- private Message getMessage() throws FileSystemException
- {
- if (part instanceof Message)
- {
- return (Message) part;
- }
+ Message mm = getMessage();
+ if (mm == null)
+ {
+ return -1;
+ }
+ if (mm.getSentDate() != null)
+ {
+ return mm.getSentDate().getTime();
+ }
+ if (mm.getReceivedDate() != null)
+ {
+ mm.getReceivedDate();
+ }
+ return 0;
+ }
- return ((MimeFileObject) FileObjectUtils.getAbstractFileObject(getParent())).getMessage();
- }
+ private Message getMessage() throws FileSystemException
+ {
+ if (part instanceof Message)
+ {
+ return (Message) part;
+ }
+
+ return ((MimeFileObject) FileObjectUtils.getAbstractFileObject(getParent())).getMessage();
+ }
- /**
+ /**
* Creates an input stream to read the file content from.
*/
protected InputStream doGetInputStream() throws Exception
{
- if (isMultipart())
- {
- // deliver the preamble as the only content
-
- String preamble = ((MimeMultipart) part.getContent()).getPreamble();
- if (preamble == null)
- {
- return new ByteArrayInputStream(new byte[]{});
- }
- return new ByteArrayInputStream(preamble.getBytes(MimeFileSystem.PREAMBLE_CHARSET));
- }
-
- return part.getInputStream();
- }
-
- boolean isMultipart() throws MessagingException
- {
- return part.getContentType() != null && part.getContentType().startsWith("multipart/");
- }
-
- protected FileContentInfoFactory getFileContentInfoFactory()
- {
- return new MimeFileContentInfoFactory();
- }
-
- protected Part getPart()
- {
- return part;
- }
-
- /**
- * Returns all headers of this part.<br />
- * The map key is a java.lang.String and the value is a:<br />
- * <ul>
- * <li>java.lang.Strings for single entries</li>
- * or a
- * <li>java.utils.List of java.lang.Strings for entries with multiple values</li>
- * </ul>
- */
- protected Map doGetAttributes() throws Exception
- {
- if (attributeMap == null)
- {
- if (part != null)
- {
- attributeMap = new MimeAttributesMap(part);
- }
- else
- {
- attributeMap = Collections.EMPTY_MAP;
- }
- }
-
- return attributeMap;
- }
-
- protected Enumeration getAllHeaders() throws MessagingException
- {
- return part.getAllHeaders();
- }
+ if (isMultipart())
+ {
+ // deliver the preamble as the only content
+
+ String preamble = ((MimeMultipart) part.getContent()).getPreamble();
+ if (preamble == null)
+ {
+ return new ByteArrayInputStream(new byte[]{});
+ }
+ return new ByteArrayInputStream(preamble.getBytes(MimeFileSystem.PREAMBLE_CHARSET));
+ }
+
+ return part.getInputStream();
+ }
+
+ boolean isMultipart() throws MessagingException
+ {
+ return part.getContentType() != null && part.getContentType().startsWith("multipart/");
+ }
+
+ protected FileContentInfoFactory getFileContentInfoFactory()
+ {
+ return new MimeFileContentInfoFactory();
+ }
+
+ protected Part getPart()
+ {
+ return part;
+ }
+
+ /**
+ * Returns all headers of this part.<br />
+ * The map key is a java.lang.String and the value is a:<br />
+ * <ul>
+ * <li>java.lang.Strings for single entries</li>
+ * or a
+ * <li>java.utils.List of java.lang.Strings for entries with multiple values</li>
+ * </ul>
+ */
+ protected Map doGetAttributes() throws Exception
+ {
+ if (attributeMap == null)
+ {
+ if (part != null)
+ {
+ attributeMap = new MimeAttributesMap(part);
+ }
+ else
+ {
+ attributeMap = Collections.EMPTY_MAP;
+ }
+ }
+
+ return attributeMap;
+ }
+
+ protected Enumeration getAllHeaders() throws MessagingException
+ {
+ return part.getAllHeaders();
+ }
}
\ No newline at end of file
Modified: commons/proper/vfs/trunk/sandbox/src/main/java/org/apache/commons/vfs/provider/mime/MimeFileProvider.java
URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/sandbox/src/main/java/org/apache/commons/vfs/provider/mime/MimeFileProvider.java?rev=1024089&r1=1024088&r2=1024089&view=diff
==============================================================================
--- commons/proper/vfs/trunk/sandbox/src/main/java/org/apache/commons/vfs/provider/mime/MimeFileProvider.java (original)
+++ commons/proper/vfs/trunk/sandbox/src/main/java/org/apache/commons/vfs/provider/mime/MimeFileProvider.java Tue Oct 19 01:59:39 2010
@@ -38,8 +38,8 @@ import java.util.Collections;
* @version $Revision$ $Date$
*/
public class MimeFileProvider
- extends AbstractLayeredFileProvider
- implements FileProvider
+ extends AbstractLayeredFileProvider
+ implements FileProvider
{
protected final static Collection capabilities = Collections.unmodifiableCollection(Arrays.asList(new Capability[]
{
@@ -48,10 +48,10 @@ public class MimeFileProvider
Capability.LIST_CHILDREN,
Capability.READ_CONTENT,
Capability.URI,
- Capability.ATTRIBUTES
+ Capability.ATTRIBUTES
}));
- public MimeFileProvider()
+ public MimeFileProvider()
{
super();
}
@@ -61,9 +61,9 @@ public class MimeFileProvider
*/
protected FileSystem doCreateFileSystem(String scheme, final FileObject file, final FileSystemOptions fileSystemOptions)
throws FileSystemException
- {
- final FileName name =
- new LayeredFileName(scheme, file.getName(), FileName.ROOT_PATH, FileType.FOLDER);
+ {
+ final FileName name =
+ new LayeredFileName(scheme, file.getName(), FileName.ROOT_PATH, FileType.FOLDER);
return new MimeFileSystem(name, file, fileSystemOptions);
}
Modified: commons/proper/vfs/trunk/sandbox/src/main/java/org/apache/commons/vfs/provider/mime/MimeFileSystem.java
URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/sandbox/src/main/java/org/apache/commons/vfs/provider/mime/MimeFileSystem.java?rev=1024089&r1=1024088&r2=1024089&view=diff
==============================================================================
--- commons/proper/vfs/trunk/sandbox/src/main/java/org/apache/commons/vfs/provider/mime/MimeFileSystem.java (original)
+++ commons/proper/vfs/trunk/sandbox/src/main/java/org/apache/commons/vfs/provider/mime/MimeFileSystem.java Tue Oct 19 01:59:39 2010
@@ -41,28 +41,28 @@ import java.util.Collection;
* @version $Revision$ $Date$
*/
public class MimeFileSystem
- extends AbstractFileSystem
- implements FileSystem
+ extends AbstractFileSystem
+ implements FileSystem
{
- private Log log = LogFactory.getLog(MimeFileSystem.class);
+ private Log log = LogFactory.getLog(MimeFileSystem.class);
- public final static String NULL_BP_NAME = "_body_part_";
- public final static String CONTENT_NAME = "_content";
- public final static String PREAMBLE_CHARSET = "UTF-8";
+ public final static String NULL_BP_NAME = "_body_part_";
+ public final static String CONTENT_NAME = "_content";
+ public final static String PREAMBLE_CHARSET = "UTF-8";
- private InputStream mimeStream = null;
+ private InputStream mimeStream = null;
- protected MimeFileSystem(final FileName rootName, final FileObject parentLayer, final FileSystemOptions fileSystemOptions)
+ protected MimeFileSystem(final FileName rootName, final FileObject parentLayer, final FileSystemOptions fileSystemOptions)
{
super(rootName, parentLayer, fileSystemOptions);
- }
+ }
- /**
+ /**
* Creates a file object.
*/
protected FileObject createFile(final FileName name) throws FileSystemException
- {
- return new MimeFileObject(name, null, this);
+ {
+ return new MimeFileObject(name, null, this);
}
/**
@@ -74,57 +74,57 @@ public class MimeFileSystem
}
- protected void doCloseCommunicationLink()
- {
- try
- {
- if (mimeStream == null)
- {
- return;
- }
-
- closeMimeStream();
- mimeStream = null;
- }
- catch (IOException e)
- {
- log.warn(e.getLocalizedMessage(), e);
- }
- }
-
- private void closeMimeStream() throws IOException
- {
- if (mimeStream instanceof SharedRandomContentInputStream)
- {
- ((SharedRandomContentInputStream) mimeStream).closeAll();
- }
- else
- {
- mimeStream.close();
- }
- }
-
- public Part createCommunicationLink() throws IOException, MessagingException
- {
- if (mimeStream != null)
- {
- closeMimeStream();
- }
-
- FileObject parentLayer = getParentLayer();
- if (!parentLayer.exists())
- {
- return null;
- }
-
- if (parentLayer.getFileSystem().hasCapability(Capability.RANDOM_ACCESS_READ))
- {
- mimeStream = new SharedRandomContentInputStream(parentLayer);
- }
- else
- {
- mimeStream = getParentLayer().getContent().getInputStream();
- }
- return new MimeMessage(null, mimeStream);
- }
+ protected void doCloseCommunicationLink()
+ {
+ try
+ {
+ if (mimeStream == null)
+ {
+ return;
+ }
+
+ closeMimeStream();
+ mimeStream = null;
+ }
+ catch (IOException e)
+ {
+ log.warn(e.getLocalizedMessage(), e);
+ }
+ }
+
+ private void closeMimeStream() throws IOException
+ {
+ if (mimeStream instanceof SharedRandomContentInputStream)
+ {
+ ((SharedRandomContentInputStream) mimeStream).closeAll();
+ }
+ else
+ {
+ mimeStream.close();
+ }
+ }
+
+ public Part createCommunicationLink() throws IOException, MessagingException
+ {
+ if (mimeStream != null)
+ {
+ closeMimeStream();
+ }
+
+ FileObject parentLayer = getParentLayer();
+ if (!parentLayer.exists())
+ {
+ return null;
+ }
+
+ if (parentLayer.getFileSystem().hasCapability(Capability.RANDOM_ACCESS_READ))
+ {
+ mimeStream = new SharedRandomContentInputStream(parentLayer);
+ }
+ else
+ {
+ mimeStream = getParentLayer().getContent().getInputStream();
+ }
+ return new MimeMessage(null, mimeStream);
+ }
}