Search the archives!
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
java.util.zip questions...
- From: Allen Tuggle" <allent@xxxxxxxxxx (Allen Tuggle)
- Subject: java.util.zip questions...
- Date: Thu, 30 Mar 2000 12:52:39 -0500
This is a multi-part message in MIME format.
------=_NextPart_000_0016_01BF9A46.D4DE7440
Content-Type: multipart/alternative;
boundary="----=_NextPart_001_0017_01BF9A46.D4DE7440"
------=_NextPart_001_0017_01BF9A46.D4DE7440
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
Hello,
I'm currently using this to simpley compress a file for storage in a =
database and then to uncompress later. Right now i'm saving the file to =
disk then opening and compressing it with java.util.zip.Deflater. and =
writing that out to disk. when I read that file back in and try to =
uncompress it with java.util.zip.Inflater it gives me an error =
(java.util.zip.DataFormatException: unknown compression method)
If any one can help I would greatly appreciate it... attatched is the =
three functions I have wrote warning they look ugly due to =
frustration....
=20
------=_NextPart_001_0017_01BF9A46.D4DE7440
Content-Type: text/html;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META content=3D"text/html; charset=3Diso-8859-1" =
http-equiv=3DContent-Type>
<META content=3D"MSHTML 5.00.2919.6307" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY>
<DIV><FONT face=3DArial size=3D2>Hello,</FONT></DIV>
<DIV><FONT face=3DArial size=3D2> I'm currently using =
this to=20
simpley compress a file for storage in a database and then to uncompress =
later. Right now i'm saving the file to disk then opening and =
compressing=20
it with java.util.zip.Deflater. and writing that out to =
disk. when I=20
read that file back in and try to uncompress it with =
java.util.zip.Inflater it=20
gives me an error (java.util.zip.DataFormatException: unknown =
compression=20
method)</FONT></DIV>
<DIV> </DIV>
<DIV> </DIV>
<DIV><FONT face=3DArial size=3D2>If any one can help I would greatly =
appreciate=20
it... attatched is the three functions I have wrote warning they =
look ugly=20
due to frustration....</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=3D"Courier New" size=3D2> =20
</FONT></DIV></BODY></HTML>
------=_NextPart_001_0017_01BF9A46.D4DE7440--
------=_NextPart_000_0016_01BF9A46.D4DE7440
Content-Type: text/plain;
name="tempfile.txt"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment;
filename="tempfile.txt"
public static void compress(String document, String signature) {=0A=
String home =3D "/usr/users/oracle/product/8.0.5/ows/4.0/test/";
=0A=
deflate(signature,"signature.zip");
inflate("signature.zip","signature.unzip");
=0A=
=0A=
}
=0A=
/** =0A=
* Method main this is the instanciating method for this class. =0A=
*/=0A=
public static void deflate(String fileName, String newName) {
String home =3D "/usr/users/oracle/product/8.0.5/ows/4.0/test/";
=0A=
try {
FileInputStream fis =3D new FileInputStream(home+fileName);
int avail =3D fis.available();=20
//Deflater deflate =3D new Deflater(Deflater.BEST_COMPRESSION);
Deflater deflate =3D new Deflater();
DeflaterOutputStream deflate_os =3D new DeflaterOutputStream((new =
FileOutputStream(home+newName)),deflate,avail);=20
int read =3D 0;=20
int defNum =3D 0;=20
byte[] bufAry =3D new byte[avail];
byte[] defAry =3D null;
deflate.setStrategy(Deflater.DEFAULT_STRATEGY);=20
while ((read =3D fis.read(bufAry)) !=3D -1) {
System.out.println("Allen ONE read =3D " + read);
defNum =3D deflate.deflate(bufAry);
System.out.println("Allen defNum =3D " + defNum);=0A=
deflate_os.write(bufAry);
//fos.write(defAry);
}=20
fis.close();
deflate_os.close();
} catch (FileNotFoundException e) {
System.out.println("error: " + e);
} catch (java.io.IOException e) {
System.out.println("error: " + e);
}
=0A=
}
=0A=
/** =0A=
* Method main this is the instanciating method for this class. =0A=
*/=0A=
public static void inflate(String fileName, String newName) {
String home =3D "/usr/users/oracle/product/8.0.5/ows/4.0/test/";
try {
FileInputStream fis =3D new FileInputStream(home+fileName);
FileOutputStream fos =3D new FileOutputStream(home+newName);
int avail =3D fis.available();=20
Inflater inflate =3D new Inflater();
//InflaterInputStream Inflate_is =3D new InflaterInputStream((new =
FileInputStream(home+fileName)),inflate,avail);=20
int read =3D 0;=20
int infNum =3D 0;=20
byte[] bufAry =3D new byte[avail];
byte[] infAry =3D null;
System.out.println("needs dictionary =3D " + inflate.needsDictionary());
while ((read =3D fis.read(bufAry)) !=3D -1) {
if (inflate.needsInput()) {
inflate.setInput(bufAry);
}
//infAry =3D new byte[inflate.getRemaining()];
infAry =3D new byte[3628];
System.out.println("Allen FIVE getREmaining() =3D " + =
inflate.getRemaining());
infNum =3D inflate.inflate(infAry);
System.out.println("Allen infNum =3D " + infNum);=0A=
//deflate_os.write(bufAry);
fos.write(infAry);
}=20
fis.close();
fos.close();
} catch (FileNotFoundException e) {
System.out.println("error: " + e);
} catch (java.util.zip.DataFormatException e) {
System.out.println("error: " + e);
} catch (java.io.IOException e) {
System.out.println("error: " + e);
}
=0A=
}=0A=
------=_NextPart_000_0016_01BF9A46.D4DE7440--
---
To unsubscribe, mail advanced-java-unsubscribe@xxxxxxxxxxxxxxxx
To get help, mail advanced-java-help@xxxxxxxxxxxxxxxx
- Follow-Ups:
- java.util.zip questions... I figured it out!
- From: <allen@xxxxxxxxxxxxx (Allen Tuggle)
- java.util.zip questions... I figured it out!
- Prev by Date: [Fwd: A Peculiar Problem with the HTTP Get method :- JSP]
- Next by Date: JDBC-ODBC bridge and prepared statements
- Previous by thread: [Fwd: A Peculiar Problem with the HTTP Get method :- JSP]
- Next by thread: java.util.zip questions... I figured it out!
- Index(es):