读取作为对象存储在 jar 中的文件内的 java.security.key
我使用 ObjectOutputStream 将 PublicKey 实例保存在文件中。然后,该文件存储在 jar 文件中,然后由 JBoss 加载。我正在尝试读取此文件,但它向我抛出一个异常,告诉我它不可序列化。 这是代码:
InputStream input = KeyLoader.class.getClassLoader().getResourceAsStream(resource); ObjectInputStream objectInputStream = new ObjectInputStream(输入); 对象 obj = objectInputStream.readObject(); 键输出 = (Key) obj; objectInputStream.close(); 返回输出;
这引发了我这个异常 发生异常:java.io.NotSerializedException
I saved a PublicKey instance in a file using ObjectOutputStream. This file is then stored inside a jar file which is then loaded by JBoss. I'm trying to read this file but it throws me an exception telling that it's not serializable.
Here is the code :
InputStream input = KeyLoader.class.getClassLoader().getResourceAsStream(resource);
ObjectInputStream objectInputStream = new ObjectInputStream(input);
Object obj = objectInputStream.readObject();
Key output = (Key) obj;
objectInputStream.close();
return output;
which throws me this exception
An exception occurred: java.io.NotSerializableException
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不确定 jar 文件中的序列化/反序列化,但是
在无法看到其余代码的情况下,我可以说几件事:
编辑:
我不太熟悉 JBoss,但也许尝试使用 JBossObjectInputStream 和 JBossObjectOutputStream (org.jboss.serial.io)。您还必须将 jboss-serialization.jar 添加到您的类路径中。 另请参阅链接
,我以前从未做过此类事情,但如果您认为jar文件使事情变得复杂,但是您应该能够使用 java.util.jar 包中的一些类来简化 jar 文件的 IO 操作。
我希望这能在某种程度上有所帮助。
I'm not sure about serialization/deserialization from within a jar file, but
without being able to see the rest of your code, I can say a few things:
key.getEcnoded()
, which would allow you to do input/output using the bytes of the key.Edit:
I'm not really familiar with JBoss, but maybe try using JBossObjectInputStream and JBossObjectOutputStream (org.jboss.serial.io). You will also have to add jboss-serialization.jar to your classpath. see link
also, I've never done this sort of thing before, but if you think the jar file is complicating things, but you should be able to use some of the classes in the
java.util.jar
package to simplify IO operations with jar files.I hope this helps in some way.