Question

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:

Was it helpful?

Solution

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()

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top