Results 1 to 6 of 6

Thread: Compress files in java

  1. #1
    Join Date
    Dec 2009
    Posts
    202

    Compress files in java

    Hi
    The package is java.util.zip interesting but it is impossible to actually use a file without recreating it completely. For example, if you want to add or remove an entry in the zip, when you open a ZipOutputStream, that is your old file is deleted basically can not handle the file structure (primarily addition / removal of entry) without removing the file and recreate that in terms of IO (I am looking for extreme performance) is relatively important especially for relatively large files of several MB. So, basically I want to know that how to compress files in java, or alternatively is there is a good, store for the zip files.

  2. #2
    Join Date
    Nov 2009
    Posts
    518

    Re: Compress files in java

    Hello,
    I think with the ZIP and JAR API is provided that is required to go through Entry and a host of specialized stream classes when it could been much easier to use an API like suppose File (or URL/URI why has not the limit) and flows and standards and access files in the archive as if they were, in a regular file system, in short, something that will have allowed to handle any AC much more transparent manner.

  3. #3
    Join Date
    Nov 2009
    Posts
    343

    Re: Compress files in java

    Hello,
    It is possible using the URL type jar, like when you access resources on the classpath. For example to retrieve a URL to a file within an archive you can use a method like this,
    Code:
        Public static URL getpatharc(Archive file, String path) {
            try {
                return new URL("jar:" + Archive.TOURI() + "!" + Path);
            } catch (MalformedURLException e) {
                / / Should not happen:
                throw new RuntimeException(e);
            }        
        }
    This works for both the jar as zip

  4. #4
    Join Date
    Nov 2009
    Posts
    356

    Re: Compress files in java

    Hello,
    The above is correct, I think it should work both for zip and jar files. The API merely hide it because I think it is impossible to change live a zip archive. There are two solutions:
    - Create a temporary file on the filesystem, which will replace the original at the end of treatment.
    - Create a temporary file in RAM, which will overwrite the original file at the end of treatment.

  5. #5
    Join Date
    Nov 2009
    Posts
    446

    Re: Compress files in java

    Hello,
    Overall it lacks an API such PluggableFileSystem that would have to mount the file systems contained in archives (ZIP, TAR, JAR, GZ, Z, RAR, ARJ, ...), in images (ISO, NRG, ...), the protocol file sharing (NFS, SMB, ...), or even other types of partitions (although the latter option probably ask ca integration with JNI) is the place where you want (the file itself even for the archives, for example) in order to manipulate their content in a transparent manner while using the package / java.io API / java.nio usual. Current methods (and the new Java 6) of the File class are sufficient to determine if they can write to the archive / image / share / partition mounted for the rest there is also enough IOException and SecurityException (when we need to authenticate to access the content) to manage most of the prohibitions and error, I think.

  6. #6
    Join Date
    Nov 2009
    Posts
    333

    Re: Compress files in java

    Hello,
    Indeed TrueZip can browse the contents of archives as if they were directories, update archive. However, this library is more, it seems to me updated. Even if the library can theoretically add drivers to support various types of archives, the documentation is rather short on the subject. If you require any more help regrading this topic then do post back and we will try to help you.

Similar Threads

  1. How can i compress MP4 files
    By Dolf in forum Windows Software
    Replies: 4
    Last Post: 27-09-2013, 02:04 PM
  2. How to Compress old files
    By NICOLASA in forum Operating Systems
    Replies: 3
    Last Post: 06-07-2009, 11:32 AM
  3. How to compress PDF files
    By avvia in forum Windows Software
    Replies: 3
    Last Post: 22-06-2009, 10:52 AM
  4. How to compress FLV Files
    By Abalakin in forum Windows Software
    Replies: 2
    Last Post: 19-05-2009, 03:34 PM
  5. Compress .JPG Files
    By fabien in forum Customize Desktop
    Replies: 3
    Last Post: 18-03-2009, 06:03 PM

Tags for this Thread

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
  •  
Page generated in 1,750,134,270.88735 seconds with 16 queries