Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

[JBVFS-152] - Fallback to returning Closeables for VFS.mount* calls

  • Loading branch information...
commit 32fc0466907888a72a93de26d0c686ef407f8efc 1 parent 69a3e98
John Bailey authored
View
18 src/main/java/org/jboss/vfs/VFS.java
@@ -398,7 +398,7 @@ private static MountHandle doMount(final FileSystem fileSystem, final VirtualFil
*
* @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;
final TempDir tempDir = tempFileProvider.createTempDir(zipFile.getName());
try {
@@ -425,7 +425,7 @@ public static MountHandle mountZip(File zipFile, VirtualFile mountPoint, TempFil
*
* @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;
try {
final TempDir tempDir = tempFileProvider.createTempDir(zipName);
@@ -455,7 +455,7 @@ public static MountHandle mountZip(InputStream zipData, String zipName, VirtualF
*
* @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);
}
@@ -470,7 +470,7 @@ public static MountHandle mountZip(VirtualFile zipFile, VirtualFile mountPoint,
*
* @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);
}
@@ -485,7 +485,7 @@ public static MountHandle mountReal(File realRoot, VirtualFile mountPoint) throw
*
* @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;
final TempDir tempDir = tempFileProvider.createTempDir("tmpfs");
try {
@@ -511,7 +511,7 @@ public static MountHandle mountTemp(VirtualFile mountPoint, TempFileProvider tem
*
* @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;
final TempDir tempDir = tempFileProvider.createTempDir(zipFile.getName());
try {
@@ -540,7 +540,7 @@ public static MountHandle mountZipExpanded(File zipFile, VirtualFile mountPoint,
*
* @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 {
boolean ok = false;
final TempDir tempDir = tempFileProvider.createTempDir(zipName);
@@ -587,7 +587,7 @@ public static MountHandle mountZipExpanded(InputStream zipData, String zipName,
*
* @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);
}
@@ -601,7 +601,7 @@ public static MountHandle mountZipExpanded(VirtualFile zipFile, VirtualFile moun
*
* @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);
}
View
12 src/main/java/org/jboss/vfs/VFSUtils.java
@@ -53,6 +53,7 @@
import org.jboss.logging.Logger;
import org.jboss.util.collection.CollectionsFactory;
+import org.jboss.vfs.spi.MountHandle;
import org.jboss.vfs.util.PathTokenizer;
import org.jboss.vfs.util.automount.Automounter;
@@ -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("(\\*\\*?)|(\\?)|(\\\\.)|(/+)|([^*?]+)");
/**
View
6 src/test/java/org/jboss/test/vfs/MountHandleTestCase.java
@@ -24,8 +24,8 @@
import org.jboss.vfs.VFS;
import org.jboss.vfs.VFSUtils;
import org.jboss.vfs.VirtualFile;
-import org.jboss.vfs.spi.MountHandle;
+import java.io.Closeable;
import java.io.File;
/**
@@ -42,11 +42,11 @@ public MountHandleTestCase(final String name) {
public void testZipGetMountSource() throws Exception {
VirtualFile jar = getVirtualFile("/vfs/test/jar1.jar");
File origin = jar.getPhysicalFile();
- MountHandle mountHandle = VFS.mountZip(jar, jar, provider);
+ Closeable mountHandle = VFS.mountZip(jar, jar, provider);
try
{
File mounted = jar.getPhysicalFile();
- File source = mountHandle.getMountSource();
+ File source = VFSUtils.getMountSource(mountHandle);
assertNotNull(origin);
assertNotNull(mounted);
Please sign in to comment.
Something went wrong with that request. Please try again.