barndog
barndog

Reputation: 7173

Unzip saz files java

I was looking through java documentation and there doesn't seem to be a way to specifically unzip saz files, which are session archives created by the network proxy Fiddler. Anyone have any idea of how to do it?

Upvotes: 0

Views: 2351

Answers (3)

jsshah
jsshah

Reputation: 1741

This should do the trick

saz files are regular zip files

public static boolean unzipFiles(String srcDirectory, String srcFile, String destDirectory)
{
    try
    {
        //first make sure that all the arguments are valid and not null
        if(srcDirectory == null)
        {
            System.out.println(1);
            return false;
        }
        if(srcFile == null)
        {
            System.out.println(2);
            return false;
        }
        if(destDirectory == null)
        {
            System.out.println(3);
            return false;
        }
        if(srcDirectory.equals(""))
        {
            System.out.println(4);
            return false;
        }
        if(srcFile.equals(""))
        {   
            System.out.println(5);
            return false;
        }
        if(destDirectory.equals(""))
        {
            System.out.println(6);
            return false;
        }
        //now make sure that these directories exist
        File sourceDirectory = new File(srcDirectory);
        File sourceFile = new File(srcDirectory + File.separator + srcFile);
        File destinationDirectory = new File(destDirectory);

        if(!sourceDirectory.exists())
        {
            System.out.println(7);
            return false;
        }
        if(!sourceFile.exists())
        {
            System.out.println(sourceFile);
            return false;
        }
        if(!destinationDirectory.exists())
        {
            System.out.println(9);
            return false;
        }

        //now start with unzip process
        BufferedOutputStream dest = null;

        FileInputStream fis = new FileInputStream(sourceFile);
        ZipInputStream zis = new ZipInputStream(new BufferedInputStream(fis));

        ZipEntry entry = null;

        while((entry = zis.getNextEntry()) != null)
        {
            String outputFilename = destDirectory + File.separator + entry.getName();

            System.out.println("Extracting file: " + entry.getName());

            createDirIfNeeded(destDirectory, entry);

            int count;

            byte data[] = new byte[BUFFER_SIZE];

            //write the file to the disk
            FileOutputStream fos = new FileOutputStream(outputFilename);
            dest = new BufferedOutputStream(fos, BUFFER_SIZE);

            while((count = zis.read(data, 0, BUFFER_SIZE)) != -1)
            {
                dest.write(data, 0, count);
            }

            //close the output streams
            dest.flush();
            dest.close();
        }

        //we are done with all the files
        //close the zip file
        zis.close();

    }
    catch(Exception e)
    {
        e.printStackTrace();
        return false;
    }

    return true;
}

Upvotes: 1

JB Nizet
JB Nizet

Reputation: 692023

This page, found by googling "saz files", says:

SAZ files are simply specially formatted .ZIP files. If you rename a .SAZ file to .ZIP, you can open it for viewing using standard ZIP viewing tools

So they're just zip files with a different extension. Unzip them exactly like you would unzip a zip file.

Upvotes: 0

Mikko Maunu
Mikko Maunu

Reputation: 42114

According this it is regular ZIP with specific extension for file name. Use java.util.zip.ZipFile.

About not having specific method for this extension - I think it kind of makes sense to not to have specific method for every possible extension.

Upvotes: 2

Related Questions