Help in creating Zip files from .Net and reading them from Java - java

I'm trying to create a Zip file from .Net that can be read from Java code.
I've used SharpZipLib to create the Zip file but also if the file generated is valid according to the CheckZip function of the #ZipLib library and can be successfully uncompressed via WinZip or WinRar I always get an error when trying to uncompress it using the Java.Utils.Zip class in Java.
Problem seems to be in the wrong header written by SharpZipLib, I've also posted a question on the SharpDevelop forum but with no results (see http://community.sharpdevelop.net/forums/t/8272.aspx for info) but with no result.
Has someone a code sample of compressing a Zip file with .Net and de-compressing it with the Java.Utils.Zip class?
Regards
Massimo

I have used DotNetZip library and it seems to work properly. Typical code:
using (ZipFile zipFile = new ZipFile())
{
zipFile.AddDirectory(sourceFolderPath);
zipFile.Save(archiveFolderName);
}

I had the same problem creating zips with SharpZipLib (latest version) and extracting with java.utils.zip.
Here is what fixed the problem for me. I had to force the exclusion of the zip64 usage:
ZipOutputStream s = new ZipOutputStream(File.Create(someZipFileName))
s.UseZip64 = UseZip64.Off;

Can't help with SharpZipLib, but you can try to create zip file using ZipPackage class System.IO.Packaging without using 3rd part libraries (requires .NET 3+).

To judge whether it's really a conformant ZIP file, see PKZIP's .ZIP File Format Specification.
For what it's worth I have had no trouble using SharpZipLib to create ZIPs on a Windows Mobile device and open them with WinZip or Windows XP's built-in Compressed Folders feature, and also no trouble producing ZIPs on the desktop with SharpZipLib and processing them with my own ZIP extraction utility (basically a wrapper around zlib) on the mobile device.

You don't wanna use the ZipPackage class in .NET - it isn't quite a standard zip model. Well it is, but it presumes a particular structure in the file, with a manifest with a well-known name, and so on. ZipPackage seems to have been optimized for Office docs and XPS docs.
A third-party library, like http://www.codeplex.com/DotNetZip, is probably a better bet if you are doing general-purpose ZIP files and want good interoperability.
DotNetZip builds files that are very interoperable with just about everything, including Java's java.utils.zip. But be careful using features that Java does not support, like ZIP64 or Unicode. ZIP64 is useful only for very large archives, which Java does not support well at this time, I think. Java supports Unicode in a particular way, so if you produce a Unicode-based ZIP file with DotNetZip, you just have to follow a few rules and it will work fine.

I had a similar problem with unzipping SharpZipLib-zipped files on Linux. I think I solved it (well I works on Linux and Mac now, I tested it), check out my blog post: http://igorbrejc.net/development/c/sharpziplib-making-it-work-for-linuxmac

Related

open SAS risk file extension of .rskcdesc

In my project which deals with SAS
we have risk binary files of extension .rskcdesc
I have been looking but not able to find any python Java library which can read it.
I need to automate data checks via Backend process, hence need a way to decode these files.
Any suggestions?
Rohit,
I don't have SAS Risk but SAS has been using zip for some of their files (like EG projects). Try renaming the file extension to .zip and open it. It may be comprised of XML files, similar to EG.

Is there a solution to read the RAR files of version 5 using Junrar library?

I'm writing part of Java application responsible for reading archive files of different formats and preparing a preview mode.
Junrar library appeared to be the most reliable to work with RAR format, but it doesn't support the latest version 5 of rar. Only earlier versions are supported.
Junrar dev team confirms this fact here:
https://github.com/junrar/junrar/issues/23
Winrar by default creates rar files of version 5, but checkbox 'RAR4' in properties helps to create a file of version 4 - which is perfect to work with. But you have to click it every time you archive the file - that's not a good way (earlier versions of Winrar can't be downloaded from official website).
In my case file is stored as a byte array. I don't need to UNRAR file, i just read it - i need 'name' and 'size' of every file inside of it - thus i prepare preview data of archive content as a small HTML table.
Do you know any other good library to work with Rar format? I can't find any.
Or maybe you can imagine some good workarounds?
There is no available solution to unrar RAR5 archives except Winrar itself. You may call it as external program if it is possible on your OS.
I am also treating archives of different formats and I am using junrar for extracting RAR, RAR5 archives remain untreated.
Junrar initially was developed by Edmund Wagner, and some time ago the support was renewed by Beothorn. But, much to my regret, he is not planning to implement RAR5 support for some reason.
I have also checked Raroscope, it does not support RAR 5 neither.
By the way, another archive, which is not supported by open source java library, is ARJ.

