首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >制作我自己的AsynchronousSocketChannel

制作我自己的AsynchronousSocketChannel
EN

Stack Overflow用户
提问于 2013-02-21 10:03:50
回答 1查看 487关注 0票数 1

我正在编写一个需要将加密数据从一台PC发送到另一台PC的程序。我不想每次都显式地加密/解密数据,然后使用AsynchronousSocketChannel发送数据,而是想知道是否可以以某种方式扩展AsynchronousSocketChannel.write和AsynchronousSocketChannel.read的功能来为我做这件事。不过,看起来AsynchronousSocketChannel.write是最终的方法。有没有办法制作我自己的AsynchronousSocketChannel,或者这是违反直觉的吗?

在此之前,非常感谢您。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-02-21 10:19:08

您可以将其封装在您自己的类中:

代码语言:javascript
复制
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);
    }
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/14993394

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档