mirror of
https://github.com/corda/corda.git
synced 2025-01-09 06:23:04 +00:00
6e7149061c
The main idea is to make DatagramChannel and *SocketChannel behave in a way that more closely matches the standard, e.g. allow binding sockets to addresses without necessarily listening on those addresses and accept null addresses where appropriate. It also avoids multiple redundant DNS lookups. This commit also implements CharBuffer and BindException, and adds the Readable interface.
59 lines
1.4 KiB
Java
59 lines
1.4 KiB
Java
/* Copyright (c) 2008-2013, Avian Contributors
|
|
|
|
Permission to use, copy, modify, and/or distribute this software
|
|
for any purpose with or without fee is hereby granted, provided
|
|
that the above copyright notice and this permission notice appear
|
|
in all copies.
|
|
|
|
There is NO WARRANTY for this software. See license.txt for
|
|
details. */
|
|
|
|
package java.io;
|
|
|
|
import java.nio.CharBuffer;
|
|
|
|
public abstract class Reader implements Closeable, Readable {
|
|
public int read(CharBuffer buffer) throws IOException {
|
|
int c = read(buffer.array(),
|
|
buffer.arrayOffset() + buffer.position(),
|
|
buffer.remaining());
|
|
|
|
if (c > 0) {
|
|
buffer.position(buffer.position() + c);
|
|
}
|
|
|
|
return c;
|
|
}
|
|
|
|
public int read() throws IOException {
|
|
char[] buffer = new char[1];
|
|
int c = read(buffer);
|
|
if (c <= 0) {
|
|
return -1;
|
|
} else {
|
|
return (int) buffer[0];
|
|
}
|
|
}
|
|
|
|
public int read(char[] buffer) throws IOException {
|
|
return read(buffer, 0, buffer.length);
|
|
}
|
|
|
|
public abstract int read(char[] buffer, int offset, int length)
|
|
throws IOException;
|
|
|
|
public boolean markSupported() {
|
|
return false;
|
|
}
|
|
|
|
public void mark(int readAheadLimit) throws IOException {
|
|
throw new IOException("mark not supported");
|
|
}
|
|
|
|
public void reset() throws IOException {
|
|
throw new IOException("reset not supported");
|
|
}
|
|
|
|
public abstract void close() throws IOException;
|
|
}
|