如何序列化ByteBuffer [英] How to serialize ByteBuffer

查看:64
本文介绍了如何序列化ByteBuffer的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望使用RMI在网络上发送java.nio.ByteBuffer,但是ByteBuffer不可序列化.我尝试了以下自定义类,但无济于事:

I wish to send a java.nio.ByteBuffer accross a network using RMI, however ByteBuffer isn't serializable. I've tried the following custom class to no avail:

public class NetByteBuffer implements java.io.Serializable {

ByteBuffer buffer;

public NetByteBuffer(ByteBuffer buffer) {
    this.buffer = buffer;
}

public ByteBuffer getByteBuffer() {
    return this.buffer;
}

}

客户端仍然收到不可序列化的异常.有什么想法吗?

The client still gets a non-serialzable exception. Any ideas?

谢谢

推荐答案

您不能.您最好获取 byte [] 并发送,然后在另一侧重建 ByteBuffer .您当然会失去它作为缓冲区的优势.

You can't. You'd better obtain the byte[] and send it instead and reconstruct the ByteBuffer on the other side. You are of course losing the advantages of it being a buffer.

这篇关于如何序列化ByteBuffer的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