java.util.zip.ZipException using ZipUtils from MSDNmag

java.util.zip.ZipException using ZipUtils from MSDNmag

Post by vijai thop » Fri, 07 May 2004 04:33:17


Hello,

I've developed a application using C# & its saving files in xml format.
Since the size of the file, is huge i'm using Zip Classes from J# in my C#
code, based on the
article in MSDNmag
( http://www.yqcomputer.com/ )

It's able to compress files upto size of 3 mb (xml) . Anything more than
that size it throw's an exception of type util.zip.ZipException, which i'm
catching it & these are the messages.
java.lang.ArrayIndexOutOfBoundsException: 65536
at java.io.FileInputStream.read(SByte[] buffer, Int32 offset, Int32
count)
at java.util.zip.ZipFile.readZIPEntries(String fname)

Is there a workaround for this problem. Even if i Ignore this exception,
when i try to open it back it throws the same exception
Any help will be greatly appreciated.

Thanks,
Vijai
 
 
 

java.util.zip.ZipException using ZipUtils from MSDNmag

Post by v-phuan » Fri, 07 May 2004 17:01:44

Hi vijai,

First of all, I would like to confirm my understanding of your issue.
From your description, I understand that you wants to use the Zip Classes
from J# in C# to compress an xml file larger than 3MB.
Have I fully understood you? If there is anything I misunderstood, please
feel free to let me know.

Here is my code which will use the Zip Classes to compress a file you may
have a try and let me know the result.
public static void compress_file(String filename, String outfilename)
{
try
{
sbyte[] buf = new sbyte[4096]; //read buffer
int retval; //return value
//set up input stream
FileInputStream fis = new FileInputStream(filename);
//set up output stream
FileOutputStream os = new FileOutputStream(outfilename);
//wrap output stream in ZipOutputStream
ZipOutputStream zos = new ZipOutputStream(os);
//set entry field in zipfile; do this once for each
//file you're compressing
ZipEntry ze = new ZipEntry(filename.Remove(0,
System.IO.Path.GetPathRoot(filename).Length));
ze.setMethod(ZipEntry.DEFLATED);
zos.putNextEntry(ze);
//read the input file in and write it to the zipfile
do
{
//read file in from input stream
retval = fis.read(buf, 0, 4096);
//-1 indicates end of file
if (retval != -1)
{
//write buffer to output stream
zos.write(buf, 0, retval);
}
}while (retval != -1);
//close this ZipEntry
zos.closeEntry();
//close input stream
fis.close();
//close output stream
zos.close();
}
catch(Exception e)
{
Console.WriteLine("Exception occurred: " + e);
}
}

[STAThread]
static void Main(string[] args)
{
//Create a file about 6MB.
string filename = @"C:\Test.xml";
XmlTextWriter w = new XmlTextWriter(filename,System.Text.Encoding.Unicode);
w.WriteStartElement("x","root","urn:1");
double percent1,percent=0;
for(int i=0;i<100000;++i)
{
percent1 = (double)i/1000;
if ((int)percent1 > percent)
{
Console.WriteLine(percent.ToString()+"%");
percent = percent1;
}

w.WriteStartElement("y" + i.ToString(),"item","urn:1");
w.Wri *** dElement();
}
w.Wri *** dElement();
w.Close();
//compress the file
compress_file(filename,@"C:\test.zip");
}


Please apply my suggestion above and let me know if it helps resolve your
problem.

However, if you still have any concern on this issue, please post a simple
reproduce sample here.
I will appreciate for your efforts.


Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

 
 
 

java.util.zip.ZipException using ZipUtils from MSDNmag

Post by vijai thop » Fri, 07 May 2004 22:22:17

i Peter,

Thanks for your suggestion. Whatever you understood is correct. I've done
exactly the same steps to compress a file, with an additional step at the
end by using this class "java.util.zip.ZipFile(_FileName) " to create a new
ZipFile. Also while opening it, i'm using the same class to extract the
contents from it. The real problem is while trying to create a new
java.util.zip.ZipFile(_FileName) its blowing out by throwing an exception.

Do you've any equivalent sample code to uncompress the ZipFile without
using this class "java.util.zip.ZipFile(_FileName)"? Here's my code to
compress & uncompress the Zip File.

public static void ExtractZipFile(ZipFile file, string path,
FilterEntryMethod filter)
{

foreach(ZipEntry entry in new EnumerationAdapter(new
EnumerationMethod(file.entries)))

{

if (!entry.isDirectory())

{

if ((filter == null || filter(entry)))

{

java.io.InputStream s = file.getInputStream(entry);

try

{

string fname =
System.IO.Path.GetFileName(entry.getName());

string newpath = System.IO.Path.Combine(path,
System.IO.Path.GetDirectoryName(entry.getName()));


System.IO.Directory.CreateDirectory(newpath);

java.io.FileOutputStream dest = new
java.io.FileOutputStream(System.IO.Path.Combine(newpath, fname));

try

{

CopyStream(s, dest);

}

finally

{

dest.close();

}

}

finally

{

s.close();

}

}

}

}

}

public static void CopyStream(java.io.InputStream from, java.io.OutputStream
to)

{

sbyte[] buffer = new sbyte[8192];

int got;

while ((got = from.read(buffer, 0, buffer.Length)) > 0)

to.write(buffer, 0, got);

}

public static ZipFile UpdateZipFile(ZipFile file, FilterEntryMethod filter,
string[] newFiles)

{

string prev = file.getName();

string tmp = System.IO.Path.GetTempFileName();

ZipFile _newZipFile = null;

try

{

ZipOutputStream to = new ZipOutputStream(new
java.io.FileOutputStream(tmp));

try

{

CopyEntries(file, to, filter);

// add entries here

if (newFiles != null)

{

foreach(string f in newFiles)

{

ZipEntry z = new ZipEntry(f.Remove(0,
System.IO.Path.GetPathRoot(f).Length));

z.setMethod(ZipEntry.DEFLATED);

to.putNextEntry(z);

try

{

java.io.FileInputStream s = new
java.io.FileInputStream(f);

try

{

CopyStream(s, to);

}

finally

 
 
 

java.util.zip.ZipException using ZipUtils from MSDNmag

Post by v-phuan » Sat, 08 May 2004 16:37:38

Hi Vijai,

I am sorry that I miss the problem in the J# runtime.
As Ianier, I think you can contact Microsoft PSS for the hotfix, because we
can not provide the hotfix in the newsgroup.

Also you can use the #ZipLib to do the job which is open source.
You may get the in the link below.
http://www.yqcomputer.com/

Otherwise I think we have to use the third-party control.
e.g.
IP*Works! Zip V5 .NET Edition
http://www.yqcomputer.com/
Xceed Zip for .NET
http://www.yqcomputer.com/


Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 
 
 

java.util.zip.ZipException using ZipUtils from MSDNmag

Post by vijai thop » Sat, 08 May 2004 23:31:35

Thanks Peter for the link. I managed to use #ZipLib by making few changes to
mycode & its not throwing any exception. Hope MS will fix this issue in
future release.

~Vijai


we
rights.
 
 
 

java.util.zip.ZipException using ZipUtils from MSDNmag

Post by Kosmatos » Sun, 09 May 2004 05:07:50

Thanks for mentioning Xceed Zip for .NET.

The correct link is to http://www.yqcomputer.com/

I don't think Hallogram lists the text for v2.0, which is much
more than just a basic Zip component.

Thanks,
Odi
 
 
 

java.util.zip.ZipException using ZipUtils from MSDNmag

Post by Kosmatos » Sun, 09 May 2004 05:09:25

Sorry - I posted the wrong link as a correction. The irony.

Xceed Zip for .NET = http://www.yqcomputer.com/