NotSerializableException:java.io.FileInputStream
NotSerializableException: java.io.FileInputStream
我的应用程序抛出此错误:
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)
RMI 方法的“客户端”是这样的:
Registry registry = LocateRegistry.getRegistry();
EntityRepository repository =
(EntityRepository) registry.lookup(EntityRepository.class.getName());
return repository.getEntityBlob(appId, namespace, entityType, entityId, blobKey);
“服务器”端是这样的
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];
}
这是否意味着 FileInputStream
不能与 RMI 一起工作?或者它应该可以工作,只是我的代码有问题?
无法通过 RMI
传输 InputStream
参见:Strategy to transmit a stream over RMI
我的应用程序抛出此错误:
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)
RMI 方法的“客户端”是这样的:
Registry registry = LocateRegistry.getRegistry();
EntityRepository repository =
(EntityRepository) registry.lookup(EntityRepository.class.getName());
return repository.getEntityBlob(appId, namespace, entityType, entityId, blobKey);
“服务器”端是这样的
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];
}
这是否意味着 FileInputStream
不能与 RMI 一起工作?或者它应该可以工作,只是我的代码有问题?
无法通过 RMI
传输InputStream
参见:Strategy to transmit a stream over RMI