private StringSequence decode(StringSequence source) { if (source.isEmpty() || (source.indexOf('%') < 0)) { return source; } ByteArrayOutputStream bos = new ByteArrayOutputStream(source.length()); write(source.toString(), bos); // AsciiBytes is what is used to store the JarEntries so make it symmetric return new StringSequence(AsciiBytes.toString(bos.toByteArray())); }
private static int indexOfRootSpec(StringSequence file, String pathFromRoot) { int separatorIndex = file.indexOf(SEPARATOR); if (separatorIndex < 0 || !file.startsWith(pathFromRoot, separatorIndex)) { return -1; } return separatorIndex + SEPARATOR.length() + pathFromRoot.length(); }
public StringSequence subSequence(int start) { return subSequence(start, length()); }
static JarURLConnection get(URL url, JarFile jarFile) throws IOException { StringSequence spec = new StringSequence(url.getFile()); int index = indexOfRootSpec(spec, jarFile.getPathFromRoot()); if (index == -1) { return (Boolean.TRUE.equals(useFastExceptions.get()) ? NOT_FOUND_CONNECTION : new JarURLConnection(url, null, EMPTY_JAR_ENTRY_NAME)); } int separator; while ((separator = spec.indexOf(SEPARATOR, index)) > 0) { JarEntryName entryName = JarEntryName.get(spec.subSequence(index, separator)); JarEntry jarEntry = jarFile.getJarEntry(entryName.toCharSequence()); if (jarEntry == null) { return JarURLConnection.notFound(jarFile, entryName); } jarFile = jarFile.getNestedJarFile(jarEntry); index = separator + SEPARATOR.length(); } JarEntryName jarEntryName = JarEntryName.get(spec, index); if (Boolean.TRUE.equals(useFastExceptions.get()) && !jarEntryName.isEmpty() && !jarFile.containsEntry(jarEntryName.toString())) { return NOT_FOUND_CONNECTION; } return new JarURLConnection(url, jarFile, jarEntryName); }
public boolean startsWith(CharSequence prefix, int offset) { int prefixLength = prefix.length(); if (length() - prefixLength - offset < 0) { return false; } int prefixOffset = 0; int sourceOffset = offset; while (prefixLength-- != 0) { if (charAt(sourceOffset++) != prefix.charAt(prefixOffset++)) { return false; } } return true; }
public boolean isEmpty() { return length() == 0; }
@Override public String toString() { return this.name.toString(); }
public boolean startsWith(CharSequence prefix) { return startsWith(prefix, 0); }
public boolean isEmpty() { return this.name.isEmpty(); }
@Override public StringSequence subSequence(int start, int end) { int subSequenceStart = this.start + start; int subSequenceEnd = this.start + end; if (subSequenceStart > this.end) { throw new StringIndexOutOfBoundsException(start); } if (subSequenceEnd > this.end) { throw new StringIndexOutOfBoundsException(end); } if (start == 0 && subSequenceEnd == this.end) { return this; } return new StringSequence(this.source, subSequenceStart, subSequenceEnd); }
@Override public boolean equals(Object obj) { if (this == obj) { return true; } if (!(obj instanceof CharSequence)) { return false; } CharSequence other = (CharSequence) obj; int n = length(); if (n != other.length()) { return false; } int i = 0; while (n-- != 0) { if (charAt(i) != other.charAt(i)) { return false; } i++; } return true; }
@Override public int hashCode() { int hash = this.hash; if (hash == 0 && length() > 0) { for (int i = this.start; i < this.end; i++) { hash = 31 * hash + this.source.charAt(i); } this.hash = hash; } return hash; }
public static JarEntryName get(StringSequence spec, int beginIndex) { if (spec.length() <= beginIndex) { return EMPTY_JAR_ENTRY_NAME; } return new JarEntryName(spec.subSequence(beginIndex)); }