gpt4 book ai didi

java - 从数据库读取 zip 存档

转载 作者:行者123 更新时间:2023-12-02 07:36:33 25 4
gpt4 key购买 nike

我有一个 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) {
}
}

}

有人可以帮我吗

提前致谢。

最佳答案

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

可能的罪魁祸首是:

  • 末尾缺少字节
  • 转换后的字节
  • 字节顺序困惑

我希望查看前 10 个、后 10 个字节和总字节数应该足以让您清楚地了解发生了什么。

关于java - 从数据库读取 zip 存档,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12155681/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com