This commit is contained in:
Administrator
2025-04-24 10:16:38 +08:00
parent 6de65562be
commit 7267aec1fd
108 changed files with 7621 additions and 1890 deletions
+13 -2
View File
@@ -1,12 +1,15 @@
package org.kne.io;
import java.io.EOFException;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.channels.ReadableByteChannel;
import java.nio.channels.SocketChannel;
import java.nio.channels.WritableByteChannel;
public class KNEChannels {
private static class ByteBufferWritableByteChannel implements WritableByteChannel{
public static class ByteBufferWritableByteChannel implements WritableByteChannel{
private ByteBuffer bbf;
public ByteBuffer getBbf() {
@@ -29,6 +32,7 @@ public class KNEChannels {
public int write(ByteBuffer src) throws IOException {
int opos=src.position();
//System.out.println(bbf+" "+src);
//FastLib .bufferPut(bbf,src);
bbf.put(src);
return src.position()-opos;
}
@@ -36,7 +40,7 @@ public class KNEChannels {
public static WritableByteChannel newWritableChannel(ByteBuffer bbf) {
return new ByteBufferWritableByteChannel(bbf);
}
private static class ByteBufferReadableByteChannel implements ReadableByteChannel {
public static class ByteBufferReadableByteChannel implements ReadableByteChannel {
private ByteBuffer bbf;
public ByteBuffer getBbf() {
@@ -70,4 +74,11 @@ public class KNEChannels {
public static ReadableByteChannel newReadableChannel(ByteBuffer bbf) {
return new ByteBufferReadableByteChannel(bbf);
}
public static void readFully(ReadableByteChannel connectSocket, ByteBuffer szeRead) throws EOFException, IOException {
while (szeRead.hasRemaining()) {
if (connectSocket.read(szeRead) == -1) {
throw new EOFException();
}
}
}
}