Skip to content

Commit

Permalink
[JBVFS-152] - Fallback to returning Closeables for VFS.mount* calls
Browse files Browse the repository at this point in the history
  • Loading branch information
John Bailey committed Mar 15, 2010
1 parent 69a3e98 commit 32fc046
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 12 deletions.
18 changes: 9 additions & 9 deletions src/main/java/org/jboss/vfs/VFS.java
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ private static MountHandle doMount(final FileSystem fileSystem, final VirtualFil
* *
* @throws IOException if an error occurs * @throws IOException if an error occurs
*/ */
public static MountHandle mountZip(File zipFile, VirtualFile mountPoint, TempFileProvider tempFileProvider) throws IOException { public static Closeable mountZip(File zipFile, VirtualFile mountPoint, TempFileProvider tempFileProvider) throws IOException {
boolean ok = false; boolean ok = false;
final TempDir tempDir = tempFileProvider.createTempDir(zipFile.getName()); final TempDir tempDir = tempFileProvider.createTempDir(zipFile.getName());
try { try {
Expand All @@ -425,7 +425,7 @@ public static MountHandle mountZip(File zipFile, VirtualFile mountPoint, TempFil
* *
* @throws IOException if an error occurs * @throws IOException if an error occurs
*/ */
public static MountHandle mountZip(InputStream zipData, String zipName, VirtualFile mountPoint, TempFileProvider tempFileProvider) throws IOException { public static Closeable mountZip(InputStream zipData, String zipName, VirtualFile mountPoint, TempFileProvider tempFileProvider) throws IOException {
boolean ok = false; boolean ok = false;
try { try {
final TempDir tempDir = tempFileProvider.createTempDir(zipName); final TempDir tempDir = tempFileProvider.createTempDir(zipName);
Expand Down Expand Up @@ -455,7 +455,7 @@ public static MountHandle mountZip(InputStream zipData, String zipName, VirtualF
* *
* @throws IOException if an error occurs * @throws IOException if an error occurs
*/ */
public static MountHandle mountZip(VirtualFile zipFile, VirtualFile mountPoint, TempFileProvider tempFileProvider) throws IOException { public static Closeable mountZip(VirtualFile zipFile, VirtualFile mountPoint, TempFileProvider tempFileProvider) throws IOException {
return mountZip(zipFile.openStream(), zipFile.getName(), mountPoint, tempFileProvider); return mountZip(zipFile.openStream(), zipFile.getName(), mountPoint, tempFileProvider);
} }


Expand All @@ -470,7 +470,7 @@ public static MountHandle mountZip(VirtualFile zipFile, VirtualFile mountPoint,
* *
* @throws IOException if an error occurs * @throws IOException if an error occurs
*/ */
public static MountHandle mountReal(File realRoot, VirtualFile mountPoint) throws IOException { public static Closeable mountReal(File realRoot, VirtualFile mountPoint) throws IOException {
return doMount(new RealFileSystem(realRoot), mountPoint); return doMount(new RealFileSystem(realRoot), mountPoint);
} }


Expand All @@ -485,7 +485,7 @@ public static MountHandle mountReal(File realRoot, VirtualFile mountPoint) throw
* *
* @throws IOException if an error occurs * @throws IOException if an error occurs
*/ */
public static MountHandle mountTemp(VirtualFile mountPoint, TempFileProvider tempFileProvider) throws IOException { public static Closeable mountTemp(VirtualFile mountPoint, TempFileProvider tempFileProvider) throws IOException {
boolean ok = false; boolean ok = false;
final TempDir tempDir = tempFileProvider.createTempDir("tmpfs"); final TempDir tempDir = tempFileProvider.createTempDir("tmpfs");
try { try {
Expand All @@ -511,7 +511,7 @@ public static MountHandle mountTemp(VirtualFile mountPoint, TempFileProvider tem
* *
* @throws IOException if an error occurs * @throws IOException if an error occurs
*/ */
public static MountHandle mountZipExpanded(File zipFile, VirtualFile mountPoint, TempFileProvider tempFileProvider) throws IOException { public static Closeable mountZipExpanded(File zipFile, VirtualFile mountPoint, TempFileProvider tempFileProvider) throws IOException {
boolean ok = false; boolean ok = false;
final TempDir tempDir = tempFileProvider.createTempDir(zipFile.getName()); final TempDir tempDir = tempFileProvider.createTempDir(zipFile.getName());
try { try {
Expand Down Expand Up @@ -540,7 +540,7 @@ public static MountHandle mountZipExpanded(File zipFile, VirtualFile mountPoint,
* *
* @throws IOException if an error occurs * @throws IOException if an error occurs
*/ */
public static MountHandle mountZipExpanded(InputStream zipData, String zipName, VirtualFile mountPoint, TempFileProvider tempFileProvider) throws IOException { public static Closeable mountZipExpanded(InputStream zipData, String zipName, VirtualFile mountPoint, TempFileProvider tempFileProvider) throws IOException {
try { try {
boolean ok = false; boolean ok = false;
final TempDir tempDir = tempFileProvider.createTempDir(zipName); final TempDir tempDir = tempFileProvider.createTempDir(zipName);
Expand Down Expand Up @@ -587,7 +587,7 @@ public static MountHandle mountZipExpanded(InputStream zipData, String zipName,
* *
* @throws IOException if an error occurs * @throws IOException if an error occurs
*/ */
public static MountHandle mountZipExpanded(VirtualFile zipFile, VirtualFile mountPoint, TempFileProvider tempFileProvider) throws IOException { public static Closeable mountZipExpanded(VirtualFile zipFile, VirtualFile mountPoint, TempFileProvider tempFileProvider) throws IOException {
return mountZipExpanded(zipFile.openStream(), zipFile.getName(), mountPoint, tempFileProvider); return mountZipExpanded(zipFile.openStream(), zipFile.getName(), mountPoint, tempFileProvider);
} }


Expand All @@ -601,7 +601,7 @@ public static MountHandle mountZipExpanded(VirtualFile zipFile, VirtualFile moun
* *
* @throws IOException if an error occurs * @throws IOException if an error occurs
*/ */
public static MountHandle mountAssembly(VirtualFileAssembly assembly, VirtualFile mountPoint) throws IOException { public static Closeable mountAssembly(VirtualFileAssembly assembly, VirtualFile mountPoint) throws IOException {
return doMount(new AssemblyFileSystem(assembly), mountPoint); return doMount(new AssemblyFileSystem(assembly), mountPoint);
} }


Expand Down
12 changes: 12 additions & 0 deletions src/main/java/org/jboss/vfs/VFSUtils.java
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@


import org.jboss.logging.Logger; import org.jboss.logging.Logger;
import org.jboss.util.collection.CollectionsFactory; import org.jboss.util.collection.CollectionsFactory;
import org.jboss.vfs.spi.MountHandle;
import org.jboss.vfs.util.PathTokenizer; import org.jboss.vfs.util.PathTokenizer;
import org.jboss.vfs.util.automount.Automounter; import org.jboss.vfs.util.automount.Automounter;


Expand Down Expand Up @@ -812,6 +813,17 @@ public static void unzip(File zipFile, File destDir) throws IOException {
} }
} }


/**
* Return the mount source File for a given mount handle.
* @param handle The handle to get the source for
* @return The mount source file or null if the handle does not have a source, or is not a MountHandle
*/
public static File getMountSource(Closeable handle) {
if(handle instanceof MountHandle)
return MountHandle.class.cast(handle).getMountSource();
return null;
}

private static final Pattern GLOB_PATTERN = Pattern.compile("(\\*\\*?)|(\\?)|(\\\\.)|(/+)|([^*?]+)"); private static final Pattern GLOB_PATTERN = Pattern.compile("(\\*\\*?)|(\\?)|(\\\\.)|(/+)|([^*?]+)");


/** /**
Expand Down
6 changes: 3 additions & 3 deletions src/test/java/org/jboss/test/vfs/MountHandleTestCase.java
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
import org.jboss.vfs.VFS; import org.jboss.vfs.VFS;
import org.jboss.vfs.VFSUtils; import org.jboss.vfs.VFSUtils;
import org.jboss.vfs.VirtualFile; import org.jboss.vfs.VirtualFile;
import org.jboss.vfs.spi.MountHandle;


import java.io.Closeable;
import java.io.File; import java.io.File;


/** /**
Expand All @@ -42,11 +42,11 @@ public MountHandleTestCase(final String name) {
public void testZipGetMountSource() throws Exception { public void testZipGetMountSource() throws Exception {
VirtualFile jar = getVirtualFile("/vfs/test/jar1.jar"); VirtualFile jar = getVirtualFile("/vfs/test/jar1.jar");
File origin = jar.getPhysicalFile(); File origin = jar.getPhysicalFile();
MountHandle mountHandle = VFS.mountZip(jar, jar, provider); Closeable mountHandle = VFS.mountZip(jar, jar, provider);
try try
{ {
File mounted = jar.getPhysicalFile(); File mounted = jar.getPhysicalFile();
File source = mountHandle.getMountSource(); File source = VFSUtils.getMountSource(mountHandle);


assertNotNull(origin); assertNotNull(origin);
assertNotNull(mounted); assertNotNull(mounted);
Expand Down

0 comments on commit 32fc046

Please sign in to comment.