java blob压缩_如何从Oracle中用Java压缩的BLOB列中提取XML文档

我在Oracle 11G(11.1)中有一个表,它有一个包含XML文档的BLOB列。

XML文档已使用Java程序写入表中,并已使用java.util.zip平减器进行序列化和压缩。

有没有简单的方法使用SQL或PLSQL来提取此文档以反转创建BLOB列以取回原始XML文档的过程?

我从Web应用程序中识别出一段Java,它读取类似于下面代码的列,但出于支持目的,希望能够从后端访问列数据。

private IntegrationStagingDataBean fromObjectToBean(StagedMessage message) throws ServerException {

IntegrationStagingDataBean bean = new IntegrationStagingDataBean();

bean.setBusinessId(message.getBusinessId());

bean.setBusinessType(message.getBusinessType());

bean.setCreateTime(message.getCreateTime());

bean.setDeleted(message.hasBeenDeleted() ? "Y" : "N");

bean.setErrorMessage(message.getErrorMessage());

bean.setId(message.getId());

bean.setStoreId(message.getStoreId());

bean.setMessageDirection(message.getMessageDirection().getDbCode());

bean.setMessageFamily(message.getMessageFamily().getDbCode());

bean.setMessageType(message.getMessageType().getDbCode());

bean.setProcessed(message.hasBeenProcessed() ? "Y" : "N");

bean.setRetryCount(message.getRetryCount());

bean.setUpdateTime(message.getUpdateTime());

try {

bean.setSerializedDeo(ObjectUtils.toByteArray(new CompressedObject(message.getDeo())));

} catch (IOException ioex) {

throw new ServerException("Problem setting compressed serialized object", ioex);

}

return bean;

}

private StagedMessage fromBeanToObject(IntegrationStagingDataBean bean) throws ServerException {

DataExchangeObject deo = null;

Blob blob = (Blob) bean.getSerializedDeo();

try {

CompressedObject compressedObject = (CompressedObject) new

ObjectInputStream(blob.getBinaryStream()).readObject();

deo = (DataExchangeObject) compressedObject.recoverObject();

} catch (Exception e) {

throw new ServerException("Couldn't uncompress/deserialize DEO from BLOB", e);

}++++++++++++++++++++++++++++++++++++++++++++++++++ ++++++++++

并发现以下附加功能遍布于少数几个软件包中,这些软件包指示它使用java.util.zip。*中的java函数deflater;

公共CompressedObject(Object对象)

抛出IOException

{

dataToSend = null;

如果(object!= null)

dataToSend = ObjectUtils.toCompressedByteArray(object);

}

public static final byte[] toCompressedByteArray(Object o)

throws IOException

{

return compressByteArray(toByteArray(o));

}

public static final byte[] compressByteArray(byte input[])

{

Deflater compressor = new Deflater(9);

compressor.setInput(input);

compressor.finish();

ByteArrayOutputStream bos = new ByteArrayOutputStream(input.length);

byte buf[] = new byte[1024];

int count;

for(; !compressor.finished(); bos.write(buf, 0, count))

count = compressor.deflate(buf);

try

{

bos.close();

}

catch(IOException e) { }

return bos.toByteArray();

}

public static final byte[] decompressByteArray(byte arr[])

{

Inflater decompressor = new Inflater();

decompressor.setInput(arr);

ByteArrayOutputStream bos = new ByteArrayOutputStream(arr.length);

byte buf[] = new byte[1024];

while(!decompressor.finished())

try

{

int count = decompressor.inflate(buf);

bos.write(buf, 0, count);

}

catch(DataFormatException e) { }

try

{

bos.close();

}

catch(IOException e) { }

return bos.toByteArray();

}提前致谢。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值