免责声明:Peoplesoft 知识并不是帮助我完成此任务的必备知识!
我如何从 Peoplesoft 表的 PUBDATALONG 列中提取数据? 该表的描述在这里: http://www.go-faster.co.uk/peopletools/psiblogdata.htm
目前我正在使用用Java编写的程序,下面是一段代码:
Inflater inflater = new Inflater();
byte[] result = new byte[rs.getInt("UNCOMPDATALEN")];
inflater.setInput(rs.getBytes("PUBDATALONG"));
int length = inflater.inflate(result);
System.out.println(new String(result, 0, length, "UTF-8"));
System.out.println();
System.out.println("-----");
System.out.println();
我如何使用 Python 重写它? 这个问题在 Stackoverflow 上以其他形式出现过,但没有真正的答案。 我对 Java 代码的作用有基本的了解,但我不知道 Python 中有任何库可以用来实现同样的事情。
有些人建议尝试 zlib,因为它与 Java Inflater 类使用的算法兼容,但我没有成功做到这一点。 考虑 PeopleSoft 手册中的以下事实:
When the message is received by the PeopleSoft database, the XML data is converted to UTF-8 to prevent any UCS2 byte order issues. It is also compressed using the deflate algorithm prior to storage in the database.
我尝试过这样的事情:
import zlib
import base64
UNCOMPDATALEN = 362 #this value is taken from the DB and is the dimension of the data after decompression.
PUBDATALONG = '789CB3B1AFC8CD51284B2D2ACECCCFB35532D43350B2B7E3E5B2F130F40C8977770D8977F4710D0A890F0E710C090D8EF70F0D09080DB183C8BAF938BAC707FBBBFB783ADA19DAE86388D904B90687FAC0F4DAD940CD70F67771B533B0D147E6DAE8A3A9D5C76B3F00E2F4355C=='
print zlib.decompress(base64.b64decode(PUBDATALONG), 0, 362)
我明白了:
zlib.error: Error -3 while decompressing data: incorrect header check
我确实做错了什么,但我不够聪明,无法自己找出答案。
最佳答案
该字符串不是 Base-64 编码的。它只是十六进制。 (我不知道为什么它以 ==
结尾,这使得它看起来有点像 Base-64 字符串。)您应该能够通过检查看到没有小写字母,或者就此而言,F
后的大写字母与典型的 Base-64 编码压缩字符串(即随机出现的数据)一样。
删除末尾的等号并在 Python 2 中使用 .decode("hex")
或在 Python 3 中使用 bytes.fromhex()
。
关于java - 如何在Python中膨胀一些由Peoplesoft(Java)缩小的数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42945983/