1 16 package org.apache.commons.vfs.provider.temp; 17 18 import org.apache.commons.vfs.FileName; 19 import org.apache.commons.vfs.FileObject; 20 import org.apache.commons.vfs.FileSystem; 21 import org.apache.commons.vfs.FileSystemException; 22 import org.apache.commons.vfs.FileSystemOptions; 23 import org.apache.commons.vfs.FileType; 24 import org.apache.commons.vfs.provider.AbstractFileProvider; 25 import org.apache.commons.vfs.provider.FileProvider; 26 import org.apache.commons.vfs.provider.UriParser; 27 import org.apache.commons.vfs.provider.local.DefaultLocalFileProvider; 28 import org.apache.commons.vfs.provider.local.LocalFileSystem; 29 30 import java.io.File ; 31 import java.util.Collection ; 32 33 38 public class TemporaryFileProvider 39 extends AbstractFileProvider 40 implements FileProvider, Comparable 41 { 42 private File rootFile; 43 44 57 58 public TemporaryFileProvider(final File rootFile) 59 { 60 this(); 61 62 this.rootFile = rootFile; 63 } 64 65 public TemporaryFileProvider() 66 { 67 super(); 68 } 69 70 public int compareTo(Object o) 71 { 72 int h1 = hashCode(); 73 int h2 = o.hashCode(); 74 if (h1 < h2) 75 { 76 return -1; 77 } 78 if (h1 > h2) 79 { 80 return 1; 81 } 82 83 return 0; 84 } 85 86 89 public synchronized FileObject findFile(final FileObject baseFile, final String uri, final FileSystemOptions properties) 90 throws FileSystemException 91 { 92 final StringBuffer buffer = new StringBuffer (uri); 94 final String scheme = UriParser.extractScheme(uri, buffer); 95 96 UriParser.fixSeparators(buffer); 97 98 FileType fileType = UriParser.normalisePath(buffer); 99 final String path = buffer.toString(); 100 101 FileSystem filesystem = findFileSystem(this, properties); 104 if (filesystem == null) 105 { 106 if (rootFile == null) 107 { 108 rootFile = getContext().getTemporaryFileStore().allocateFile("tempfs"); 109 } 110 final FileName rootName = 111 getContext().parseURI(scheme + ":" + FileName.ROOT_PATH); 112 filesystem = new LocalFileSystem(rootName, rootFile.getAbsolutePath(), properties); 115 addFileSystem(this, filesystem); 116 } 117 118 return filesystem.resolveFile(path); 120 } 121 122 public Collection getCapabilities() 123 { 124 return DefaultLocalFileProvider.capabilities; 125 } 126 } 127 | Popular Tags |