src/java.base/share/classes/jdk/internal/jrtfs/JrtFileSystem.java

Print this page
rev 11561 : 8073445: (fs) FileSystem.getPathMatcher(...) should check syntax component without regard to case
Summary: Change String equals() to equalsIgnoreCase() where needed.
Reviewed-by: alanb
   1 /*
   2  * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  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


 236         return supportedFileAttributeViews;
 237     }
 238 
 239     @Override
 240     public String toString() {
 241         return "jrt:/";
 242     }
 243 
 244     private static final String GLOB_SYNTAX = "glob";
 245     private static final String REGEX_SYNTAX = "regex";
 246 
 247     @Override
 248     public PathMatcher getPathMatcher(String syntaxAndInput) {
 249         int pos = syntaxAndInput.indexOf(':');
 250         if (pos <= 0 || pos == syntaxAndInput.length()) {
 251             throw new IllegalArgumentException();
 252         }
 253         String syntax = syntaxAndInput.substring(0, pos);
 254         String input = syntaxAndInput.substring(pos + 1);
 255         String expr;
 256         if (syntax.equals(GLOB_SYNTAX)) {
 257             expr = JrtUtils.toRegexPattern(input);
 258         } else {
 259             if (syntax.equals(REGEX_SYNTAX)) {
 260                 expr = input;
 261             } else {
 262                 throw new UnsupportedOperationException("Syntax '" + syntax
 263                         + "' not recognized");
 264             }
 265         }
 266         // return matcher
 267         final Pattern pattern = Pattern.compile(expr);
 268         return (Path path) -> pattern.matcher(path.toString()).matches();
 269     }
 270 
 271     static byte[] getBytes(String name) {
 272         return name.getBytes(UTF_8);
 273     }
 274 
 275     static String getString(byte[] name) {
 276         return new String(name, UTF_8);
 277     }
 278 
 279     private static class NodeAndImage {


   1 /*
   2  * Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  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


 236         return supportedFileAttributeViews;
 237     }
 238 
 239     @Override
 240     public String toString() {
 241         return "jrt:/";
 242     }
 243 
 244     private static final String GLOB_SYNTAX = "glob";
 245     private static final String REGEX_SYNTAX = "regex";
 246 
 247     @Override
 248     public PathMatcher getPathMatcher(String syntaxAndInput) {
 249         int pos = syntaxAndInput.indexOf(':');
 250         if (pos <= 0 || pos == syntaxAndInput.length()) {
 251             throw new IllegalArgumentException();
 252         }
 253         String syntax = syntaxAndInput.substring(0, pos);
 254         String input = syntaxAndInput.substring(pos + 1);
 255         String expr;
 256         if (syntax.equalsIgnoreCase(GLOB_SYNTAX)) {
 257             expr = JrtUtils.toRegexPattern(input);
 258         } else {
 259             if (syntax.equalsIgnoreCase(REGEX_SYNTAX)) {
 260                 expr = input;
 261             } else {
 262                 throw new UnsupportedOperationException("Syntax '" + syntax
 263                         + "' not recognized");
 264             }
 265         }
 266         // return matcher
 267         final Pattern pattern = Pattern.compile(expr);
 268         return (Path path) -> pattern.matcher(path.toString()).matches();
 269     }
 270 
 271     static byte[] getBytes(String name) {
 272         return name.getBytes(UTF_8);
 273     }
 274 
 275     static String getString(byte[] name) {
 276         return new String(name, UTF_8);
 277     }
 278 
 279     private static class NodeAndImage {