/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/**
* Unix specific Path <--> URI conversion
*/
class UnixUriUtils {
private UnixUriUtils() { }
/**
* Converts URI to Path
*/
if (!uri.isAbsolute())
throw new IllegalArgumentException("URI is not absolute");
throw new IllegalArgumentException("URI is not hierarchical");
throw new IllegalArgumentException("URI scheme is not \"file\"");
throw new IllegalArgumentException("URI has an authority component");
throw new IllegalArgumentException("URI has a fragment component");
throw new IllegalArgumentException("URI has a query component");
// compatability with java.io.File
// transformation use raw path
if (len == 0)
throw new IllegalArgumentException("URI path component is empty");
// transform escaped octets and unescaped characters to bytes
len--;
int rlen = 0;
int pos = 0;
byte b;
if (c == '%') {
if (b == 0)
throw new IllegalArgumentException("Nul character not allowed");
} else {
assert c < 0x80;
b = (byte)c;
}
}
}
/**
* Converts Path to URI
*/
char c = (char)(path[i] & 0xff);
} else {
}
}
// trailing slash if directory
try {
} catch (UnixException x) {
// ignore
}
}
try {
} catch (URISyntaxException x) {
throw new AssertionError(x); // should not happen
}
}
// The following is copied from java.net.URI
// Compute the low-order mask for the characters in the given string
long m = 0;
for (int i = 0; i < n; i++) {
if (c < 64)
m |= (1L << c);
}
return m;
}
// Compute the high-order mask for the characters in the given string
long m = 0;
for (int i = 0; i < n; i++) {
if ((c >= 64) && (c < 128))
m |= (1L << (c - 64));
}
return m;
}
// Compute a low-order mask for the characters
// between first and last, inclusive
long m = 0;
for (int i = f; i <= l; i++)
m |= 1L << i;
return m;
}
// Compute a high-order mask for the characters
// between first and last, inclusive
long m = 0;
for (int i = f; i <= l; i++)
m |= 1L << i;
return m;
}
// Tell whether the given character is permitted by the given mask pair
if (c < 64)
if (c < 128)
return false;
}
// decode
private static int decode(char c) {
if ((c >= '0') && (c <= '9'))
return c - '0';
if ((c >= 'a') && (c <= 'f'))
return c - 'a' + 10;
if ((c >= 'A') && (c <= 'F'))
return c - 'A' + 10;
throw new AssertionError();
}
// digit = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" |
// "8" | "9"
// upalpha = "A" | "B" | "C" | "D" | "E" | "F" | "G" | "H" | "I" |
// "J" | "K" | "L" | "M" | "N" | "O" | "P" | "Q" | "R" |
// "S" | "T" | "U" | "V" | "W" | "X" | "Y" | "Z"
// lowalpha = "a" | "b" | "c" | "d" | "e" | "f" | "g" | "h" | "i" |
// "j" | "k" | "l" | "m" | "n" | "o" | "p" | "q" | "r" |
// "s" | "t" | "u" | "v" | "w" | "x" | "y" | "z"
// alpha = lowalpha | upalpha
// alphanum = alpha | digit
// mark = "-" | "_" | "." | "!" | "~" | "*" | "'" |
// "(" | ")"
// unreserved = alphanum | mark
// pchar = unreserved | escaped |
// ":" | "@" | "&" | "=" | "+" | "$" | ","
private static final long L_PCHAR
private static final long H_PCHAR
// All valid path characters
private final static char[] hexDigits = {
'0', '1', '2', '3', '4', '5', '6', '7',
'8', '9', 'A', 'B', 'C', 'D', 'E', 'F'
};
}