Gzip to compress zip files

hi everyone..i am making a backup utility. it will compress, encrypt and split the files and send it to an ftp server. i have everything worked out except for one bug...when i compress already compressed data, it gets corrupted...like installers, or zip and rar files..i cannot retrieve the files after compressing them with the program. here is the code for compressing and decompressing, can anyone help me?
private string CompressFile(string filetocompress)
               try
                    FileInputStream fis = new FileInputStream(filetocompress);          
                    FileOutputStream fos = new FileOutputStream(filetocompress + "test123");          
                    GZIPOutputStream gzos = new GZIPOutputStream(fos);          
                    sbyte[] buffer = new sbyte[2048];          
                    int read = fis.read(buffer);          
                    while (read == 2048)          
                         gzos.write(buffer);               
                         read = fis.read(buffer);          
                    gzos.write(buffer, 0, read);          
                    // The next step is VERY important. If you do not flush the buffer          
                    // on the inner (gzip) stream, the outer (file) stream will get          
                    // closed before it gets the last buffer of data.          
                    gzos.close();          
                    fis.close();          
                    fos.close();
                    return filetocompress + "test123";
               catch (Exception e)
               return filetocompress + "test123";
private string DecompressFile(string filetocompress)
               try
                    GZIPInputStream gin = new GZIPInputStream(new FileInputStream(filetocompress));
                    OutputStream fout = new FileOutputStream(filetocompress + "test1234");
                    // Transfer bytes from the compressed file to the output file
                    sbyte[] buf = new sbyte[1024*1024];
                    int len;
                    while ((len = gin.read(buf)) > 0)
                         fout.write(buf, 0, len);
                         fout.flush();
                    // Close the file and stream
                    gin.close();
                    fout.close();
                    return filetocompress + "test1234";
               catch (Exception e)
               return filetocompress + "test1234";

sbyte[] buffer = new sbyte[2048];
Where has sbyte come from? ASAIK java has no signed byte.
When you post code, please use [code] and [/code] tags as described in Formatting Help on the message entry page. It makes it much easier to read.

