NotSerializableException: java.io.FileInputStream [英] NotSerializableException: java.io.FileInputStream
本文介绍了NotSerializableException: java.io.FileInputStream的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的应用程序抛出此错误:
java.rmi.UnmarshalException:错误解组返回;嵌套异常是:java.io.WriteAbortedException:写入中止;java.io.NotSerializableException: java.io.FileInputStream在 java.rmi/sun.rmi.server.UnicastRef.invoke(UnicastRef.java:194)在 java.rmi/java.rmi.server.RemoteObjectInvocationHandler.invokeRemoteMethod(RemoteObjectInvocationHandler.java:209)在 java.rmi/java.rmi.server.RemoteObjectInvocationHandler.invoke(RemoteObjectInvocationHandler.java:161)在 com.sun.proxy.$Proxy40.getEntityBlob(来源不明)在 com.mycompany.backend.repository.EntityRepositoryImpl.getEntityBlob(EntityRepositoryImpl.java:260)
客户"RMI 方法的一面是这样的:
Registry registry = LocateRegistry.getRegistry();EntityRepository 存储库 =(EntityRepository) registry.lookup(EntityRepository.class.getName());返回 repository.getEntityBlob(appId, namespace, entityType, entityId, blobKey);
还有服务器"这边是这个
public InputStream getEntityBlob(字符串应用程序ID,字符串命名空间,字符串实体类型,最终字符串 entityId,final String blobKey) 抛出 RemoteException {final InputStream[] inputStream = new InputStream[1];manager.transactPersistentEntityStore(xodusRoot, appId, true, txn -> {EntityId idOfEntity = txn.toEntityId(entityId);最终实体实体 = txn.getEntity(idOfEntity);inputStream[0] = entity.getBlob(blobKey);});返回输入流[0];}
这是否意味着 FileInputStream
不能与 RMI 一起工作?或者它应该可以工作,只是我的代码有问题?
解决方案
不可能通过 RMI 传输 InputStream
参见:通过 RMI 传输流的策略>
My app is throwing this error:
java.rmi.UnmarshalException: error unmarshalling return; nested exception is:
java.io.WriteAbortedException: writing aborted; java.io.NotSerializableException: java.io.FileInputStream
at java.rmi/sun.rmi.server.UnicastRef.invoke(UnicastRef.java:194)
at java.rmi/java.rmi.server.RemoteObjectInvocationHandler.invokeRemoteMethod(RemoteObjectInvocationHandler.java:209)
at java.rmi/java.rmi.server.RemoteObjectInvocationHandler.invoke(RemoteObjectInvocationHandler.java:161)
at com.sun.proxy.$Proxy40.getEntityBlob(Unknown Source)
at com.mycompany.backend.repository.EntityRepositoryImpl.getEntityBlob(EntityRepositoryImpl.java:260)
The "client" side of the RMI method is this:
Registry registry = LocateRegistry.getRegistry();
EntityRepository repository =
(EntityRepository) registry.lookup(EntityRepository.class.getName());
return repository.getEntityBlob(appId, namespace, entityType, entityId, blobKey);
And the "server" side is this
public InputStream getEntityBlob(
String appId,
String namespace,
String entityType,
final String entityId,
final String blobKey) throws RemoteException {
final InputStream[] inputStream = new InputStream[1];
manager.transactPersistentEntityStore(xodusRoot, appId, true, txn -> {
EntityId idOfEntity = txn.toEntityId(entityId);
final Entity entity = txn.getEntity(idOfEntity);
inputStream[0] = entity.getBlob(blobKey);
});
return inputStream[0];
}
Does it mean that FileInputStream
cannot work with RMI? Or it should work and there's just a problem with my code?
解决方案
It's not possible to transmit an InputStream
over RMI
See: Strategy to transmit a stream over RMI
这篇关于NotSerializableException: java.io.FileInputStream的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文