Skip to content

Commit

Permalink
some more missing stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
wagyourtail committed Aug 21, 2024
1 parent b0506a2 commit 7fb7040
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import java.io.IOException;
import java.io.UncheckedIOException;
import java.nio.CharBuffer;
import java.util.Arrays;
import java.util.Objects;

@Adapter("java/util/HexFormat")
Expand Down Expand Up @@ -44,6 +45,10 @@ public J_U_HexFormat withLowerCase() {
return new J_U_HexFormat(delimiter, prefix, suffix, lowercase);
}

public boolean isUpperCase() {
return Arrays.equals(digits, uppercase);
}

public String formatHex(byte[] bytes) {
return formatHex(bytes, 0, bytes.length);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,32 @@
import xyz.wagyourtail.jvmdg.version.Stub;

import java.lang.invoke.MethodHandles;
import java.util.concurrent.CompletableFuture;
import java.util.stream.Stream;

public class J_L_Process {
private static final MethodHandles.Lookup IMPL_LOOKUP = Utils.getImplLookup();

@Stub
public static long pid(Process process) throws Throwable {
return (long) IMPL_LOOKUP.findGetter(process.getClass(), "pid", int.class).invoke(process);
}


public static CompletableFuture<Process> onExit(Process process) {
return CompletableFuture.supplyAsync(() -> {
try {
process.waitFor();
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
return process;
});
}

@Stub
public static J_L_ProcessHandle toHandle(Process process) throws Throwable {
long pid = (long) IMPL_LOOKUP.findGetter(process.getClass(), "pid", int.class).invoke(process);
return J_L_ProcessHandle.of(pid).get();
return J_L_ProcessHandle.of(pid(process)).get();
}

@Stub
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,41 @@

import xyz.wagyourtail.jvmdg.version.Stub;

import java.io.File;
import java.io.IOException;
import java.nio.file.FileSystems;
import java.nio.file.Path;
import java.nio.file.WatchEvent;
import java.nio.file.WatchKey;
import java.nio.file.WatchService;
import java.util.Iterator;
import java.util.NoSuchElementException;

public class J_N_F_Path {

@Stub(abstractDefault = true)
public static File toFile(Path path) {
if (path.getFileSystem() == FileSystems.getDefault()) {
return new File(path.toString());
}
throw new UnsupportedOperationException("Path not associated with default filesystem.");
}

@Stub(abstractDefault = true)
public static boolean startsWith(Path path, String other) {
return path.startsWith(path.getFileSystem().getPath(other));
}

@Stub(abstractDefault = true)
public static boolean endsWith(Path path, String other) {
return path.endsWith(path.getFileSystem().getPath(other));
}

@Stub(abstractDefault = true)
public static WatchKey register(Path path, WatchService watcher, WatchEvent.Kind<?>... events) throws IOException {
return path.register(watcher, events, new WatchEvent.Modifier[0]);
}

@Stub(abstractDefault = true)
public static Path resolve(Path self, String other) throws Throwable {
return self.resolve(self.getFileSystem().getPath(other));
Expand Down

0 comments on commit 7fb7040

Please sign in to comment.