src/solaris/classes/java/io/UnixFileSystem.java

Print this page

        

*** 1,7 **** /* ! * Copyright (c) 1998, 2010, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this --- 1,7 ---- /* ! * Copyright (c) 1998, 2013, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this
*** 53,98 **** public char getPathSeparator() { return colon; } ! /* A normal Unix pathname contains no duplicate slashes and does not end ! with a slash. It may be the empty string. */ ! ! /* Normalize the given pathname, whose length is len, starting at the given ! offset; everything before this offset is already normal. */ ! private String normalize(String pathname, int len, int off) { ! if (len == 0) return pathname; ! int n = len; ! while ((n > 0) && (pathname.charAt(n - 1) == '/')) n--; ! if (n == 0) return "/"; ! StringBuffer sb = new StringBuffer(pathname.length()); ! if (off > 0) sb.append(pathname.substring(0, off)); char prevChar = 0; ! for (int i = off; i < n; i++) { char c = pathname.charAt(i); if ((prevChar == '/') && (c == '/')) continue; sb.append(c); prevChar = c; } - return sb.toString(); - } ! /* Check that the given pathname is normal. If not, invoke the real ! normalizer on the part of the pathname that requires normalization. ! This way we iterate through the whole pathname string only once. */ ! public String normalize(String pathname) { ! int n = pathname.length(); ! char prevChar = 0; ! for (int i = 0; i < n; i++) { ! char c = pathname.charAt(i); ! if ((prevChar == '/') && (c == '/')) ! return normalize(pathname, n, i - 1); ! prevChar = c; ! } ! if (prevChar == '/') return normalize(pathname, n, n - 1); ! return pathname; } public int prefixLength(String pathname) { if (pathname.length() == 0) return 0; return (pathname.charAt(0) == '/') ? 1 : 0; --- 53,86 ---- public char getPathSeparator() { return colon; } ! /* ! * A normal Unix path name contains no duplicate slashes and does not end ! * with a slash. It may be the empty string. Check and normalize the ! * given pathname. The whole pathname string is only iterated once. ! */ ! @Override ! public String normalize(String pathname) { ! final int len = pathname.length(); ! StringBuilder sb = new StringBuilder(len); char prevChar = 0; ! ! for (int i = 0; i < len; i++) { char c = pathname.charAt(i); + if (c == CHAR_NUL) continue; if ((prevChar == '/') && (c == '/')) continue; + sb.append(c); prevChar = c; } ! if (prevChar == '/' && sb.length() > 1) ! sb.setLength(sb.length() - 1); ! ! return sb.toString(); } public int prefixLength(String pathname) { if (pathname.length() == 0) return 0; return (pathname.charAt(0) == '/') ? 1 : 0;