GithubHelp home page GithubHelp logo

protectedzipcreator's Introduction

ProtectedZipCreator

Create password protected Zip files, using java stored procedures. The example of the compressing blob file into zip file is described bellow

   p_ProtectedZipCreator.Archive(ab_Input => lb_file, 
                                 ab_Output => lb_Result, 
                                 av_zipPass => 'some_password',
                                 av_FileName => 'some_file.txt', 
                                 ac_OutErrBuf => lc_Err);

where, ab_Input - the source file for compressing, ab_Output - the compressed zip file, av_ZipPass - the password for the zip file, av_FileName - the filename inside the zip archive, ac_OutErrBuf - clob file containing the log of the java errors.

Install

For installing firstly you will need loadjava utility. The loadjava utility loads Java source and class files into the database. When class files are created in a conventional manner, outside the database, loadjava is used to get them into the database. For the ProtectedZipCreator we need to install zip4j external library. Change the directory of the terminal to {project_root}/external-libraries/zip4j-1.3.2.jar directory and execute the following script in order to load java into Oracle database.

loadjava -user db_user/db_user_pass@db_name -resolve -v zip4j-1.3.2.jar

After loading java library to the Database, compile the {project_root}/java-sources and {project_root}/packages sources into the Database.

Example

You will need to have SOME_DIRECTORY directory and inside of the directory file called some_file.txt. After executing the bellow script, in the SOME_DIRECTORY directory will be created a compressed file some_file.zip.

declare
   lb_file blob;
   lb_Result blob;
   lc_Err clob;

   procedure LoadBlobFromFile(av_Directory varchar2, av_FileName varchar2) is
      lb_xml bfile := bFilename(av_Directory, av_FileName);
      li_dest int := 1;
      li_src int := 1;
      warning int;
      ltx int := 0;
   begin
      dbms_lob.fileopen(lb_xml, dbms_lob.lob_readonly);
      dbms_lob.loadblobfromfile(lb_file, lb_xml, dbms_lob.getlength(lb_xml),
                                li_dest, li_src);
      dbms_lob.fileclose(lb_xml);
   end;

   procedure save_file(av_Directory varchar2, av_FileName varchar2, lb_Src blob) is
      l_file UTL_FILE.FILE_TYPE;
      l_buffer raw(32767);
      l_amount binary_integer := 32767;
      l_pos integer := 1;
      l_blob_len integer;
   begin
   
      l_blob_len := DBMS_LOB.getlength(lb_Src);
   
      -- Open the destination file.
      l_file := UTL_FILE.fopen(av_Directory, av_FileName, 'w', 32767);
   
      -- Read chunks of the BLOB and write them to the file
      -- until complete.
      while l_pos < l_blob_len loop
         DBMS_LOB.read(lb_Src, l_amount, l_pos, l_buffer);
         UTL_FILE.put_raw(l_file, l_buffer, true);
         l_pos := l_pos + l_amount;
      end loop;
   
      -- Close the file.
      UTL_FILE.fclose(l_file);
   
   exception
      when others then
         -- Close the file if something goes wrong.
         if UTL_FILE.is_open(l_file) then
            UTL_FILE.fclose(l_file);
         end if;
         raise;
   end;

begin
   dbms_lob.createtemporary(lb_file, true, dbms_lob.call);
   dbms_lob.createtemporary(lb_Result, true, dbms_lob.call);
   dbms_lob.createtemporary(lc_Err, true, dbms_lob.call);
   LoadBlobFromFile('SOME_DIRECTORY', 'some_file.txt');

   p_ProtectedZipCreator.Archive(ab_Input => lb_file, ab_Output => lb_Result,
                                 av_zipPass => '123',
                                 av_FileName => 'some_file.txt',
                                 ac_OutErrBuf => lc_Err);

   save_file('SOME_DIRECTORY', 'some_file.zip', lb_Result);
end;

Compatibility

Tested on Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production.

protectedzipcreator's People

Contributors

arammkrtchyan avatar jonheller1 avatar mikron avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

protectedzipcreator's Issues

Add more files into ZIP file

Hi,
is it possible to add some procedure to add more that one file to te zip file ?
(some array for ArrayList)
regards

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.