locking in zipfs demo
Joel Uckelman
uckelman at nomic.net
Sat Dec 5 08:02:01 PST 2009
Thus spake Joel Uckelman:
>
> Done. Patch attached.
>
Ack, I exported the wrong changeset. Here's the patch I meant to send:
-------------- next part --------------
# HG changeset patch
# User Joel Uckelman <uckelman at nomic.net>
# Date 1260027861 -3600
# Node ID 4cf3aee1209b5c2ef886ee7f66a96ccb352af98f
# Parent c9509c24484b305e4564a730cc8356155bd8c2a9
Switched to use FS read lock (to prevent FS closure), not Path-local read lock.
diff --git a/src/share/demo/nio/ZipFileSystem/com/sun/nio/zipfs/ZipFilePath.java b/src/share/demo/nio/ZipFileSystem/com/sun/nio/zipfs/ZipFilePath.java
--- a/src/share/demo/nio/ZipFileSystem/com/sun/nio/zipfs/ZipFilePath.java
+++ b/src/share/demo/nio/ZipFileSystem/com/sun/nio/zipfs/ZipFilePath.java
@@ -45,8 +45,6 @@
import java.net.URI;
import java.nio.channels.FileChannel;
import java.nio.file.attribute.Attributes;
-import java.util.concurrent.locks.ReentrantReadWriteLock;
-import java.util.concurrent.locks.ReentrantReadWriteLock.ReadLock;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.zip.ZipEntry;
@@ -71,7 +69,6 @@
// resolved path for locating zip inside zip file
// resloved path does not contain ./ and .. components
private final byte[] pathForZip;
- private final ReadLock readLock = new ReentrantReadWriteLock().readLock();
private ZipFilePath pathToZip;
private final byte[] pathForPrint;
@@ -143,7 +140,7 @@
*/
public boolean isDirectory() {
try {
- begin();
+ fileSystem.begin();
try {
ZipFilePath resolved = getResolvedPathForZip();
return Attributes.readBasicFileAttributes(resolved, LinkOption.NOFOLLOW_LINKS).isDirectory();
@@ -151,7 +148,7 @@
return false;
}
} finally {
- end();
+ fileSystem.end();
}
}
@@ -165,17 +162,6 @@
return index;
}
- final void begin() {
- readLock.lock();
- if (!fileSystem.isOpen()) {
- throw new ClosedFileSystemException();
- }
- }
-
- final void end() {
- readLock.unlock();
- }
-
static int nextNonSeparator(byte[] path, int index) {
int length = path.length;
@@ -822,7 +808,7 @@
}
}
try {
- begin();
+ fileSystem.begin();
ZipFilePath realPath = getResolvedPathForZip();
if (realPath.getNameCount() == 0) {
throw new IOException("entry missing in the path");
@@ -839,7 +825,7 @@
return new ZipFilePathInputStream(zfile.getInputStream(entry));
}
} finally {
- end();
+ fileSystem.end();
}
}
@@ -849,10 +835,10 @@
Filter<? super Path> filter) throws IOException
{
try {
- begin();
+ fileSystem.begin();
return new ZipFileStream(getResolvedPathForZip(), filter);
} finally {
- end();
+ fileSystem.end();
}
}
private static final DirectoryStream.Filter<Path> acceptAllFilter =
@@ -967,14 +953,14 @@
@Override
public FileStore getFileStore() throws IOException {
try {
- begin();
+ fileSystem.begin();
if (isAbsolute()) {
return ZipFileStore.create(getRoot());
} else {
return ZipFileStore.create(getResolvedPathForZip().getRoot());
}
} finally {
- end();
+ fileSystem.end();
}
}
@@ -1076,7 +1062,7 @@
throw new IllegalArgumentException("not opened for Read"); //this is never thrown
}
try {
- begin();
+ fileSystem.begin();
ZipFilePath realPath = getResolvedPathForZip();
if (realPath.getNameCount() == 0) {
throw new IOException("entry Not Found");
@@ -1098,7 +1084,7 @@
);
}
} finally {
- end();
+ fileSystem.end();
}
}
@@ -1150,7 +1136,7 @@
}
try {
- begin();
+ fileSystem.begin();
ZipFilePath resolvedZipPath = getResolvedPathForZip();
int nameCount = resolvedZipPath.getNameCount();
if (nameCount == 0) {
@@ -1167,7 +1153,7 @@
}
}
} finally {
- end();
+ fileSystem.end();
}
}
More information about the nio-dev
mailing list