1

hi When am trying to read blob getting the exception . am posting how am writing into DB and geting to db kindly suggest , its causing too much problem..

ava.io.StreamCorruptedException: invalid stream header: 4920616D
                at java.io.ObjectInputStream.readStreamHeader(ObjectInputStream.java:782)
                at java.io.ObjectInputStream.<init>(ObjectInputStream.java:279)
                at com.jiit.jfx.persistence.TypeHelper.readBlob(TypeHelper.java:137)
                at com.jiit.jfx.persistence.TypeHelper.get(TypeHelper.java:84)
                at com.jiit.jfx.persistence.dataaccess.OracleSQLQuery.get(OracleSQLQuery.java:116)
                at com.jiit.jfx.persistence.dataaccess.OracleSQLQuery.doOperation(OracleSQLQuery.java:65)
                at com.jiit.jfx.persistence.dataaccess.AbstractDAO.execute(AbstractDAO.java:181)
                at com.jiit.jfx.persistence.dataaccess.AbstractDAO.executeSQL(AbstractDAO.java:208)
                at 

com.jiit.ngcs.mx.server.model.rail.ASMMessageStore.getASMMessageStore(ASMMessageStore.java:196)




    enter code here

    Reading BOLB :

        public static Blob createBlob(Object serializable) throws PersistenceException{
            try {
                ByteArrayOutputStream bStream = new ByteArrayOutputStream();
                ObjectOutputStream oStream = new ObjectOutputStream(bStream);
                oStream.writeObject(serializable);
                oStream.flush();
                oStream.close();
                return createBlob(bStream.toByteArray());
            } catch (Exception e) {
                throw new PersistenceException(e.getMessage());
            }
        }
        in TypeHelper.java -- > createBlob


        private static Object readBlob(int index, ResultSet rs) throws SQLException {
            try {
                InputStream is = rs.getBinaryStream(index);
                if(is != null) {
                    ObjectInputStream os = new ObjectInputStream(is);
                    return os.readObject();
                }
                return null;
            } catch (IOException e) {
                e.printStackTrace();
                throw new SQLException(e.getMessage());
            } catch (ClassNotFoundException e) {
                e.printStackTrace();
                throw new SQLException(e.getMessage());
            }

Tried all cases given in stackoverflow and other blogs . still not understand exact issues.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Chandu
  • 11
  • 1
  • 2

1 Answers1

5

Lets start with 4920616D. If you decode that as ASCII characters, you get "I am" ... English text. Now that could be a coincidence, but lets assume that it isn't.

What could cause text to appear where you were expecting a serialized object?

Well, one possibility is that you have gotten the resultset index values wrong. If index 1 in the resultset corresponded to a value from a CHAR or VARCHAR or similar field, then your JDBC driver could return a "binary stream" consisting of a bunch of encoded text. You could see those characters for a number of character encoding schemes that the database could be using for storing text, including ASCII, LATIN-1 and UTF-8.

Stephen C
  • 698,415
  • 94
  • 811
  • 1,216
  • Thanks for responding , i understood the situation what result set fetching and the stream which is invalid . but the same is working for if i fetch for 10 records at a time , if am fetching 50 records only having an issue. for this any solution there. pls clear me what other ways to sort it out.. thanks . Chandu – Chandu Dec 27 '15 at 10:06
  • 1
    I / we can't provide you any more help unless you supply us with an MCVE (http://stackoverflow.com/help/mcve) that allow use to see for ourselves what is happening. – Stephen C Dec 27 '15 at 11:55
  • sure Stephen , will try to supply with an MCVE.. :-) – Chandu Dec 28 '15 at 04:39
  • If you write an MVCE, there is a chance that someone will be able to help you. I'm not promising that I will. – Stephen C Dec 28 '15 at 23:05