2

I was using java.util.zip.ZipFile to unzip large files with ColdFusion. However, I am now getting this error: "invalid CEN header (bad signature)".

I found a post that shows that this is related to zip 64 bit format and that I could use java.util.zip.ZipInputStream to handle it. However, I can't get past this error: "You have attempted to dereference a scalar variable of type class [B as a structure with members." which is caused by this line:

bos = createObject("java","java.io.BufferedOutputStream").init(fos,buffer.length);

Any help is greatly appreciated!

Here is my code

    fis = createObject("java","java.io.FileInputStream").init(zipFilePath);
    bis = createObject("java", "java.io.BufferedInputStream").init(fis);
    zis = createObject("java", "java.util.zip.ZipInputStream").init(bis);

    cnt=0;
    while(1==1){
        cnt++;
        entry = zis.getNextEntry();
        if (isNull(entry))
        {
            writeOutput("done"&now());
            break;
        }

        nm = entry.getName();

        lenPth = len(nm) - len(getFileFromPath(nm));

        if (lenPth) {
            pth = outputPath & left(nm, lenPth);
        } else {
            pth = outputPath;
        }

        if (NOT directoryExists(pth)) {
            fil = createObject("java", "java.io.File");
            fil.init(pth);
            fil.mkdirs();
        }

        byteClass = createObject("java", "java.lang.Byte").TYPE;
        buffer = createObject("java","java.lang.reflect.Array").newInstance(byteClass, 2048);

        fos = createObject("java","java.io.FileOutputStream").init(outputPath & nm);
        bos = createObject("java","java.io.BufferedOutputStream").init(fos,buffer.length);

            while(1==1) {
                size = zis.read(buffer, 0, buffer.length);
                if(size == -1)
                    break;
                bos.write(buffer, 0, size);
            }
            bos.flush();
            bos.close();



    }

    zis.close();
    fis.close();

sources:

Community
  • 1
  • 1
jessieloo
  • 1,759
  • 17
  • 24
  • an array's length in java is a special case which CF may not be handling properly. Have you tried using 2048 instead of buffer.length in your code? You can also drop the buffer size argument completely as BufferedOutputStream has a default size. That would at least tell you whether CF has a problem with the FileOutputStream or the length argument. – barnyr Feb 26 '13 at 17:14
  • 1
    I know this isn't what you're looking for, but in the past when faced with issues with CF unzipping files, we switched to using the CLI of 7zip with cfexecute and never went back. It'd save you a lot of work and code if it did work for you. To answer your question, you can use `ArrayLen( buffer )` instead of `buffer.length`. – Busches Feb 26 '13 at 17:37

1 Answers1

2

Passing in ArrayLen( Buffer ) instead of buffer.length will resolve the error.

bos = createObject("java","java.io.BufferedOutputStream").init(fos,arrayLen(buffer));

You can also use the getLength( array ) method of java.lang.reflect.Array but creating another instance of that seems like overkill compared to using arrayLen()

Busches
  • 1,964
  • 16
  • 19