From 0b9378daeb3279c33547c4c472aba217c7215e8e Mon Sep 17 00:00:00 2001 From: Nathan Diepeveen <62761434+NexelOfficial@users.noreply.github.com> Date: Tue, 25 Jun 2024 15:18:24 +0200 Subject: [PATCH] feat: basic file implementation (#44) --- src/java.ts | 121 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 121 insertions(+) diff --git a/src/java.ts b/src/java.ts index 7c7939f..c626ed5 100644 --- a/src/java.ts +++ b/src/java.ts @@ -24,6 +24,52 @@ declare global { } } namespace util { + class Scanner { + constructor(source: io.File); + constructor(source: io.File, charsetName: string); + constructor(source: string); + + close(): void; + findInLine(pattern: string): string | null; + findWithinHorizon(pattern: string, horizon: number): string | null; + hasNext(): boolean; + hasNext(pattern: string): boolean; + hasNextBigDecimal(): boolean; + hasNextBigInteger(): boolean; + hasNextBigInteger(radix: number): boolean; + hasNextBoolean(): boolean; + hasNextByte(): boolean; + hasNextByte(radix: number): boolean; + hasNextDouble(): boolean; + hasNextFloat(): boolean; + hasNextInt(): boolean; + hasNextInt(radix: number): boolean; + hasNextLine(): boolean; + hasNextLong(): boolean; + hasNextLong(radix: number): boolean; + hasNextShort(): boolean; + hasNextShort(radix: number): boolean; + next(): string; + next(pattern: string): string; + nextBoolean(): boolean; + nextDouble(): number; + nextFloat(): number; + nextInt(): number; + nextInt(radix: number): number; + nextLine(): string; + nextLong(): number; + nextLong(radix: number): number; + nextShort(): number; + nextShort(radix: number): number; + radix(): number; + remove(): void; + reset(): Scanner; + skip(pattern: string): Scanner; + toString(): string; + useDelimiter(pattern: string): Scanner; + useRadix(radix: number): Scanner; + } + interface Collection extends java.lang.Iterable { add(value: T): boolean; addAll(collection: java.util.Collection): boolean; @@ -126,5 +172,80 @@ declare global { interface Pattern {} } } + namespace io { + class File { + constructor(parent: File, child: string); + constructor(pathName: string); + constructor(parent: string, child: string); + + canExecute(): boolean; + canRead(): boolean; + canWrite(): boolean; + compareTo(pathname: File): number; + createNewFile(): boolean; + static createTempFile(prefix: string, suffix: string): File; + static createTempFile(prefix: string, suffix: string, directory: File): File; + delete(): boolean; + deleteOnExit(): void; + exists(): boolean; + getAbsoluteFile(): File; + getAbsolutePath(): string; + getCanonicalFile(): File; + getCanonicalPath(): string; + getFreeSpace(): number; + getName(): string; + getParent(): string | null; + getParentFile(): File | null; + getPath(): string; + getTotalSpace(): number; + getUsableSpace(): number; + hashCode(): number; + isAbsolute(): boolean; + isDirectory(): boolean; + isFile(): boolean; + isHidden(): boolean; + lastModified(): number; + length(): number; + list(): string[] | null; + listFiles(): File[] | null; + static listRoots(): File[]; + mkdir(): boolean; + mkdirs(): boolean; + renameTo(dest: File): boolean; + setExecutable(executable: boolean): boolean; + setExecutable(executable: boolean, ownerOnly: boolean): boolean; + setLastModified(time: number): boolean; + setReadable(readable: boolean): boolean; + setReadable(readable: boolean, ownerOnly: boolean): boolean; + setReadOnly(): boolean; + setWritable(writable: boolean): boolean; + setWritable(writable: boolean, ownerOnly: boolean): boolean; + toString(): string; + } + + class FileWriter { + constructor(file: File); + constructor(file: File, append: boolean); + constructor(fileName: string); + constructor(fileName: string, append: boolean); + + close(): void; + flush(): void; + getEncoding(): string | null; + write(c: number): void; + write(str: string, off?: number, len?: number): void; + } + + class FileReader { + constructor(file: File); + constructor(fileName: string); + + close(): void; + getEncoding(): string; + read(c: number): number; + read(cbuf: Uint8Array, off: number, len: number): number; + ready(): boolean; + } + } } }