User not logged in - login - register
Home Calendar Books School Tool Photo Gallery Message Boards Users Statistics Advertise Site Info
go to bottom | |
 Message Boards » » java zip utility issue Page [1]  
LittleZZ
Veteran
442 Posts
user info
edit post

anyone have a lot of experience with the java.util.zip api? I'm trying to use it to unzip some files downloaded from a server at work, and when I run it, i get the following error:

Exception in thread "main" java.lang.InternalError: invalid compression method

I've done some research online and found a few possible issues, but none of them seem to apply to my situation.

One site mentioned to make sure to download the file from the ftp site as binary and not ascii, which is what I am doing. Another site mentioned that it may not be an actual zip file, so I looked and the first two bytes of the file are the characters 'P' and 'K' which denotes a zip file rather than a gzip file.

winzip opens the file without any issue, and I have tried using a zip file that was already on my computer, and i had a little better results, but got another error dealing with no more entries.

Here is the code that is causing the problem:

public String[] getContents() {
try {
zip = new ZipFile(this.inputFile);
int i=0;
String zipContents = null;

for (Enumeration entries = zip.entries(); entries.hasMoreElements() {
// Get the entry name
if (i == 0) {
zipContents = ((ZipEntry)entries.nextElement()).getName();
}
else {
zipContents = zipContents + " " +
((ZipEntry)entries.nextElement()).getName();
}

i++;
}

contents = zipContents.split(" ");
return contents;
}
catch (Exception e) {
e.printStackTrace();
return null;
}
}

The error occurs on the line where the ZipFile is create ("zip = new ZipFile(this.inputFile);")

Any suggestions?

3/18/2006 8:27:36 PM

LittleZZ
Veteran
442 Posts
user info
edit post

hmmm...well i've done a little more research since posting and it seems that the files I am downloading were compressed using the imploded compression method (06). From what I can find this is not supported by the java.util.zip api. So, it looks my options are to run an external command to unzip it, or find an api that supports the imploded compression method. Once again, any help would be appriciated. Thanks

3/18/2006 8:45:24 PM

ZeroDegrez
All American
3897 Posts
user info
edit post

If you need to run an external application... You can access the runtime object and call the exec() command on it and run any shell command if you know what the name of the external app is called, or where it is located.

I have not done any zipping with java...so I haven't bothered looking for an alternative api for it. Though I bet if you check sourceforge.net you may find something.

3/18/2006 9:33:19 PM

Perlith
All American
7620 Posts
user info
edit post

Java zipping is extremely limited with what it supports. Think of zips and jars as the same thing in java, and then you can guess the limitations. I think at best, it supports a password on the file and some basic compression methods. I know 1.4.x doesn't support encryption ... ran into this issue earlier.

Winzip 9.x and a couple of other zipping utilities have compression unique to those programs. MIght want to send an email and find out what program/flags they used to zip the file up with.

3/19/2006 8:56:21 AM

LittleZZ
Veteran
442 Posts
user info
edit post

thanks for the input guys...

Zero, I am aware of that, and would like to do it from the program itself if rather relying on an external program if possible. This is because the overall program is something that would be installed on a variety of systems, where you really do not know what is installed already, so we would have to include the zip utility with the package to insure that it works like it is supposed to. In addition, this is an internal program for my job so we would have to be weary of licensing issues with any external programs that we use. Thanks for the sourceforge.net idea, haven't checked there yet, so I'll look into it tomorrow.

Perlith, I am only concerned with unzipping files that have been compressed and placed on an internal server, so encryption and password encoding isn't an issue. Have you seen any other api's that may be usefull? As for winzip, see my above comment about using an external aplication to do this. We have been told to take winzip and pkzip off of our systems in the past so I am a little leary about using one of those for this.

BTTT for any other suggestions...

3/20/2006 7:28:44 PM

zorthage
1+1=5
17148 Posts
user info
edit post

What's the source of the zip files? If you can control the zipping, you shouldn't have trouble with the unzipping. If you don't have access to the zipping, I don't think the java API will give you what you need.

3/20/2006 8:58:04 PM

LittleZZ
Veteran
442 Posts
user info
edit post

zorthage, i cannot control the zipping of the files, thats why i'm having this issue. I did find another api called truZip that looked promising, but it turns out to have the same limitations as the java.util.zip api. I think we're just going to go with winZip (i talked to the guy I'm working with and he said winZip should be ok, just not pkZip) and unzip the files via the commandline interface and exec(). Thanks for the input guys.

3/21/2006 11:00:53 AM

Shaggy
All American
17820 Posts
user info
edit post


//The Command class
//The Command class executes a command in a dos command prompt and captures the output and any errors.
//Eric DeVaudreuil
//8/31/04
//version .5


import java.util.*;
import java.io.*;

public class Command
{

private String cmdOutput;
private String cmdError;

private int debugLevel;

public Command(int debug)
{
this.cmdOutput = null;
this.cmdError = null;
this.debugLevel = debug;
}

public void setDebug(int d)
{
this.debugLevel = d;
}

public int getDebug()
{
return this.debugLevel;
}

public String runCommand(String theCommand)
{
String exitVal ="";
Runtime rt = Runtime.getRuntime();
String[] cmd = new String[3];
cmd[0] = "cmd.exe";
cmd[1] = "/C";
cmd[2] = theCommand;

try
{
Process proc = rt.exec(cmd);

if(this.debugLevel >=1)
{
if(this.debugLevel>=2)
{
System.out.println("*****Command.java debug level "+this.debugLevel);
System.out.println("*****Printing command output/errors for "+theCommand);
System.out.println("*****Exit Value: "+exitVal);
}

this.cmdOutput = new String("");
this.cmdError = new String("");

InputStreamReader osr = new InputStreamReader(proc.getInputStream());
InputStreamReader esr = new InputStreamReader(proc.getErrorStream());

BufferedReader obr = new BufferedReader(osr);
BufferedReader ebr = new BufferedReader(esr);

String oline = null;
String eline = null;
int linenumber=0;
while ( (oline = obr.readLine()) != null)
{
linenumber++;
this.cmdOutput+=("line "+linenumber+":: "+oline+"\n");
if(this.debugLevel >=2)
{
System.out.println("Command Output> "+oline);
}
}
linenumber=0;
while ( (eline = ebr.readLine()) != null)
{
this.cmdError+=("line "+linenumber+":: "+eline+"\n");
if(this.debugLevel >=2)
{
System.out.println("Command Error> "+eline);
}
}
}
exitVal = Integer.toString(proc.waitFor());
if(this.debugLevel>=2)
{
System.out.println("*****Command.java debug level "+this.debugLevel);
System.out.println("*****Printing command output/errors for "+theCommand);
System.out.println("*****Exit Value: "+exitVal);
}

}
catch(Exception e)
{
System.out.println(e);
e.printStackTrace();
}
return exitVal;
}

public String getOutput()
{
if(this.debugLevel<1)
{
return "";
}
return this.cmdOutput;
}

public String getError()
{
if(this.debugLevel<1)
{
return "";
}
return this.cmdError;
}


/* public static void main (String [] args)
{
Command c = new Command(1);
String cmd = "";
System.out.println("Enter command");
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
try
{
cmd = br.readLine();
}
catch (IOException ioe)
{
System.out.println("omf java is ass!");
System.exit(1);
}

String exit = c.runCommand(cmd);


System.out.println(c.getOutput());
System.out.println(c.getError());
System.out.println("Exit value: "+exit);
}*/

}

3/21/2006 11:37:45 AM

 Message Boards » Tech Talk » java zip utility issue Page [1]  
go to top | |
Admin Options : move topic | lock topic

© 2024 by The Wolf Web - All Rights Reserved.
The material located at this site is not endorsed, sponsored or provided by or on behalf of North Carolina State University.
Powered by CrazyWeb v2.39 - our disclaimer.