author | ohair |
Tue, 28 Dec 2010 15:53:50 -0800 | |
changeset 7668 | d4a77089c587 |
parent 6537 | 7aa4e7bb5dae |
child 10891 | 8c554ab7cfed |
permissions | -rw-r--r-- |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
1 |
/* |
7668 | 2 |
* Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved. |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
4 |
* |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
10 |
* |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
15 |
* accompanied this code). |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
16 |
* |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
17 |
* You should have received a copy of the GNU General Public License version |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
20 |
* |
5506 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
24 |
*/ |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
25 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
26 |
package sun.nio.fs; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
27 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
28 |
import java.nio.file.*; |
2071
5e6af6d106cb
6808647: (file) Paths.get("C:").newDirectoryStream() iterates over Path elements with additional slash [win]
alanb
parents:
2057
diff
changeset
|
29 |
import java.nio.file.attribute.BasicFileAttributes; |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
30 |
import java.util.Iterator; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
31 |
import java.util.NoSuchElementException; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
32 |
import java.io.IOException; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
33 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
34 |
import static sun.nio.fs.WindowsNativeDispatcher.*; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
35 |
import static sun.nio.fs.WindowsConstants.*; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
36 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
37 |
/** |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
38 |
* Windows implementation of DirectoryStream |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
39 |
*/ |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
40 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
41 |
class WindowsDirectoryStream |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
42 |
implements DirectoryStream<Path> |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
43 |
{ |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
44 |
private final WindowsPath dir; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
45 |
private final DirectoryStream.Filter<? super Path> filter; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
46 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
47 |
// handle to directory |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
48 |
private final long handle; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
49 |
// first entry in the directory |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
50 |
private final String firstName; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
51 |
|
2071
5e6af6d106cb
6808647: (file) Paths.get("C:").newDirectoryStream() iterates over Path elements with additional slash [win]
alanb
parents:
2057
diff
changeset
|
52 |
// buffer for WIN32_FIND_DATA structure that receives information about file |
5e6af6d106cb
6808647: (file) Paths.get("C:").newDirectoryStream() iterates over Path elements with additional slash [win]
alanb
parents:
2057
diff
changeset
|
53 |
private final NativeBuffer findDataBuffer; |
5e6af6d106cb
6808647: (file) Paths.get("C:").newDirectoryStream() iterates over Path elements with additional slash [win]
alanb
parents:
2057
diff
changeset
|
54 |
|
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
55 |
private final Object closeLock = new Object(); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
56 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
57 |
// need closeLock to access these |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
58 |
private boolean isOpen = true; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
59 |
private Iterator<Path> iterator; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
60 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
61 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
62 |
WindowsDirectoryStream(WindowsPath dir, DirectoryStream.Filter<? super Path> filter) |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
63 |
throws IOException |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
64 |
{ |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
65 |
this.dir = dir; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
66 |
this.filter = filter; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
67 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
68 |
try { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
69 |
// Need to append * or \* to match entries in directory. |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
70 |
String search = dir.getPathForWin32Calls(); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
71 |
char last = search.charAt(search.length() -1); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
72 |
if (last == ':' || last == '\\') { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
73 |
search += "*"; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
74 |
} else { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
75 |
search += "\\*"; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
76 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
77 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
78 |
FirstFile first = FindFirstFile(search); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
79 |
this.handle = first.handle(); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
80 |
this.firstName = first.name(); |
2071
5e6af6d106cb
6808647: (file) Paths.get("C:").newDirectoryStream() iterates over Path elements with additional slash [win]
alanb
parents:
2057
diff
changeset
|
81 |
this.findDataBuffer = WindowsFileAttributes.getBufferForFindData(); |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
82 |
} catch (WindowsException x) { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
83 |
if (x.lastError() == ERROR_DIRECTORY) { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
84 |
throw new NotDirectoryException(dir.getPathForExceptionMessage()); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
85 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
86 |
x.rethrowAsIOException(dir); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
87 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
88 |
// keep compiler happy |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
89 |
throw new AssertionError(); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
90 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
91 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
92 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
93 |
@Override |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
94 |
public void close() |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
95 |
throws IOException |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
96 |
{ |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
97 |
synchronized (closeLock) { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
98 |
if (!isOpen) |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
99 |
return; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
100 |
isOpen = false; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
101 |
} |
2071
5e6af6d106cb
6808647: (file) Paths.get("C:").newDirectoryStream() iterates over Path elements with additional slash [win]
alanb
parents:
2057
diff
changeset
|
102 |
findDataBuffer.release(); |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
103 |
try { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
104 |
FindClose(handle); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
105 |
} catch (WindowsException x) { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
106 |
x.rethrowAsIOException(dir); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
107 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
108 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
109 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
110 |
@Override |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
111 |
public Iterator<Path> iterator() { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
112 |
if (!isOpen) { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
113 |
throw new IllegalStateException("Directory stream is closed"); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
114 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
115 |
synchronized (this) { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
116 |
if (iterator != null) |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
117 |
throw new IllegalStateException("Iterator already obtained"); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
118 |
iterator = new WindowsDirectoryIterator(firstName); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
119 |
return iterator; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
120 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
121 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
122 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
123 |
private class WindowsDirectoryIterator implements Iterator<Path> { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
124 |
private boolean atEof; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
125 |
private String first; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
126 |
private Path nextEntry; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
127 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
128 |
WindowsDirectoryIterator(String first) { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
129 |
atEof = false; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
130 |
this.first = first; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
131 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
132 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
133 |
// applies filter and also ignores "." and ".." |
2071
5e6af6d106cb
6808647: (file) Paths.get("C:").newDirectoryStream() iterates over Path elements with additional slash [win]
alanb
parents:
2057
diff
changeset
|
134 |
private Path acceptEntry(String s, BasicFileAttributes attrs) { |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
135 |
if (s.equals(".") || s.equals("..")) |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
136 |
return null; |
2071
5e6af6d106cb
6808647: (file) Paths.get("C:").newDirectoryStream() iterates over Path elements with additional slash [win]
alanb
parents:
2057
diff
changeset
|
137 |
if (dir.needsSlashWhenResolving()) { |
5e6af6d106cb
6808647: (file) Paths.get("C:").newDirectoryStream() iterates over Path elements with additional slash [win]
alanb
parents:
2057
diff
changeset
|
138 |
StringBuilder sb = new StringBuilder(dir.toString()); |
5e6af6d106cb
6808647: (file) Paths.get("C:").newDirectoryStream() iterates over Path elements with additional slash [win]
alanb
parents:
2057
diff
changeset
|
139 |
sb.append('\\'); |
5e6af6d106cb
6808647: (file) Paths.get("C:").newDirectoryStream() iterates over Path elements with additional slash [win]
alanb
parents:
2057
diff
changeset
|
140 |
sb.append(s); |
5e6af6d106cb
6808647: (file) Paths.get("C:").newDirectoryStream() iterates over Path elements with additional slash [win]
alanb
parents:
2057
diff
changeset
|
141 |
s = sb.toString(); |
5e6af6d106cb
6808647: (file) Paths.get("C:").newDirectoryStream() iterates over Path elements with additional slash [win]
alanb
parents:
2057
diff
changeset
|
142 |
} else { |
5e6af6d106cb
6808647: (file) Paths.get("C:").newDirectoryStream() iterates over Path elements with additional slash [win]
alanb
parents:
2057
diff
changeset
|
143 |
s = dir + s; |
5e6af6d106cb
6808647: (file) Paths.get("C:").newDirectoryStream() iterates over Path elements with additional slash [win]
alanb
parents:
2057
diff
changeset
|
144 |
} |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
145 |
Path entry = WindowsPath |
2071
5e6af6d106cb
6808647: (file) Paths.get("C:").newDirectoryStream() iterates over Path elements with additional slash [win]
alanb
parents:
2057
diff
changeset
|
146 |
.createFromNormalizedPath(dir.getFileSystem(), s, attrs); |
3065
452aaa2899fc
6838333: New I/O: Update file system API to jsr203/nio2-b101
alanb
parents:
2071
diff
changeset
|
147 |
try { |
452aaa2899fc
6838333: New I/O: Update file system API to jsr203/nio2-b101
alanb
parents:
2071
diff
changeset
|
148 |
if (filter.accept(entry)) |
452aaa2899fc
6838333: New I/O: Update file system API to jsr203/nio2-b101
alanb
parents:
2071
diff
changeset
|
149 |
return entry; |
452aaa2899fc
6838333: New I/O: Update file system API to jsr203/nio2-b101
alanb
parents:
2071
diff
changeset
|
150 |
} catch (IOException ioe) { |
6537
7aa4e7bb5dae
6881498: (file) Re-examine DirectoryStream exception handling
alanb
parents:
5506
diff
changeset
|
151 |
throw new DirectoryIteratorException(ioe); |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
152 |
} |
3065
452aaa2899fc
6838333: New I/O: Update file system API to jsr203/nio2-b101
alanb
parents:
2071
diff
changeset
|
153 |
return null; |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
154 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
155 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
156 |
// reads next directory entry |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
157 |
private Path readNextEntry() { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
158 |
// handle first element returned by search |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
159 |
if (first != null) { |
2071
5e6af6d106cb
6808647: (file) Paths.get("C:").newDirectoryStream() iterates over Path elements with additional slash [win]
alanb
parents:
2057
diff
changeset
|
160 |
nextEntry = acceptEntry(first, null); |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
161 |
first = null; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
162 |
if (nextEntry != null) |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
163 |
return nextEntry; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
164 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
165 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
166 |
for (;;) { |
2071
5e6af6d106cb
6808647: (file) Paths.get("C:").newDirectoryStream() iterates over Path elements with additional slash [win]
alanb
parents:
2057
diff
changeset
|
167 |
String name = null; |
5e6af6d106cb
6808647: (file) Paths.get("C:").newDirectoryStream() iterates over Path elements with additional slash [win]
alanb
parents:
2057
diff
changeset
|
168 |
WindowsFileAttributes attrs; |
5e6af6d106cb
6808647: (file) Paths.get("C:").newDirectoryStream() iterates over Path elements with additional slash [win]
alanb
parents:
2057
diff
changeset
|
169 |
|
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
170 |
// synchronize on closeLock to prevent close while reading |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
171 |
synchronized (closeLock) { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
172 |
try { |
6537
7aa4e7bb5dae
6881498: (file) Re-examine DirectoryStream exception handling
alanb
parents:
5506
diff
changeset
|
173 |
if (isOpen) { |
7aa4e7bb5dae
6881498: (file) Re-examine DirectoryStream exception handling
alanb
parents:
5506
diff
changeset
|
174 |
name = FindNextFile(handle, findDataBuffer.address()); |
2071
5e6af6d106cb
6808647: (file) Paths.get("C:").newDirectoryStream() iterates over Path elements with additional slash [win]
alanb
parents:
2057
diff
changeset
|
175 |
} |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
176 |
} catch (WindowsException x) { |
6537
7aa4e7bb5dae
6881498: (file) Re-examine DirectoryStream exception handling
alanb
parents:
5506
diff
changeset
|
177 |
IOException ioe = x.asIOException(dir); |
7aa4e7bb5dae
6881498: (file) Re-examine DirectoryStream exception handling
alanb
parents:
5506
diff
changeset
|
178 |
throw new DirectoryIteratorException(ioe); |
7aa4e7bb5dae
6881498: (file) Re-examine DirectoryStream exception handling
alanb
parents:
5506
diff
changeset
|
179 |
} |
7aa4e7bb5dae
6881498: (file) Re-examine DirectoryStream exception handling
alanb
parents:
5506
diff
changeset
|
180 |
|
7aa4e7bb5dae
6881498: (file) Re-examine DirectoryStream exception handling
alanb
parents:
5506
diff
changeset
|
181 |
// NO_MORE_FILES or stream closed |
7aa4e7bb5dae
6881498: (file) Re-examine DirectoryStream exception handling
alanb
parents:
5506
diff
changeset
|
182 |
if (name == null) { |
7aa4e7bb5dae
6881498: (file) Re-examine DirectoryStream exception handling
alanb
parents:
5506
diff
changeset
|
183 |
atEof = true; |
7aa4e7bb5dae
6881498: (file) Re-examine DirectoryStream exception handling
alanb
parents:
5506
diff
changeset
|
184 |
return null; |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
185 |
} |
2071
5e6af6d106cb
6808647: (file) Paths.get("C:").newDirectoryStream() iterates over Path elements with additional slash [win]
alanb
parents:
2057
diff
changeset
|
186 |
|
5e6af6d106cb
6808647: (file) Paths.get("C:").newDirectoryStream() iterates over Path elements with additional slash [win]
alanb
parents:
2057
diff
changeset
|
187 |
// grab the attributes from the WIN32_FIND_DATA structure |
5e6af6d106cb
6808647: (file) Paths.get("C:").newDirectoryStream() iterates over Path elements with additional slash [win]
alanb
parents:
2057
diff
changeset
|
188 |
// (needs to be done while holding closeLock because close |
5e6af6d106cb
6808647: (file) Paths.get("C:").newDirectoryStream() iterates over Path elements with additional slash [win]
alanb
parents:
2057
diff
changeset
|
189 |
// will release the buffer) |
5e6af6d106cb
6808647: (file) Paths.get("C:").newDirectoryStream() iterates over Path elements with additional slash [win]
alanb
parents:
2057
diff
changeset
|
190 |
attrs = WindowsFileAttributes |
5e6af6d106cb
6808647: (file) Paths.get("C:").newDirectoryStream() iterates over Path elements with additional slash [win]
alanb
parents:
2057
diff
changeset
|
191 |
.fromFindData(findDataBuffer.address()); |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
192 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
193 |
|
2071
5e6af6d106cb
6808647: (file) Paths.get("C:").newDirectoryStream() iterates over Path elements with additional slash [win]
alanb
parents:
2057
diff
changeset
|
194 |
// return entry if accepted by filter |
5e6af6d106cb
6808647: (file) Paths.get("C:").newDirectoryStream() iterates over Path elements with additional slash [win]
alanb
parents:
2057
diff
changeset
|
195 |
Path entry = acceptEntry(name, attrs); |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
196 |
if (entry != null) |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
197 |
return entry; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
198 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
199 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
200 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
201 |
@Override |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
202 |
public synchronized boolean hasNext() { |
6537
7aa4e7bb5dae
6881498: (file) Re-examine DirectoryStream exception handling
alanb
parents:
5506
diff
changeset
|
203 |
if (nextEntry == null && !atEof) |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
204 |
nextEntry = readNextEntry(); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
205 |
return nextEntry != null; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
206 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
207 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
208 |
@Override |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
209 |
public synchronized Path next() { |
6537
7aa4e7bb5dae
6881498: (file) Re-examine DirectoryStream exception handling
alanb
parents:
5506
diff
changeset
|
210 |
Path result = null; |
7aa4e7bb5dae
6881498: (file) Re-examine DirectoryStream exception handling
alanb
parents:
5506
diff
changeset
|
211 |
if (nextEntry == null && !atEof) { |
7aa4e7bb5dae
6881498: (file) Re-examine DirectoryStream exception handling
alanb
parents:
5506
diff
changeset
|
212 |
result = readNextEntry(); |
7aa4e7bb5dae
6881498: (file) Re-examine DirectoryStream exception handling
alanb
parents:
5506
diff
changeset
|
213 |
} else { |
7aa4e7bb5dae
6881498: (file) Re-examine DirectoryStream exception handling
alanb
parents:
5506
diff
changeset
|
214 |
result = nextEntry; |
7aa4e7bb5dae
6881498: (file) Re-examine DirectoryStream exception handling
alanb
parents:
5506
diff
changeset
|
215 |
nextEntry = null; |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
216 |
} |
6537
7aa4e7bb5dae
6881498: (file) Re-examine DirectoryStream exception handling
alanb
parents:
5506
diff
changeset
|
217 |
if (result == null) |
7aa4e7bb5dae
6881498: (file) Re-examine DirectoryStream exception handling
alanb
parents:
5506
diff
changeset
|
218 |
throw new NoSuchElementException(); |
7aa4e7bb5dae
6881498: (file) Re-examine DirectoryStream exception handling
alanb
parents:
5506
diff
changeset
|
219 |
return result; |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
220 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
221 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
222 |
@Override |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
223 |
public void remove() { |
6537
7aa4e7bb5dae
6881498: (file) Re-examine DirectoryStream exception handling
alanb
parents:
5506
diff
changeset
|
224 |
throw new UnsupportedOperationException(); |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
225 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
226 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
diff
changeset
|
227 |
} |