170
171 @Override
172 public final Set<String> supportedFileAttributeViews() {
173 return supportedFileAttributeViews;
174 }
175
176 @Override
177 public final String toString() {
178 return "jrt:/";
179 }
180
181 @Override
182 public final String getSeparator() {
183 return "/";
184 }
185
186 @Override
187 public PathMatcher getPathMatcher(String syntaxAndInput) {
188 int pos = syntaxAndInput.indexOf(':');
189 if (pos <= 0 || pos == syntaxAndInput.length()) {
190 throw new IllegalArgumentException();
191 }
192 String syntax = syntaxAndInput.substring(0, pos);
193 String input = syntaxAndInput.substring(pos + 1);
194 String expr;
195 if (syntax.equalsIgnoreCase("glob")) {
196 expr = JrtUtils.toRegexPattern(input);
197 } else if (syntax.equalsIgnoreCase("regex")) {
198 expr = input;
199 } else {
200 throw new UnsupportedOperationException("Syntax '" + syntax
201 + "' not recognized");
202 }
203 // return matcher
204 final Pattern pattern = Pattern.compile(expr);
205 return (Path path) -> pattern.matcher(path.toString()).matches();
206 }
207
208 JrtPath resolveLink(JrtPath path) throws IOException {
209 Node node = checkNode(path);
210 if (node.isLink()) {
272 static boolean followLinks(LinkOption... options) {
273 if (options != null) {
274 for (LinkOption lo : options) {
275 Objects.requireNonNull(lo);
276 if (lo == LinkOption.NOFOLLOW_LINKS) {
277 return false;
278 } else {
279 throw new AssertionError("should not reach here");
280 }
281 }
282 }
283 return true;
284 }
285
286 // check that the options passed are supported by (read-only) jrt file system
287 static void checkOptions(Set<? extends OpenOption> options) {
288 // check for options of null type and option is an intance of StandardOpenOption
289 for (OpenOption option : options) {
290 Objects.requireNonNull(option);
291 if (!(option instanceof StandardOpenOption)) {
292 throw new IllegalArgumentException();
293 }
294 }
295 if (options.contains(StandardOpenOption.WRITE) ||
296 options.contains(StandardOpenOption.APPEND)) {
297 throw readOnly();
298 }
299 }
300
301 // clean up this file system - called from finalize and close
302 synchronized void cleanup() throws IOException {
303 if (isOpen) {
304 isOpen = false;
305 image.close();
306 image = null;
307 }
308 }
309
310 // These methods throw read only file system exception
311 final void setTimes(JrtPath jrtPath, FileTime mtime, FileTime atime, FileTime ctime)
312 throws IOException {
|
170
171 @Override
172 public final Set<String> supportedFileAttributeViews() {
173 return supportedFileAttributeViews;
174 }
175
176 @Override
177 public final String toString() {
178 return "jrt:/";
179 }
180
181 @Override
182 public final String getSeparator() {
183 return "/";
184 }
185
186 @Override
187 public PathMatcher getPathMatcher(String syntaxAndInput) {
188 int pos = syntaxAndInput.indexOf(':');
189 if (pos <= 0 || pos == syntaxAndInput.length()) {
190 throw new IllegalArgumentException("pos is " + pos);
191 }
192 String syntax = syntaxAndInput.substring(0, pos);
193 String input = syntaxAndInput.substring(pos + 1);
194 String expr;
195 if (syntax.equalsIgnoreCase("glob")) {
196 expr = JrtUtils.toRegexPattern(input);
197 } else if (syntax.equalsIgnoreCase("regex")) {
198 expr = input;
199 } else {
200 throw new UnsupportedOperationException("Syntax '" + syntax
201 + "' not recognized");
202 }
203 // return matcher
204 final Pattern pattern = Pattern.compile(expr);
205 return (Path path) -> pattern.matcher(path.toString()).matches();
206 }
207
208 JrtPath resolveLink(JrtPath path) throws IOException {
209 Node node = checkNode(path);
210 if (node.isLink()) {
272 static boolean followLinks(LinkOption... options) {
273 if (options != null) {
274 for (LinkOption lo : options) {
275 Objects.requireNonNull(lo);
276 if (lo == LinkOption.NOFOLLOW_LINKS) {
277 return false;
278 } else {
279 throw new AssertionError("should not reach here");
280 }
281 }
282 }
283 return true;
284 }
285
286 // check that the options passed are supported by (read-only) jrt file system
287 static void checkOptions(Set<? extends OpenOption> options) {
288 // check for options of null type and option is an intance of StandardOpenOption
289 for (OpenOption option : options) {
290 Objects.requireNonNull(option);
291 if (!(option instanceof StandardOpenOption)) {
292 throw new IllegalArgumentException(
293 "option class : " + option.getClass().getName());
294 }
295 }
296 if (options.contains(StandardOpenOption.WRITE) ||
297 options.contains(StandardOpenOption.APPEND)) {
298 throw readOnly();
299 }
300 }
301
302 // clean up this file system - called from finalize and close
303 synchronized void cleanup() throws IOException {
304 if (isOpen) {
305 isOpen = false;
306 image.close();
307 image = null;
308 }
309 }
310
311 // These methods throw read only file system exception
312 final void setTimes(JrtPath jrtPath, FileTime mtime, FileTime atime, FileTime ctime)
313 throws IOException {
|