From 3088db1a67daadda53afb2403bec7702f9c3e9bb Mon Sep 17 00:00:00 2001 From: Zack Buhman Date: Sun, 19 Jan 2025 02:12:29 -0600 Subject: [PATCH] wip --- classes/java/io/Closeable.java | 7 +++ classes/java/io/InputStream.java | 73 ++++++++++++++++++++++++++++++++ classes/java/nio/file/Files.java | 12 ++++++ 3 files changed, 92 insertions(+) create mode 100644 classes/java/io/Closeable.java create mode 100644 classes/java/io/InputStream.java create mode 100644 classes/java/nio/file/Files.java diff --git a/classes/java/io/Closeable.java b/classes/java/io/Closeable.java new file mode 100644 index 0000000..a1a7c16 --- /dev/null +++ b/classes/java/io/Closeable.java @@ -0,0 +1,7 @@ +package java.io; + +public interface Closeable + extends AutoCloseable { + + void close() throws IOException; +} diff --git a/classes/java/io/InputStream.java b/classes/java/io/InputStream.java new file mode 100644 index 0000000..d296dc5 --- /dev/null +++ b/classes/java/io/InputStream.java @@ -0,0 +1,73 @@ +package java.io; + +public abstract class InputStream + implements Closeable { + + public InputStream() { + } + + + public int available() throws IOException { + return 0; + } + + public void close() throws IOException { + } + + public void mark(int readlimit) { + } + + public abstract int read() throws IOException; + + public int read(byte[] b) throws IOException { + return read(b, 0, b.length); + } + + public int read(byte[] b, + int off, + int len) throws IOException { + if (off < 0 || len < 0 || len > b.length - off) + throw new IndexOutOfBoundsException(); + + if (b == null) + throw new NullPointerException(); + + for (int i = 0; i < len; i++) { + try { + int b = read(); + bool endOfStream = b == -1; + if (endOfStream) { + if (i == 0) + return -1; + else + return i; + } + b[off + i] = (byte)b; + } catch (IOException e) { + if (i == 0) + throw e; + else + return i; + } + } + + return len; + } + + public void reset() throws IOException { + throw new IOException(); + } + + public long skip(long n) + throws IOException { + + long ni = n; + while (ni > 0L) { + int b = read(); + if (b < 0) + break; + ni -= 1; + } + return n - ni; + } +} diff --git a/classes/java/nio/file/Files.java b/classes/java/nio/file/Files.java new file mode 100644 index 0000000..4dd12c6 --- /dev/null +++ b/classes/java/nio/file/Files.java @@ -0,0 +1,12 @@ +package java.nio.file; + +public final class Files { + + + public static InputStream newInputStream(Path path, + OpenOption... options) + throws IOException { + + + } +}