Win a copy of Head First Agile this week in the Agile forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Unzipping afile using java  RSS feed

 
Ramkumar Ramasubbu
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

i am trying to unzip a file. while unzipping it gives NullPointerException.
Here is the piece of code i am using.

ResultSet rs = stmt.executeQuery();
rs.next();
blob = rs.getBlob(1);
byteBuffer = blob.getBytes(1, (int) blob.length());
String compressionType = "ZIP";
String bomCache = new String(unCompress(byteBuffer));


private static byte[] unCompress(byte[] compressedContents)throws Exception{
int SIZE_ENTRY_LENGTH = 64;
String SIZE_ENTRY_NAME = "__size";
String BOM_ENTRY_NAME = "BOM";
//String path = "D:\\Ramkumar\\Project_Document\\BlobFiles\\";
final int BUFFER = 2048;
byte[] sizeBA = new byte[SIZE_ENTRY_LENGTH];
byte[] uncompressedContents = null;
int uncompressedSize = 0;
ZipEntry entry;
ZipEntry sizeZipEntry = null;
ZipEntry bomZipEntry = null;

try{
System.out.println("compressedContents:" +compressedContents.length);
ByteArrayInputStream bais = new ByteArrayInputStream(compressedContents);
ZipInputStream zis = new ZipInputStream(new BufferedInputStream(bais));
System.out.println("zis contents "+zis.toString().length());
System.out.println("zis contents "+zis.available());
entry = zis.getNextEntry();
Enumeration entries;

System.out.println("entry "+entry);
while ((entry = zis.getNextEntry()) != null) {
System.out.println("Inside while 1");
if((entry.toString()).equals(SIZE_ENTRY_NAME))


this is the output///////////////////////////////////

gotConnection oracle.jdbc.driver.OracleConnection@1050e1f
compressedContents:46
zis contents 35
zis contents 1
entry null
Exception in thread "main" java.lang.NullPointerException

i am gettin exception at this point.

while ((entry = zis.getNextEntry()) != null)

it is showing nuul for entry. but there are contents in the ZipInputStream.please refer the output.

Can anybody please provide me a solution.

Thanks,
Ramkumar
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!