0

当我想将 ResultScanner 对象写入磁盘时,我遇到了这个错误:

Exception in thread "main" java.io.WriteAbortedException: writing aborted; java.io.NotSerializableException: org.apache.hadoop.hbase.client.ClientScanner
    at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1351)
    at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:1988)
    at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1912)
    at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1795)
    at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1347)
    at java.io.ObjectInputStream.readObject(ObjectInputStream.java:369)
    at cache1.CacheManager.getCache(CacheManager.java:112)
    at cache1.Cache1.main(Cache1.java:43)
Caused by: java.io.NotSerializableException: org.apache.hadoop.hbase.client.ClientScanner
    at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1180)
    at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1528)
    at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1493)
    at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1416)
    at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1174)
    at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:346)
    at cache1.CacheManager.putCache(CacheManager.java:102)
    at cache1.Cache1.main(Cache1.java:41)

据我所知,问题在于 ResultScanner (ClientScanner) 不可序列化。由于我无权访问此类,我该如何解决这个序列化问题?或者有没有其他方法可以将此对象存储到文件中?

4

1 回答 1

0

不幸的是,您需要自己执行序列化,因为拥有 Serializable 接口 JVM 无法为您完成。

当您扩展此类时,您可以实现 readObject 和 writeObject 并通过自己存储所有状态来对其进行序列化(您还可以阅读:How to serialize a non-serializable in Java?)。

我希望这会有所帮助。

于 2013-05-21T09:09:48.867 回答