@@ -914,6 +914,7 @@ SeekableByteChannel newByteChannel(byte[] path,
914
914
checkWritable ();
915
915
beginRead (); // only need a read lock, the "update()" will obtain
916
916
// the write lock when the channel is closed
917
+ ensureOpen ();
917
918
try {
918
919
Entry e = getEntry (path );
919
920
if (e != null ) {
@@ -1075,7 +1076,7 @@ public long read(ByteBuffer[] dsts, int offset, int length)
1075
1076
}
1076
1077
public int write (ByteBuffer src , long position )
1077
1078
throws IOException
1078
- {
1079
+ {
1079
1080
return fch .write (src , position );
1080
1081
}
1081
1082
public MappedByteBuffer map (MapMode mode ,
@@ -1114,10 +1115,6 @@ protected void implCloseChannel() throws IOException {
1114
1115
private Set <InputStream > streams =
1115
1116
Collections .synchronizedSet (new HashSet <>());
1116
1117
1117
- // the ex-channel and ex-path that need to close when their outstanding
1118
- // input streams are all closed by the obtainers.
1119
- private final Set <ExistingChannelCloser > exChClosers = new HashSet <>();
1120
-
1121
1118
private final Set <Path > tmppaths = Collections .synchronizedSet (new HashSet <>());
1122
1119
private Path getTempPathForEntry (byte [] path ) throws IOException {
1123
1120
Path tmpPath = createTempFileInSameDirectoryAs (zfpath );
@@ -1711,14 +1708,6 @@ private void writeTo(Entry e, OutputStream os) throws IOException {
1711
1708
1712
1709
// sync the zip file system, if there is any update
1713
1710
private void sync () throws IOException {
1714
- // check ex-closer
1715
- if (!exChClosers .isEmpty ()) {
1716
- for (ExistingChannelCloser ecc : exChClosers ) {
1717
- if (ecc .closeAndDeleteIfDone ()) {
1718
- exChClosers .remove (ecc );
1719
- }
1720
- }
1721
- }
1722
1711
if (!hasUpdate )
1723
1712
return ;
1724
1713
PosixFileAttributes attrs = getPosixAttributes (zfpath );
@@ -1781,22 +1770,8 @@ private void sync() throws IOException {
1781
1770
end .cenlen = written - end .cenoff ;
1782
1771
end .write (os , written , forceEnd64 );
1783
1772
}
1784
- if (!streams .isEmpty ()) {
1785
- //
1786
- // There are outstanding input streams open on existing "ch",
1787
- // so, don't close the "cha" and delete the "file for now, let
1788
- // the "ex-channel-closer" to handle them
1789
- Path path = createTempFileInSameDirectoryAs (zfpath );
1790
- ExistingChannelCloser ecc = new ExistingChannelCloser (path ,
1791
- ch ,
1792
- streams );
1793
- Files .move (zfpath , path , REPLACE_EXISTING );
1794
- exChClosers .add (ecc );
1795
- streams = Collections .synchronizedSet (new HashSet <>());
1796
- } else {
1797
- ch .close ();
1798
- Files .delete (zfpath );
1799
- }
1773
+ ch .close ();
1774
+ Files .delete (zfpath );
1800
1775
1801
1776
// Set the POSIX permissions of the original Zip File if available
1802
1777
// before moving the temp file
@@ -3141,36 +3116,6 @@ public Set<PosixFilePermission> permissions() {
3141
3116
}
3142
3117
}
3143
3118
3144
- private static class ExistingChannelCloser {
3145
- private final Path path ;
3146
- private final SeekableByteChannel ch ;
3147
- private final Set <InputStream > streams ;
3148
- ExistingChannelCloser (Path path ,
3149
- SeekableByteChannel ch ,
3150
- Set <InputStream > streams ) {
3151
- this .path = path ;
3152
- this .ch = ch ;
3153
- this .streams = streams ;
3154
- }
3155
-
3156
- /**
3157
- * If there are no more outstanding streams, close the channel and
3158
- * delete the backing file
3159
- *
3160
- * @return true if we're done and closed the backing file,
3161
- * otherwise false
3162
- * @throws IOException
3163
- */
3164
- private boolean closeAndDeleteIfDone () throws IOException {
3165
- if (streams .isEmpty ()) {
3166
- ch .close ();
3167
- Files .delete (path );
3168
- return true ;
3169
- }
3170
- return false ;
3171
- }
3172
- }
3173
-
3174
3119
// purely for parent lookup, so we don't have to copy the parent
3175
3120
// name every time
3176
3121
static class ParentLookup extends IndexNode {
0 commit comments