F
Flavio Castelli
I, I'm trying to load an object serialized to a file using an
ObjectOutputStream.
My code looks like this one:
1. FileInputStream fis = new FileInputStream(pwdFileName);
2. ObjectInputStream keyFile = new ObjectInputStream(fis);
3. SecretKey deskey = (SecretKey) keyFile.readObject();
4. keyFile.close();
I get a StreamCorruptedException at line 3.
Debugging I discovered that FileInputStream::available() return 258 bytes,
while FileInputStream::available() returns 0.
This is the exception's stacktrace:
java.io.StreamCorruptedException
at java.ibjectInputStream.readObject0(ObjectInputStream.java:1301)
at java.ibjectInputStream.defaultReadFields(ObjectInputStream.java:1845)
at java.ibjectInputStream.readSerialData(ObjectInputStream.java:1769)
at
java.ibjectInputStream.readOrdinaryObject(ObjectInputStream.java:1646)
at java.ibjectInputStream.readObject0(ObjectInputStream.java:1274)
at java.ibjectInputStream.readObject(ObjectInputStream.java:324)
at it.reply.encryption.DesDecrypter.decrypt(DesDecrypter.java:116)
at it.foo.bar.dao.DSFactory.loadCryptedDataSourceUser(DSFactory.java:26)
at it.foo.bar.ContextListener.contextInitialized(ContextListener.java:78)
at
org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3763)
at
org.apache.catalina.core.StandardContext.start(StandardContext.java:4211)
at
org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:759)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:739)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:524)
at
org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:904)
at
org.apache.catalina.startup.HostConfig.deployDirectories(HostConfig.java:867)
at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:474)
at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1122)
at
org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:310)
at
org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1021)
at org.apache.catalina.core.StandardHost.start(StandardHost.java:718)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1013)
at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:442)
at org.apache.catalina.core.StandardService.start(StandardService.java:450)
at org.apache.catalina.core.StandardServer.start(StandardServer.java:709)
at org.apache.catalina.startup.Catalina.start(Catalina.java:551)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:294)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:432)
This code is called from the method contextInitialized of a class
implementing ServletContextListener.
If I use the code into a java command-line program everything works fine.
Any hint?
Thanks in advance
Flavio
ObjectOutputStream.
My code looks like this one:
1. FileInputStream fis = new FileInputStream(pwdFileName);
2. ObjectInputStream keyFile = new ObjectInputStream(fis);
3. SecretKey deskey = (SecretKey) keyFile.readObject();
4. keyFile.close();
I get a StreamCorruptedException at line 3.
Debugging I discovered that FileInputStream::available() return 258 bytes,
while FileInputStream::available() returns 0.
This is the exception's stacktrace:
java.io.StreamCorruptedException
at java.ibjectInputStream.readObject0(ObjectInputStream.java:1301)
at java.ibjectInputStream.defaultReadFields(ObjectInputStream.java:1845)
at java.ibjectInputStream.readSerialData(ObjectInputStream.java:1769)
at
java.ibjectInputStream.readOrdinaryObject(ObjectInputStream.java:1646)
at java.ibjectInputStream.readObject0(ObjectInputStream.java:1274)
at java.ibjectInputStream.readObject(ObjectInputStream.java:324)
at it.reply.encryption.DesDecrypter.decrypt(DesDecrypter.java:116)
at it.foo.bar.dao.DSFactory.loadCryptedDataSourceUser(DSFactory.java:26)
at it.foo.bar.ContextListener.contextInitialized(ContextListener.java:78)
at
org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3763)
at
org.apache.catalina.core.StandardContext.start(StandardContext.java:4211)
at
org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:759)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:739)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:524)
at
org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:904)
at
org.apache.catalina.startup.HostConfig.deployDirectories(HostConfig.java:867)
at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:474)
at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1122)
at
org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:310)
at
org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1021)
at org.apache.catalina.core.StandardHost.start(StandardHost.java:718)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1013)
at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:442)
at org.apache.catalina.core.StandardService.start(StandardService.java:450)
at org.apache.catalina.core.StandardServer.start(StandardServer.java:709)
at org.apache.catalina.startup.Catalina.start(Catalina.java:551)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:294)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:432)
This code is called from the method contextInitialized of a class
implementing ServletContextListener.
If I use the code into a java command-line program everything works fine.
Any hint?
Thanks in advance
Flavio