Professional Web Applications Themes

java.util.zip.ZipOutputStream - Coldfusion - Advanced Techniques

I'd like to create an object, which would save a created zipfile into a variable instead of file. OutputStream = createObject("java","java.io.FileOutputStream").in it("c:\a.zip"); ZipStream = createObject("java","java.util.zip.ZipOutputStream ").init(OutputStream); This code works just perfect, but it creates a file (c:\a.zip) this is unwanted, I'd like to put this filecontents into a string variable. I'm newbie in Java, so after hours of trying everything from the java.io class, I decided to ask for help here. Thank you in advance....

  1. #1

    Default java.util.zip.ZipOutputStream

    I'd like to create an object, which would save a created zipfile into a
    variable instead of file.

    OutputStream =
    createObject("java","java.io.FileOutputStream").in it("c:\a.zip");
    ZipStream =
    createObject("java","java.util.zip.ZipOutputStream ").init(OutputStream);

    This code works just perfect, but it creates a file (c:\a.zip) this is
    unwanted, I'd like to put this filecontents into a string variable.
    I'm newbie in Java, so after hours of trying everything from the java.io
    class, I decided to ask for help here.

    Thank you in advance.

    cicovec-at-hotmail Guest

  2. #2

    Default Re: java.util.zip.ZipOutputStream

    need to see ur init() function in line 1 to figure out how you are using the argument passed in the method.
    adonis1976 Guest

  3. #3

    Default Re: java.util.zip.ZipOutputStream

    Ok, I finally figured how to make a zipOutputStream become the type I needed,
    It was ByteArray object (solution is in the code), but now I stand in front of
    another problem - How to send the zip output to the client on ColdFusion MX 6.1

    <cfheader name="Content-Disposition" value="attachment;
    filename=#filename#.zip">
    <cfcontent type="application/unknown" reset="yes"
    variable="#filecontents#"><cfabort>

    This code only works in MX 7, is there a way to send binary data to client in
    ColdFusion MX6.1?

    <cfscript>
    function createZipFile(variable) {
    jStringWriter = createObject("java","java.io.StringWriter").init() ;
    jByteArrayOutputStream =
    createObject("java","java.io.ByteArrayOutputStream ").init();
    jZipStream =
    createObject("java","java.util.zip.ZipOutputStream ").init(jByteArrayOutputStream
    );
    jZipStream.setLevel(0);
    streams.jZipStream = jZipStream;
    streams.jByteArrayOutputStream = jByteArrayOutputStream;
    return streams;
    }

    function addZipEntry(streams, entryname, contents) {
    var jZipEntry =
    createObject("java","java.util.zip.ZipEntry").init (entryname);
    var buffer = repeatString(" ", 1024).getBytes();
    var Data = "";
    var jInputStream =
    createObject("java","java.io.StringReader").init(c ontents);
    var jZipStream = streams.jZipStream;
    jZipStream.putNextEntry(jZipEntry);

    Data = jInputStream.read();
    if (Data neq -1) {
    do {
    jZipStream.write(Data);
    Data = jInputStream.read();
    } while(Data neq -1);
    }
    jZipStream.closeEntry();
    }

    function CloseZipStream(streams) {
    var ret = "";
    streams.jZipStream.close();
    ret = streams.jByteArrayOutputStream.toByteArray();
    streams.jByteArrayOutputStream.close();
    return ret;
    }
    </cfscript>

    cicovec-at-hotmail Guest

Similar Threads

  1. SNMP::Util
    By Marcel van Leeuwen in forum PERL Modules
    Replies: 4
    Last Post: April 10th, 05:57 PM
  2. java.util.Arrays$ArrayList exception causing JRun error
    By skozey in forum Coldfusion Server Administration
    Replies: 3
    Last Post: December 17th, 10:25 AM
  3. How to cast cfquery object to type java.util.Map
    By _jt in forum Coldfusion - Advanced Techniques
    Replies: 3
    Last Post: May 27th, 09:22 AM
  4. List::Util / arrays
    By Jeff 'Japhy' Pinyan in forum PERL Beginners
    Replies: 0
    Last Post: August 6th, 02:57 AM
  5. programatic CPU util
    By Rick Jones in forum AIX
    Replies: 1
    Last Post: July 8th, 12:48 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139