Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 2nd, 2012  |  syntax: None  |  size: 1.32 KB  |  hits: 19  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Unable to zip multiple files using Java
  2. inputStream = AWSFileUtil.getInputStream(
  3.                     AWSConnectionUtil.getS3Object(null),
  4.                     "cdn.generalsentiment.com", filePath);
  5.        
  6. ByteArrayInputStream byteArrayInputStream = new    
  7. ByteArrayInputStream(inputStream.toString().getBytes());
  8.             while (byteArrayInputStream.read(inputStream.toString().getBytes()) > 0) {
  9.                 zipOutputStream.write(inputStream.toString().getBytes());
  10.             }
  11.        
  12. zipOutputStream.close();
  13.         ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
  14.         fileInputStream = new FileInputStream(file);
  15.         while (fileInputStream.read(buffer) > 0) {
  16.             byteArrayOutputStream.write(buffer);
  17.         }
  18.         byteArrayOutputStream.close();
  19.         inputStream = new ByteArrayInputStream(byteArrayOutputStream.toByteArray());
  20.         reportName = "GS_MediaValue_Reports.zip";
  21.         fileType = "zip";
  22.     }
  23.  
  24.     return fileType;
  25.        
  26. ZipEntry entry = new ZipEntry( fileName ); // You have to give each entry a different filename
  27. zipOutputStream.putNextEntry( entry );
  28. byte buffer[] = new byte[ 1024 ]; // 1024 is the buffer size here, but it could be anything really
  29. int count;
  30. while( (count = inputStream.read( buffer, 0, 1024 ) ) != -1 ) {
  31.     zipOutputStream.write( buffer, 0, count );
  32. }