NotSerializableException: java.io.FileInputStream

huangapple go评论74阅读模式
英文:

NotSerializableException: java.io.FileInputStream

问题

我的应用程序抛出以下错误:

java.rmi.UnmarshalException: 解组返回值时出错; 嵌套异常为:
    	java.io.WriteAbortedException: 写入中止; 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 一起使用?或者它应该可以工作,只是我的代码有问题?

英文:

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?

答案1

得分: 0

不可能通过RMI传输InputStream

详情请见:https://stackoverflow.com/questions/64147697/strategy-to-transmit-a-stream-over-rmi

英文:

It's not possible to transmit an InputStream over RMI

See: https://stackoverflow.com/questions/64147697/strategy-to-transmit-a-stream-over-rmi

huangapple
  • 本文由 发表于 2020年10月1日 08:38:59
  • 转载请务必保留本文链接:https://go.coder-hub.com/64147608.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定