forked from KNEMC/KLALB
KLALB3.2
This commit is contained in:
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user