0

我有一个 zip 文件,我将它作为 blob 字段存储在数据库中。当我想从中下载它时,zip 文件已损坏。我只能从 7zip 打开它。当我尝试在将文件上传到数据库之前打开它以及何时在数据库中时,该文件是好的。当我从数据库中以 blob 形式检索文件时,尝试在 unix 上解压缩时出现此错误

    Archive:  test.zip
      End-of-central-directory signature not found.  Either this file is not
      a zipfile, or it constitutes one disk of a multi-part archive.  In the
      latter case the central directory and zipfile comment will be found on
      the last disk(s) of this archive.
    unzip:  cannot find zipfile directory in one of test.zip or
            test.zip.zip, and cannot find test.zip.ZIP, period.

这是我从数据库中检索 zip 时的代码:

        public oracle.sql.BLOB GetBlob(Connection myConn, 
                                       CallableStatement cstmt) throws Exception {
            String strSql = null;

            BLOB tempBlob = null;
            try {

                strSql = .... // Here is the sql procedure which I called to retrieve the blobl field.
                cstmt = myConn.prepareCall(strSql);
                cstmt.registerOutParameter(1, OracleTypes.BLOB);
                cstmt.setLong(2, request_id);
                cstmt.execute();
                tempBlob = (oracle.sql.BLOB)cstmt.getObject(1);
                int bufsize = tempBlob.getBufferSize();

            } catch (Exception e) {
                e.printStackTrace();
                throw e;
            }
            return tempBlob;

这是阅读:

                oracle.sql.BLOB tempBlob = null;
            Connection myConn = null;
            CallableStatement cstmt = null;

            try {
                myConn = DBHelper.getConnection();
                if (null == myConn)
                    throw new SQLException();
                tempBlob = GetBlob(myConn, cstmt);

                int bufsize = tempBlob.getBufferSize();
                InputStream in = tempBlob.getBinaryStream();
                int length = 0;

                byte buf[] = new byte[bufsize];
                while ((in != null) && ((length = in.read(buf)) != -1)) {
                    out.write(buf, 0, length);

                }
                in.close();
                //          out.flush();
                //          out.close();
            } catch (Exception e) {
                e.printStackTrace();
            } finally {
                if (null != myConn) {
                    try {
                        myConn.close();
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
                if (cstmt != null) {
                    try {
                        cstmt.close();
                    } catch (SQLException e) {
                    }
                }

            }

有人可以帮助我。

提前致谢。

4

1 回答 1

2

比较之前和之后的文件。差异应该会给您一些提示,说明出了什么问题。

可能的罪魁祸首是:

  • 最后缺少字节
  • 转换后的字节
  • 字节顺序混乱

I'd expect looking at the first 10, the last 10 and the total number of bytes should be sufficient to give you a good idea what is going on.

于 2012-08-28T09:07:27.897 回答