Similar Messages

  • What application do I use to open compressed zip files?

    Hi!
    I am wondering what application I use to open a compressed zip file?
    Thanks.

    Normally you just double-click on them and they open!  The application that does this is "Archive Utility".  Located in /System/Library/CoreServices .
    charlie

  • Compress/Zip Files

    Does anyone know how to compress/zip files in OSX? I've tried doing this through Terminal, but it's been a couple of years since I last tried using UNIX commands and I can't get it to work.
    For what it's worth, I'm trying to compress pictures (.jpg) to email them.
    Any help would be great. Thanks.

    Hi McCons;
    An easy way to get around the file size limitations of email is to establish an iChat session and send the file over iChat.
    Allan

  • Is this file a compressed zip file ?

    Hi all,
    My program receive a file, which can be a regular file or a compressed zip file ...
    Is there any way for it to determine if this file is a zip one in order to decompress it ?
    Thanks !
    Vincent

    Try to handle it as a zip file (including maybe the perusal of its contents) and see whether there is an error.
    Some platforms come however with the command called "file" which guesses the file type basically upon its contents.
    $ file a.xls a.doc c.c bubu.ppt
    a.xls: ISO-8859 Java program text
    a.doc: ASCII text, with very long lines, with CRLF, LF line terminators
    c.c: empty
    bubu.ppt: Zip archive data, at least v1.0 to extract
    NAME
    file - determine file type
    SYNOPSIS
    file [ -bciknsvzL ] [ -f namefile ] [ -m magicfiles ] file ...
    file -C [ -m magicfile ]
    HISTORY
    There has been a file command in every UNIX since at least Research Version 6 (man page dated January 16, 1975). The System V version introduced one significant major change: the external list of magic number types. This slowed the program down slightly but made it a lot more flexible.

  • Compress/zip files from the command line in Windows 7?

    In Windows 7 is there a native way to compress or zip files from the command line?  I'd like to do it without installing any third-party utilities such as 7Zip.

    I fully agree that Compact is not the answer. There are additional concerns with the Compact command. It enables disk compression which is a total no-no. Very bad! It makes your computer very slow and is quite difficult to undo. The only time anyone should
    use this command is when they're removing disk compression because someone turned it on to save space.  Turning this off has to be done by booting into the recovery console, if my memory serves me correctly, and it's a real nuisance.  So
    definitely no to the Compact command.
    If you wanted to compress files before sending them to another drive, or over a network, or by email, then Compact wouldn't actually help at all because the files have to get uncompressed whenever they're accessed, especially before sending them anywhere. 
    When I say accessed, I mean that just looking at a file triggers the OS to decompress it in the background and present you with an uncompressed version of it then letting you change it and recompressing it again for storage every single time you access the
    file, which is why your machine gets slower.  If you have folders or files that have blue text instead of black, then you've probably already made this mistake.
    I would also like to know if there is a built-in command for zipping files/directories, or, if there isn't such a thing built into Windows, then I would like to know if this is feature is accessible through Visual Studio, which would be just as good as having
    a command-line program for those of us that do a bit of programming.
    If anyone knows if MS provides such a feature, either by command-line or through an API, then I'd love to hear about it.  Good luck to those of you that have disk compression turn on.

  • Download report as compressed/zip file

    Hi,
    i was wondering if it is possible to download a report compresed/(zip file). Some reports are more then 10MB and it's sometimes timeconsuming to download it to you local machine via a slow internet connection. If this is possible.. Is it then also possible to create an Ibot to sent a zipped report to mail :)
    regards,
    Osman

    I don't think you can compress a file or zip it and then download it. But you can schedule an ibot to download the file to a local drive using javascripts at night when no one is around and it doesn't matter how long it takes. Then, if you need to email them out, you can zip them there and email them. Here are some links that will help you with the javascripting:
    http://oraclebizint.wordpress.com/2007/12/17/oracle-bi-ee-101332-calling-java-scripts-and-java-classes-from-ibots/
    http://sureshotstrategies.wordpress.com/2008/04/12/writing-ibots-results-to-a-file/

  • Compress/zip file

    How do I compress/zip a keynote file that has been needs to be exported to a powerpoint file - So that I can email a presentation?
    Thanks

    Zip is now part of the Mac OS. Right-click on the file and choose "Compress ..." and the file will be zipped.
    John

  • Creating a zipped file from table data

    I am currently extracting data from a table and creating a flat file which is read later to create a compressed (zip) file.
    Is there a way that I can create a zipped file in one step (i.e. directly from the table data)? I am trying to reduce the number of file i/o hits in my appication.
    Thanks,
    Minesh

    Is there a way that I can create a zipped file in one step (i.e. directly from the table data)?Yes. Instead of doing something like:
    FileOutputStream fout = new FileOutputStream("flatfile");
    // write using foutdo this:
    ZipOutputStream zout = new ZipOutputStream("flatfile.zip");
    zout.putNextEntry(new ZipEntry("flatfile"));
    // write using zout

  • Compressing PDF files in Finder - Files are no smaller after compression!

    Hi,
    I have PDF portfolio files (Acrobat 9) that include images (jpegs and PNGs)and PDFs. I want to compress them so i can email them. When i ctrl click them and select 'compress' the resulting .zip file is exactly the same size as the original PDF file! Can anyone explain why?!
    Is it not possible to create compressed zip files from PDFs containing multiple files / types?
    FYI, i have made the PDFs themselves as small as possible within Acrobat before trying to compress them, compressing is a last resort!
    Thanks

    Thanks. I've reduced the image sizes to what i think is the minimum for good viewing, but the total PDF size is still too big for emialing (about 25mb). Is there any alternative to resizing the images (and other files) again and making the tottal PDF size smaller?

  • Making a Zip file.

    I have a folder of files and folders which i want to make into a zip file. How can i do that?

    Hello,
    Making ZIP Files (Compressed Files) in One Click
    Where the instructions say: To create a compressed file, either Control-click on the file and choose Create Archive (which is Apple-speak for “make a compressed ZIP file”). When you control click instead of seeing "make a compressed zip file", you might see: Compress ... such and such file.
    Carolyn

  • 500 error indexing zip files of pdf

    New install of CF10 and updated with mandatory hotfix and up to update 7.  I create a collection through CF Admin and attempt to index the contents of a directory that contains PDF and compressed zip files containing PDF files, I add .PDF and .ZIP to the list of file extensions to index.  I get a 500 error and indexing fails.  If I only attempt to index PDF extensions, the indexing operation completes successfully on the same directory.
    Has anyone else experienced this behavior and found a fix for it?
    Thanks in advance
    Tony
    Update: further testing shows that .txt files and .ppt files that are contained within a .zip file container are indexed successfully.  As soon as I add a .pdf to the .zip, it fails with the 500 internal server error.
    Message was edited by: Krispy74

    Resolved

  • How to create a self-extracting downloaded Zip file ...

    I have a question about Mac file compression for an eBook PDF.  I know how to compress the file with Mac OS X 10.8.5.  I right-click the PDF I want to compress and select "Compress <file name>" from the Contextual Menu.  The file is compressed as a ZIP file.  The file I'm compressing will be distributed from a web server to Mac users.
    SITUATION:  I want the Mac user to be able to download the ZIP file to their Mac.  Once the ZIP file is downloaded to their Mac, I want the ZIP file to automatically open to place the eBook PDF on their desktop - so please indulge me here.  I know that a Mac user only needs to double-click the ZIP file to extract the eBook PDF, BUT, IF POSSIBLE, I want this to happen automatically after the ZIP file is downloaded.
    QUESTION:  Is there any way to automatially extract the eBook PDF from the ZIP file once the Mac user downloads the ZIP file to their destop?  If so, how do I do this?  If not, is there anyother way to do this that does not required any additional software like StuffIt Expander to decompress the file?  As an aside, If I compress the eBook PDF using Mac OS X 10.8.5, is this compressed ZIP file compatible with older versions of Mac OS, i.e., can they double-click the compressed ZIP file to open it?
    Thank you in advance for your comments and help . . .
    Jim Minor
    Email: [email protected]

    In OSX, zip extraction depends on the browser and browser settings. For example, Safari will open files automatically depending on this setting in Sarari Preferences: So the short answer I think is no. Your zip recipients are going to have to click on the zips to open them if their browser is not set to open them automatically.
    I'm no zip expert but I would think a zip is a zip and should be compatible with older versions of OSX. That is, 10.4 or later, which didn't include Stuffit any more. Earlier versions would need Stuffit or something similar.

  • Transfering a .zip file

    ive got a compressed ZIP file of photos that i want to send to Germany - any way i can?
    Thanks

    Hi macmanman,
    One solution that comes to mind (assuming you are only after solutions that don't cost money) is to log in to your router, forward port 548 to your Mac's IP address, enable File Sharing in your Mac's preferences and then put the appropriate file in your Shared folder. Obviously your Mac needs to be switched on and connected to the interwebbywotsit for this to work.
    With the above method, all a remote user has to do is select Go->Connect to Server... from the Finder menubar, enter your public IP address (if you don't know what your public IP address is just go to www.whatismyip.com) and log in as a Guest. This will give them access to files within your Shared folder and they can download the specific file.
    If you are looking at sending large files on a regular basis, and do not have a Mac that is accessible all the time, then you will need to start considering fee based solutions which involve remote storage like .Mac etc.
    Kryten

  • Get "in memory" zip file's content

    Hello,
    How can I get the contents of a compressed zip file that is in memory?
    Thanks
    Karen

    The zip file is in memory as a byte array.
    However I'm downloading the zip file from a server, and storing it in memory myself so the format is not an issue. I can manipulate it as I need.
    Karen

  • Can't figure out why the "Do this automatically for files like this from now on" is disabled Compressed (zipped) Folders

    I recently had to uninstall and reinstall Firefox. Now with the new version it will not allow me to click the check box "Do this automatically for files like this from now on". The line is disabled and a light gray. I went into the Applications tab under options and can't find the Compressed (zipped) Folders file type either.
    I download a bunch of files for work and to have to click is going to be the biggest pain. Any help will be greatly appreciated!!

    Screenshot:

Maybe you are looking for