Skip to content

Commit

Permalink
Update CallerFinder
Browse files Browse the repository at this point in the history
  • Loading branch information
burningtnt committed Oct 16, 2024
1 parent 58e32c4 commit 9914658
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
4 changes: 2 additions & 2 deletions HMCL/src/main/java/org/jackhuang/hmcl/ui/nbt/NBTFileType.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import com.github.steveice10.opennbt.tag.builtin.IntTag;
import com.github.steveice10.opennbt.tag.builtin.ListTag;
import com.github.steveice10.opennbt.tag.builtin.Tag;
import org.apache.commons.compress.utils.BoundedInputStream;
import org.apache.commons.io.input.BoundedInputStream;
import org.jackhuang.hmcl.util.io.FileUtils;

import java.io.*;
Expand Down Expand Up @@ -77,7 +77,7 @@ public Tag read(File file) throws IOException {

InputStream input = new ByteArrayInputStream(buffer);
input.skip(5);
input = new BoundedInputStream(input, chunkLength - 1);
input = BoundedInputStream.builder().setInputStream(input).setMaxCount(chunkLength - 1).get();

switch (buffer[4]) {
case 0x01:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@
* @author Glavo
*/
final class CallerFinder {
private static final StackWalker WALKER = StackWalker.getInstance(StackWalker.Option.RETAIN_CLASS_REFERENCE);
private static final StackWalker WALKER = StackWalker.getInstance();
private static final String PACKAGE_PREFIX = CallerFinder.class.getPackageName() + ".";
private static final Predicate<StackWalker.StackFrame> PREDICATE = stackFrame -> !stackFrame.getClassName().startsWith(PACKAGE_PREFIX);
private static final Function<Stream<StackWalker.StackFrame>, Optional<StackWalker.StackFrame>> FUNCTION = stream -> stream.filter(PREDICATE).findFirst();
private static final Function<StackWalker.StackFrame, String> FRAME_MAPPING = frame -> frame.getClassName() + "." + frame.getMethodName();;

static String getCaller() {
return WALKER.walk(FUNCTION).map(it -> it.getClassName() + "." + it.getMethodName()).orElse(null);
return WALKER.walk(FUNCTION).map(FRAME_MAPPING).orElse(null);
}

private CallerFinder() {
Expand Down

0 comments on commit 9914658

Please sign in to comment.