< prev index next >
src/java.base/share/classes/jdk/internal/jimage/UTF8String.java
Print this page
@@ -27,18 +27,22 @@
import java.nio.charset.Charset;
import java.util.Arrays;
public final class UTF8String implements CharSequence {
-
// Same as StandardCharsets.UTF_8 without loading all of the standard charsets
static final Charset UTF_8 = Charset.forName("UTF-8");
static final int NOT_FOUND = -1;
static final int HASH_MULTIPLIER = 0x01000193;
static final UTF8String EMPTY_STRING = new UTF8String("");
- static final UTF8String CLASS_STRING = new UTF8String(".class");
+ static final UTF8String SLASH_STRING = new UTF8String("/");
+ static final UTF8String DOT_STRING = new UTF8String(".");
+
+ // TODO This strings are implementation specific and should be defined elsewhere.
+ static final UTF8String MODULES_STRING = new UTF8String("/modules");
+ static final UTF8String PACKAGES_STRING = new UTF8String("/packages");
final byte[] bytes;
final int offset;
final int count;
int hashcode;
@@ -158,12 +162,12 @@
}
return seed & 0x7FFFFFFF;
}
- int hashCode(int base) {
- return hashCode(base, bytes, offset, count);
+ int hashCode(int seed) {
+ return hashCode(seed, bytes, offset, count);
}
@Override
public int hashCode() {
if (hashcode < 0) {
@@ -184,11 +188,11 @@
}
return equals(this, (UTF8String)obj);
}
- private static boolean equals(UTF8String a, UTF8String b) {
+ public static boolean equals(UTF8String a, UTF8String b) {
if (a == b) {
return true;
}
int count = a.count;
@@ -209,10 +213,14 @@
}
return true;
}
+ public byte[] getBytesCopy() {
+ return Arrays.copyOfRange(bytes, offset, offset + count);
+ }
+
byte[] getBytes() {
if (offset != 0 || bytes.length != count) {
return Arrays.copyOfRange(bytes, offset, offset + count);
}
@@ -230,35 +238,13 @@
@Override
public char charAt(int index) {
int ch = byteAt(index);
- return (ch & 0x80) != 0 ? (char)ch : '\0';
+ return (ch & 0x80) == 0 ? (char)ch : '\0';
}
@Override
public CharSequence subSequence(int start, int end) {
return (CharSequence)substring(start, end - start);
}
-
- static UTF8String match(UTF8String a, UTF8String b) {
- int aCount = a.count;
- int bCount = b.count;
-
- if (aCount < bCount) {
- return null;
- }
-
- byte[] aBytes = a.bytes;
- byte[] bBytes = b.bytes;
- int aOffset = a.offset;
- int bOffset = b.offset;
-
- for (int i = 0; i < bCount; i++) {
- if (aBytes[aOffset + i] != bBytes[bOffset + i]) {
- return null;
- }
- }
-
- return new UTF8String(aBytes, aOffset + bCount, aCount - bCount);
- }
}
< prev index next >