classlib: Add nio's channel interfaces (#751)

- Add the basic java.nio.channels.Channel interfaces.
 - Add several nio exception types.
 - Add UncheckedIOException
This commit is contained in:
Jonathan Coates 2023-09-21 08:20:24 +01:00 committed by GitHub
parent 010bb721f2
commit 6efade1b49
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 138 additions and 0 deletions

View File

@ -0,0 +1,15 @@
package org.teavm.classlib.java.io;
import java.io.IOException;
public class TUncheckedIOException extends RuntimeException {
private static final long serialVersionUID = 1645785175445590213L;
public TUncheckedIOException(IOException cause) {
super(cause);
}
public TUncheckedIOException(String message, IOException cause) {
super(message, cause);
}
}

View File

@ -0,0 +1,4 @@
package org.teavm.classlib.java.nio.channels;
public interface TByteChannel extends TReadableByteChannel, TWritableByteChannel {
}

View File

@ -0,0 +1,11 @@
package org.teavm.classlib.java.nio.channels;
import org.teavm.classlib.java.io.TCloseable;
import java.io.IOException;
public interface TChannel extends TCloseable {
boolean isOpen();
void close() throws IOException;
}

View File

@ -0,0 +1,7 @@
package org.teavm.classlib.java.nio.channels;
import java.io.IOException;
public class TClosedChannelException extends IOException {
private static final long serialVersionUID = 5928119801967419918L;
}

View File

@ -0,0 +1,5 @@
package org.teavm.classlib.java.nio.channels;
public class TNonReadableChannelException extends IllegalStateException {
private static final long serialVersionUID = -2344456823086925506L;
}

View File

@ -0,0 +1,5 @@
package org.teavm.classlib.java.nio.channels;
public class TNonWritableChannelException extends IllegalStateException {
private static final long serialVersionUID = -837317372114923332L;
}

View File

@ -0,0 +1,9 @@
package org.teavm.classlib.java.nio.channels;
import org.teavm.classlib.java.nio.TByteBuffer;
import java.io.IOException;
public interface TReadableByteChannel extends TChannel {
int read(TByteBuffer dst) throws IOException;
}

View File

@ -0,0 +1,13 @@
package org.teavm.classlib.java.nio.channels;
import java.io.IOException;
public interface TSeekableByteChannel extends TByteChannel {
long position();
TSeekableByteChannel position(long newPosition) throws IOException;
long size() throws IOException;
TSeekableByteChannel truncate(long size) throws IOException;
}

View File

@ -0,0 +1,9 @@
package org.teavm.classlib.java.nio.channels;
import org.teavm.classlib.java.nio.TByteBuffer;
import java.io.IOException;
public interface TWritableByteChannel extends TChannel {
int write(TByteBuffer src) throws IOException;
}

View File

@ -0,0 +1,13 @@
package org.teavm.classlib.java.nio.file;
public class TAccessDeniedException extends TFileSystemException {
private static final long serialVersionUID = 6428707745039365878L;
public TAccessDeniedException(String file) {
super(file);
}
public TAccessDeniedException(String file, String other, String reason) {
super(file, other, reason);
}
}

View File

@ -0,0 +1,47 @@
package org.teavm.classlib.java.nio.file;
import java.io.IOException;
public class TFileSystemException extends IOException {
private static final long serialVersionUID = 9093298181737952280L;
private final String file;
private final String other;
private final String reason;
public TFileSystemException(String file) {
this.file = file;
this.other = null;
this.reason = null;
}
public TFileSystemException(String file, String other, String reason) {
super(reason);
this.file = file;
this.other = other;
this.reason = reason;
}
public String getFile() {
return file;
}
public String getOtherFile() {
return other;
}
public String getReason() {
return reason;
}
@Override
public String getMessage() {
if (file == null && other == null) return reason;
StringBuilder out = new StringBuilder();
if (file != null) out.append(file);
if (other != null) out.append(" -> ").append(other);
if (reason != null) out.append(": ").append(reason);
return out.toString();
}
}