How to compress text file to rar format using java program

Is there any java library by which we can compress a plain text file(.txt) into winRAR format(.rar). I have been searching in google but couldn't find any relevant library which does that.
you can always do
Runtime.getRuntime().exec("rar -a somefile.txt");
I think RAR is not open-source format. I'd rather use ZIP - it's built-in in Java.
RAR is a proprietary format, and I don't know of any library to create it (although there seem to be some that can read it). Any reason why you wouldn't use another, more open format like 7zip (for compression), or plain Zip (for universal compatibility)?
(From the question, of which this one is a duplicate - RAR archives with java)
You could try JUnRar, "a RAR handling API implemented in pure Java" (quoting the site).
No you can not do it. Only WinRAR can create rar file. There is only a unrar library for it.
One reason to use RAR: It is sooooo much better than ZIP. For example: One of our production print files has a lot of repetition (including images) in it. 142 MB large, it zips to about 80MB. RAR seems to detect these repetitions and the resulting file is not even 2MB!
Why RAR? as others have mentioned, RAR is not open.
Java has native ZIP API.
Java Zip API: How to Create a Zip File Using Java

Using zip file without extracting in java

I'm facing a problem that, we have a .zip file that contains some text files. Now I'm using java to access that files. If it is not in the .zip file I can read and print on my console easily using FileInputStream.
But how to read a file from .zip file? I use J2SE only..
You should try a ZipInputStream. The interface is a little obtuse, but you can use getNextEntry() to iterate through the items in the .zip file.
As a side note, the Java class-loader does exactly this to load classes from .jar files without extracting them first.
Everything you need is in ZipFile: https://docs.oracle.com/javase/7/docs/api/java/util/zip/ZipFile.html. Google for examples on the web, and if you have specific problems then come back to SO for help.
(The link will eventually break; when it does simply websearch java zipfile.)

File names with Japanese characters turn to garbage when written to a zip file using java.util.zip.*

I have a directory with a name that contains Japanese characters, and I need to use the zip utils in java.util.zip to write it to a zip file. Writing the zip file succeeds, but when I open the resulting zip file with either Windows' built-in compressed file utility or 7-Zip, the directory with Japanese characters in the name appears as a bunch of garbage characters. I do have the Japanese/East Asian language pack installed on my system -- I can create directories with Japanese names, so that isn't the issue.
Interestingly, if I write a separate script to read the resulting zip file using java.util.zip, the directory name is correct, and I can extract the contents of the zip into appropriately named directories, with Japanese characters. But I can't do this using the commercial zip tools that I've tried, which is undoubtedly what our customers will want to do.
Any ideas about what is causing this problem, and how I can work around it?
I know about this bug, but I still need a workaround for this case.
TrueZIP claims to do this better:
The J2SE API always uses UTF-8 (eight
bit Unicode character set) for entry
names and comments instead of CP437
(a.k.a. IBM437, the genuine IBM-PC
character set), which is used by the
de-facto standard PKZIP from PKWARE.
As a result, you cannot read or write
ZIP files with international entry
file names such as e.g. "täscht.txt"
in a ZIP file created by a (southern)
German.
[description of other problems omitted]
The TrueZIP Library has been developed to overcome these limitations/disadvantages.
Miracles indeed happen, and Sun/Oracle did really fix the long-living bug/rfe:
Now it's possible to [set up filename encodings upon creating][1] the zip file/stream (requires Java 7).
[1]: http://download.java.net/jdk7/docs/api/java/util/zip/ZipOutputStream.html#ZipOutputStream(java.io.OutputStream, java.nio.charset.Charset)
If java.util.zip still behaves as this post describes, I'm not sure if it is possible (with the built-in classes). I have seen Chilkat's Java Zip library mentioned before as a way to get this to work, but have never used it.

Categories

Resources