我正在编写一个需要将加密数据从一台PC发送到另一台PC的程序。我不想每次都显式地加密/解密数据,然后使用AsynchronousSocketChannel发送数据,而是想知道是否可以以某种方式扩展AsynchronousSocketChannel.write和AsynchronousSocketChannel.read的功能来为我做这件事。不过,看起来AsynchronousSocketChannel.write是最终的方法。有没有办法制作我自己的AsynchronousSocketChannel,或者这是违反直觉的吗?
在此之前,非常感谢您。
发布于 2013-02-21 10:19:08
您可以将其封装在您自己的类中:
import java.nio.ByteBuffer;
import java.nio.channels.AsynchronousSocketChannel;
import java.util.concurrent.Future;
public class EncryptedAsynchronousSocketChannel {
private AsynchronousSocketChannel channel;
public Future<Integer> read(ByteBuffer dst){
return channel.read(dst);
}
public Future<Integer> write(ByteBuffer src){
return channel.write(src);
}
}https://stackoverflow.com/questions/14993394
复制相似问题