我有以下Java脚本,但有时会遇到问题。我需要尝试将其编写为Pl Sql,然后我可以在应用程序中使用它。我可以到达base64_decode但我无法让UTL_COMPRESS.LZ_UNCOMPRESS工作。有什么想法,建议吗?
Bellow是我需要在Pl SQL中模拟的工作(ish)java代码
import java.util.*;
import java.util.zip.*;
import java.io.*;
import java.util.Arrays;
import org.apache.commons.codec.binary.Base64;
//import org.apache.bob;
public class decompress {
public static void main(String[] args) {
//String zpl = "rVrbbhw5kn33V+hlgV1sWg7mjVk9wADMqmRnVkmyWlK37cGiAE2PVnb3WDbc02uMH/phsT8x
这是一个非常长的字符串,作为数据库中的clob。 6kwF4z6vyGzQYdMKVlUUj1lsWrJJlABbPLdfYvz7xzZVbzZv / 7DPwE =“;
try{
String zpl = args[0];
if (zpl.length()<2) {
System.out.println("ERROR");
} else {
//System.out.println(zpl);
//byte[] res = decompress(zpl.getBytes("UTF-8"));
Base64 b64 = new Base64();
byte[] res=Base64.decodeBase64(zpl);
//System.out.println(new String(res, "UTF-8"));
byte[] decom=decompress(res);
System.out.println(new String(decom,"UTF-8"));
}
//System.out.println("THIS " + res.toString());
} catch (Exception e) {
//System.out.println(e.getMessage());
//e.printStackTrace();
System.out.println("ERROR");
}
}
public static byte[] decompress(byte[] data) throws IOException, DataFormatException {
Inflater inflater = new Inflater(true);
inflater.setInput(data);
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
byte[] buffer = new byte[1024];
while (!inflater.finished()) {
int count = inflater.inflate(buffer);
outputStream.write(buffer, 0, count);
}
outputStream.close();
byte[] output = outputStream.toByteArray();
inflater.end();
return output;
}
}
SQL函数尝试在尝试解压缩时将哪个接缝做到64位但是分开。
CREATE OR REPLACE
FUNCTION decode_base64_x(
p_clob_in IN CLOB)
RETURN BLOB
IS
v_blob BLOB ;
v_result BLOB ;
v_offset INTEGER;
v_buffer_size binary_integer := 48;
v_buffer_varchar VARCHAR2(48);
v_buffer_raw raw(48);
l_uncompressed_blob BLOB ;
l_in_blob BLOB;
BEGIN
IF p_clob_in IS NULL THEN
RETURN NULL;
END IF;
dbms_lob.createtemporary(v_blob, true);
v_offset := 1;
FOR i IN 1 .. ceil(dbms_lob.getlength(p_clob_in) / v_buffer_size)
LOOP
dbms_lob.read(p_clob_in, v_buffer_size, v_offset, v_buffer_varchar);
v_buffer_raw := utl_raw.cast_to_raw(v_buffer_varchar);
v_buffer_raw := utl_encode.base64_decode(v_buffer_raw);
dbms_lob.writeappend(v_blob, utl_raw.length(v_buffer_raw), v_buffer_raw);
v_offset := v_offset + v_buffer_size;
END LOOP;
v_result := v_blob;
--
--
-- l_in_blob := (UTL_RAW.CAST_TO_RAW (v_blob) );
--
UTL_COMPRESS.LZ_UNCOMPRESS( src => v_blob, dst => l_uncompressed_blob);
--
dbms_lob.freetemporary(v_blob);
-- l_uncompressed_blob := UTL_COMPRESS.LZ_UNCOMPRESS( src => v_blob ) ;
-- UTL_COMPRESS.lz_uncompress (src => v_blob , dst => l_uncompressed_blob);
-- RETURN l_uncompressed_blob;
RETURN v_result;
END decode_base64_x;
我认为它只是UTL_COMPRESS.LZ_UNCOMPRESS位我错了!