diff --git a/src/main/java/nl/sander/beejava/constantpool/ConstantPool.java b/src/main/java/nl/sander/beejava/constantpool/ConstantPool.java index f8a29bb..5263ad2 100644 --- a/src/main/java/nl/sander/beejava/constantpool/ConstantPool.java +++ b/src/main/java/nl/sander/beejava/constantpool/ConstantPool.java @@ -7,15 +7,6 @@ import java.util.ArrayList; public class ConstantPool extends ArrayList{ - public int getIndex(ConstantPoolEntry entry) { - for (int i = 0; i < size(); i++) { - if (get(i) == entry) { - return i + 1; - } - } - return -1; - } - public byte[] getBytes() { ByteBuf bytes = new ByteBuf(); forEach(entry -> bytes.addU8(entry.getBytes())); @@ -23,7 +14,10 @@ public class ConstantPool extends ArrayList{ } /** - * get the length +1 + * get the length for constant_pool_count in the class file + * + * 4.1. The ClassFile Structure + * The value of the constant_pool_count item is equal to the number of entries in the constant_pool table plus one */ public int getLength() { return size() + 1; diff --git a/src/main/java/nl/sander/beejava/util/ByteBuf.java b/src/main/java/nl/sander/beejava/util/ByteBuf.java index 1dd34ca..1f3d606 100644 --- a/src/main/java/nl/sander/beejava/util/ByteBuf.java +++ b/src/main/java/nl/sander/beejava/util/ByteBuf.java @@ -18,37 +18,6 @@ public class ByteBuf { data = ByteBuffer.allocate(initialSize); } - public String toString() { - return toString(StandardCharsets.UTF_8); - } - - public String toString(Charset charset) { - data.flip(); - - CharsetDecoder decoder = charset.newDecoder(); // decode is not threadsafe, might put it in threadlocal - // but I don't think this (newDecoder()+config) is expensive - - decoder.onMalformedInput(CodingErrorAction.REPLACE) - .onUnmappableCharacter(CodingErrorAction.REPLACE); - - try { - return decoder.decode(data).toString(); - } catch (CharacterCodingException e) { - throw new RuntimeException(e); - } - } - - public void clear() { - data.clear(); - } - - public void addU8(final byte c) { - if (data.remaining() == 0) { - enlarge(1); - } - data.put(c); - } - public void addU8(final byte[] bytes) { if (data.remaining() < bytes.length) { enlarge(bytes.length);