Adding image to a zip file

Hi all,
I am trying to work out a servlet that creates an on-the-fly zip file. I am trying to add an image in this zip file and then I want to prompt user to download the created zip file. It is creating the zip file -it prompts the user and downloads the zip file... but when I open the downloaded zip file -the image is not found to be added in it. Please help, here is the code:
package servlets;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.util.zip.*;
import java.net.*;
import java.util.*;
public class CreateZipFile extends HttpServlet {
     byte b[] = new byte[300000];
     ByteArrayOutputStream bout = new ByteArrayOutputStream();
     ZipOutputStream zout = null;
     ServletOutputStream out = null;
     ServletContext servletContext = null;
     HttpServletResponse res=null;
     public void doGet (HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException
          this.res=res;
          out=res.getOutputStream();
          servletContext=getServletContext();
          File f= new File(getServletContext().getRealPath(req.getContextPath()));
          String fs = System.getProperty("file.separator");
          addToZip_Image (f.getParentFile() + fs + ("images/thermorack.jpg"));
          System.out.println("ready");
          String zip = bout.toString();
          res.setContentType("application/zip");
          res.setHeader("Content-Disposition", "inline; filename=output_dd.zip;");
          System.out.println("finished");
          out.println(zip);
          out.flush();
     public void addToZip_Image(String img) throws ServletException, IOException
          System.out.println("image=" + img);
               try {
                    FileInputStream input = new FileInputStream(img);
                    zout = new ZipOutputStream(new FileOutputStream(img));
                    zout.putNextEntry(new ZipEntry("image.jpg"));
                    int len;
                    while ((len = input.read(b)) > 0) {
                    zout.write(b, 0, len);
                    zout.closeEntry();
                    zout.close();
                    input.close();
                    System.out.println("closed");                    
               } catch (Exception e) {
                    System.out.println("Exception occurred");
                    res.setContentType("text/html");
                    out.println("<html><head><title>Error</title></head>");
                    out.println("<body><b>");
                    out.println("An error has occured while processing "
                              + "<br>");
                    out.println("Here is the exception: <br>" + e + "<br>");
                    e.printStackTrace(new PrintWriter(out));
                    out.println("</body>");
                    out.println("</html>");
}

You would need to purchase Stuffit Standard:
http://my.smithmicro.com/mac/stuffit/index.html

Similar Messages

  • Image Capture creating zip files instead of regular files

    I've been using Image Capture for many years. For some reason, all of a sudden, all my scans are being put into a zip file instead of as a regular file. I'd like to have Image Capture make regular files again such as pdf etc.  What do I do?
    Does this have anything to do with going to OS Yosemite 10.10?

    Hi
    appzapper & such are pretty flaky at removing things usefully, imo.
    Use the uninstaller for speed download - http://www.yazsoft.com/products/speed-download/faqs/?how-to-un-install-speed-dow nload-properly
    or get a hold of FindAnyFile or easyfind & search for Growl & Speeddownload & yazsoft - but from all I hear, the uninstaller works fine.
    Failing that, Safari's settings plist file isn't in caches
    Home/Library/Preferences/com.apple.safari.plist
    is the place
    & if you're still stuck, test & maybe download another browser using a New User Account.

  • Adding Image in Report RDF file

    Hi Friends
    Using Form and report 6
    I want to takeout the report in oracle, Report is generating good, with the same time i want to add company's logo on the report so everytime while taking out the report logo should also print.
    Please suggest the best solution it is urgent...
    sanjay

    Report is generating goodThen you should not have problem to generate RDF file. Images are kept in RDF or PDF output.

  • Mail Distorts & Corrupts Files (images, PDF's .zips)

    Hello,
    I constantly send images, PDF's, .zip files using Mac Mail and the receiving party usually reports that the images are distorted, PDF's cannot be opened and .Zip files are corrupt. What can I do?

    firstly - is the receiving party using a mac or windows box?
    If windows - are you checking the "send windows friendly attachments" box?.
    You can make this the default setting in Mail - Edit - Attachments - always send windows friendly attachments. There should be a check mark next to it.
    If another mac user - are they using apple's Mail app, or some other one?
    If you send an email to yourself - do the images/pdf's/zips come through as normal?

  • ByteArrayInputStream as source for zip file entry corrupts the ByteArray

    Hi All,
    I have managed to create and add a (in-memory) zip file as an email attachment. I add a file to the zip file , then push data to this file via a ByteArrayInputStream.
    Adding the file (created via ByteArrayInputStream) to an email works perfectly. If i then add another step and zip this file it corrupts the output.
    It looks like it is turning the carriage return into a [] . Its 'almost right' as when I cut & paste the contents of the txt file i created (from the zip file) into Word it displays correctly, with the carriage returns. Is it some kind of encoding problem, or mime type issue?
    My ByteArrayInputStream uses buf.append("\n"); for carriage returns. I think the problem is with
    ByteArrayInputStream baIn = new  ByteArrayInputStream( getAttachementNoFormat(eq_rt.getStoredProc()) );where I think i need to encode this somehow. Here is the complete code to create and add the zip file to an email. Any isuggestions will be appreciated.
    //START of new ZIP code    
                                                                                             /* Specify files to be zipped */
                                                                                            // Create temp file.
                                                                                            //File temp = File.createTempFile(fileName, ".txt");                           
                                                                                            //temp.deleteOnExit();                                                           
                                                                                            //BufferedWriter bOut = new BufferedWriter(new FileWriter(temp));                                                          
                                                                                            //ByteArrayInputStream baInTemp = new ByteArrayInputStream( getAttachementNoFormat(eq_rt.getStoredProc() ) );
                                                                                            //bOut.write( baInTemp.toString() );
                                                                                            //bOut.close();
                                                                                             String[] filesToZip = new String[3];
                                                                                             filesToZip[0] = "C:\\Program Files\\NetBeans3.6\\firstfile.txt";
                                                                                             filesToZip[1] = "C:\\Program Files\\NetBeans3.6\\secondfile.txt";
                                                                                             filesToZip[2] = "C:\\Program Files\\NetBeans3.6\\thirdfile.txt";
                                                                                             final String fileToZip = fileName;
                                                                                             /*  Create a memory buffer to store the ByteArray, fixed size */                                                         
                                                                                             byte[] buffer = new byte[18024];
                                                                                             /* Specify zip file name */
                                                                                             String zipFileName= eq_rt.getReportName() + ".zip";
                                                                                             try {
                                                                                                 /* Create ZipOutputStream to store the FileOutputStream */
                                                                                                 // ZipOutputStream out = new ZipOutputStream(new FileOutputStream(zipFileName));
                                                                                                 ByteArrayOutputStream byteArray = new ByteArrayOutputStream();                                                             
                                                                                                 ZipOutputStream out = new ZipOutputStream(byteArray);                                                              
                                                                                                 /* Set the compression ratio */
                                                                                                 out.setLevel(Deflater.DEFAULT_COMPRESSION);
                                                                                                 /* iterate through the array of files, adding each to the zip file */
                                                                                                 for (int a = 0; a < filesToZip.length; a++) {
                                                                                                    /* Print the filenumber being added to the zip */
                                                                                                    System.out.println(a);
                                                                                                    /* Associate a file input stream for the current file */
                                                                                                   // FileInputStream in = new FileInputStream(filesToZip[a]);
                                                                                                       This ROCKS as it is passing a array into the text file .getBytes() seems
                                                                                                       to be the KEY in getting ByteArrayInputStream to WORK
                                                                                                    //String strSocketInput = "TAIWAN";
                                                                                                    //ByteArrayInputStream baIn = new ByteArrayInputStream(strSocketInput.getBytes());
                                                                                                    //String strSocketInput = new String (getAttachementNoFormat(eq_rt.getStoredProc()).toString() );                                                                                           
                                                                                                    //ByteArrayInputStream baIn = new ByteArrayInputStream( getAttachementNoFormat(eq_rt.getStoredProc()) );
                                                                                                     ByteArrayInputStream baIn = new  ByteArrayInputStream( getAttachementNoFormat(eq_rt.getStoredProc()) );
                                                                                                    //String strSocketInput = "TAIWAN";
                                                                                                    //ByteArrayInputStream baIn = new ByteArrayInputStream(strSocketInput.getBytes());
                                                                                                    /* Add ZIP entry to output stream. */                                                   
                                                                                                    out.putNextEntry(new ZipEntry(filesToZip[a]));                                                  
                                                                                                    /* Transfer bytes from the current file to the ZIP file */
                                                                                                    int len;
                                                                                                    while ((len = baIn.read(buffer)) > 0)
                                                                                                    out.write(buffer, 0, len);
                                                                                                    /* Close the current entry */
                                                                                                    out.closeEntry();
                                                                                                    /* Close the current file input stream */
                                                                                                    baIn.close();                                                   
                                                                                                /* Close the ZipOutPutStream (very important to close the zip before you attach it to the email) Thanks DrClap */
                                                                                                out.close();                                                    
                                                                                                /* Create a datasource for email attachment */
                                                                                                // DataSource sourcezip = new FileDataSource(zipFileName);
                                                                                                DataSource sourcezip = new ByteArrayDataSource(byteArray.toByteArray(), zipFileName, "application/gzip" );
                                                                                                /* Create a new MIME bodypart */
                                                                                                BodyPart attachment = new MimeBodyPart();
                                                                                                attachment.setDataHandler(new DataHandler(sourcezip));
                                                                                                attachment.setFileName(zipFileName);                       
                                                                                                /* attach the attachemnts to the mail */
                                                                                                multipart.addBodyPart(attachment);                                                       
                                                                                             catch (IllegalArgumentException iae) {
                                                                                               iae.printStackTrace();
                                                                                             catch (FileNotFoundException fnfe) {
                                                                                               fnfe.printStackTrace();
                                                                                             catch (IOException ioe)
                                                                                             ioe.printStackTrace();
                                                                                           // End Of New ZIP code    

    I came up with 'a' solution (not sure if its the best way but appears to work)
    \n = corrupt
    \r\n = ok in zip

  • I am trying to organize a zip file with a bunch of links and files. But when I drag an image file to a folder, it always "Snaps to grid" instead of just landing where I put it.

    I am trying to organize a zip file with a bunch of links and files. But when I drag an image file to a folder, it always "Snaps to grid" instead of just landing where I put it. All of the files are going into the same zip file but I want them visually in the space that I put them and not at the bottom of the snap to grid folder location they are looking like.  I am trying to  drag and drop files in groups so that I can group them for now, but image files always do their own "sort by" when I drag them from my web pages. Links don't do it though.  I tried resetting the folder, and deleting the DS files. No luck.

    You keep asking variants on this same question. You've had replies in all your other threads. If you can't find them, go here and click where it says Activity:
    Thomas Cannon Jr.

  • Adding zip file to classpath or -Xbootclasspath on J9

    Hi,
    I'm trying to add a zip file containing javax classes (jscience-vm14.zip) to the classpath when running my program. I haven't had any problems adding jar files for instance, but I can't seem to have this zip file included so that it can be recognized by the jvm.
    I've noticed in the installation document of the J9 that if you want to add javax classes it has to be put on the -Xbootclasspath. So I've tried including the zip file using -Xbootclasspath/p:path/to/zipfile/zipfile.zip and I've tried -Xbootclasspath/a:path/to/zipfile/zipfile.zip. I've also tried just including it in the classpath with no luck either. I keep getting a NoClassDefFoundError: javax.units.Unit which is part of the jscience package
    Any ideas how to get the zip file included?
    Kind regards
    Simon

    Hi,
    Thank you for your answer!
    I'm using SWT and here's the code:
    lstBread.addListener (SWT.Selection, new Listener () {
                   public void handleEvent (Event e) {
                   System.out.println("Widget selected!");
    It's working wtihout error on win32 platform. But there is no call on Windows Mobile 5.0 platform. It doesn't run and no exception is throwed on J9 console.
    However, when i use the same way for event handling in SWT Button, there is no problem both on WM5 and win32 platform. It's executed as i want.
    The code for SWT Button:
    btnSView.addListener (SWT.Selection, new Listener () {
                   public void handleEvent (Event e) {
         System.out.println("Widget selected!");     
    I couldn't find the reason of that. Why doesn't the list#addListener run on WMobile?
    Best Regards,
    Ceyhun Hallac

  • How to read ZIP files(having PDFs,Image) using MQ Series link for R/3

    Hi,
    1)Is it possible to transfer a zip file (having an image or pdf) using IDocs in SAP 4.6C using MQ Series link for R/?
    Scenario: "MQ Series link for R/3" converts Business-Reports from a third-party software,into SAP IDocs.Each Business-Report contains one XML file and one ZIP file.
    2)Being on ABAP side,do I have to worry about how the zip file would be converted into IDocs?
    Detailed descrption:
    This scenario requires integration of a non-SAP software which talks in XML with SAP R/3(4.6C).The customer has decided to go with 'MQ Series link for R/3' (which integrates any non-SAP application running on IBM MQ Series to R/3,by converting data(in any format) into IDocs).He is not ready to go for XI.
    The Problem area is a functionality which requires the non-SAP software to send XML file along with an attached Zip file.So,XML document,basically,has a 'zippedFile' XML element having actual file in XML keyword 'file'.
    This XML document ideally, should be converted by the subsystem(MQSeries link for R/3) into IDocs i.e. into a stream which could be stored in a table on R/3 side and later, sent back to the non-SAP software through MQ Series link to be converted into zip-file again with corresponding pdfs,images.I want someone who has worked in a similar scenario to confirm this.

    Hi,
    I have a feeling I have posted this question in the wrong forum or maybe I will let you decide this.Any help would be appreciated (even the right forum name).
    My scenario requires integration of a non-SAP software which talks in XML with SAP R/3(4.6C).The customer has decided to go with 'MQ Series link for R/3' (which integrates any non-SAP application running on IBM MQ Series to R/3,by converting data(in any format) into IDocs).He is not ready to go for XI.
    The Problem area is a functionality which requires the non-SAP software to send XML file along with an attached Zip file.So,XML document,basically,has a 'zippedFile' XML element having actual file in XML keyword 'file'.
    This XML document ideally, should be converted by the subsystem(MQSeries link for R/3) into IDocs i.e. into a stream which could be stored in a table on R/3 side and later, sent back to the non-SAP software through MQ Series link to be converted into zip-file again with corresponding pdfs,images.I wanted someone who has worked in a similar scenario to confirm this.

  • Adding images to rows in a table depending on file type

    Hello,
    Within Visual Composer we have a table which lists documents and contains information about the document type
    i.e. description = 'This is a Word Document', file type = 'application/msword'
    then I have uploaded the images (icons) for the different file types, created a 'Document Type' column (of type image) in the table and assigned the correct boolean statements to determine which icons are shown
    e.g. BOOL(IF(@MIMETYPE == 'application/msword', true, false))
    This is the exact steps explained in the how to: How To… Integrate BI Document Store and SAP Analytics Applications
    But just does not work? It will not display the icons even though the file type (MIMETYPE) is displayed and is correct.
    Any help much appreciated!

    Seem to have fixed the problem.
    By adding a filter before the table view it seems to allow a slight delay which allows the file types to load and the IF statements run correctly and display the correct images for the various file types.
    Still seems that there is a slight Visual Composer Issue there? (but now with a work-around)

  • Website image and zip file download links not working in Dreamweaver Air application

    Hi
    I have successfully created and AIR app for an existing business website using the Dreamweaver AIR Extension. The site works very well in all respects except for the part where we have high resolution images and zip files available for download. The download links refuse to do anything, and right-click (PC) / ctl-click (Mac) does nto work either.
    I suspect this may be an AIR sandbox/security issue but am I correct and what can I do to fix it?
    Thanks in advance for any assistance you may be able to give.
    Martin

    I am now facing the same problem. I wrote a servlet .
    code like this
             response = (HttpServletResponse) faces.getExternalContext().getResponse();
             response.setContentType("application/x-download");
             String agent = request.getHeader("USER-AGENT");
             boolean isIE=false;            
            if (null != agent && agent.indexOf("MSIE")!=-1) { 
                isIE=true;
            if (isIE) {
                fileName = URLEncoder.encode(fileName, "UTF-8");
            } else {
                fileName = new String(fileName.getBytes("utf-8"), "ISO-8859-1");
            response.setHeader("Content-Disposition","attachment;filename="+fileName);
            ServletOutputStream os = response.getOutputStream();
            byte b[]=new byte[1024];
            int n;
            while((n=in.read(b))!=-1){
                os.write(b,0,n);
           in.close();
           os.close();
    and i open a new window refer to above jsp ,also i set a breakPoint at os.close(),the program has passed through,but nothing happened in the window.
    If i use IE or FF ,the browser will open a small window to allow me select whether open or  save the file.So can anybody give me some advice.Is it because air using webkit engine and the engine does not do this kind of job?
            Thanks.

  • Sending Downsized Images to Zip File Problems

    I use Adobe Elements 5.0 and have been uploading images to the organizer for a couple of years without problems, until just recently.  Here is how the process used to work.  When images are uploaded they are saved to a new file folder under C drive/ Public Photos/ specific folder with date and subject matter;  I fix the images in adobe then go to the specific folder and create a subfolder within that folder called "downsized".  I then use Adobe to "process multiple files" and downsize for purposes of sending to Pbase. Once the files have been downsized the images end up in the specifc folder, inside the downsized subfolder.  I then rt click and select "send to" 'compressed (zip) folder'.  From there I would open Pbase and upload the zipped folder to a new gallery.
    Recently everything has been fine until I get to the send to zip folder.  Instead of sending to the familiar yellow zip folder it is being sent to the adobe photoshop editor in the form of the adobe icon.  I click on that and it promts me for filename, width, height, resolution and color mode.  I am unable to upload this zipped file version to Pbase.  Previously, when things were operating correctly, I would have a folder, with a subfolder under that called downsized.  Within the downsized folder would be the zipped file for sending to Pbase.  Something has happened recently so that I am ending up with a folder, a subfolder called downsized a sub 'folder' under that which is the adobe elements icon and a downsized file under that which is a copy of the downzied photos in the first downsized file.  In checking out all of my 100 or so folders all of them have been 'converted" to the same organization pattern.  What has happened and how do I fix the problem so that I can send the downsized folder to a zip file for importing to Pbase?  Thank you. 

    You should realize I am just making wild guesses at your problem. And I am assuming you actually have a Microsoft Word document that you are sending. If you do, then following menu options "Insert, Picture, From File..." should work. But if you are just writing out HTML and telling the browser it's actually a Word document, I have no idea.

  • Ive gotten a zip file and i have no idea how to open it and view images

    ive gotten a zip file and i have no idea how to open it and view images?

    Double-click it in the Finder.
    (107691)

  • Making a zip file to upload images to PBASE

    I do have Mobile Me, but need to upload 200 images to PBase. I've tried this before and had problems. Can I create a zip file from Iphoto? or a .tar (don't know this type) If so, please tell me how. Thanks.

    First, have you tried iPhoto2PBase?
    http://newwavedigitalmedia.com/iPhoto2PBase.htm
    Second, if that is not acceptable, my guess is that you would have to do it in a two step process where you export the photos you want in pbase to your desktop (or where ever) then zip up those photos into a file to upload.
    Patrick

  • Adding images files to DVD-ROM

    By adding image files to the dvd-rom when burning my slideshow and movie. Can the photos be put on a desktop for printing after burn is done?

    There's a nice option to add whatever files you choose to the DVD-ROM area using the command to Edit DVD-ROM. Here are instructions:
    http://docs.info.apple.com/article.html?path=iDVD/7.0/en/6693.html
    and a related thread:
    http://discussions.apple.com/thread.jspa?threadID=2136021
    John

  • Adding a file into existing zip file

    I need a add a file into existing zip file. and write into printwriter.
    How to do it?
    Waiting for the reply.
    Thanks and Regards,
    Narayanan. G

    Narayanan.G wrote:
    I need a add a file into existing zip file.API: [ZipOutputStream#putNextEntry()|http://java.sun.com/javase/6/docs/api/java/util/zip/ZipOutputStream.html#putNextEntry%28java.util.zip.ZipEntry%29]
    Tutorial: [http://java.sun.com/developer/technicalArticles/Programming/compression/].
    and write into printwriter.Writing a zip file into printwriter? Huh? Please elaborate.

Maybe you are looking for

  • Maximum number of allowed pages in Pivot Table exceeded Configured Limit:

    When trying to create Calculated Item on Pivot table Page section Item like Division dim the calculated item is 'All' -> sum * and Customer again the calculated item is 'All -> sum * . it performs the first calculation (for division) but in the next

  • How to add 'Confidential' watermark to all the pages in portal

    Hi How to add 'Confidential' watermark to all the pages in portal.We have ESS/MSS business packages installed 60.1, 60.2. ECC5, EP SP16 is the environment. Help will be appreciated Thanks Sharath

  • Can older G5 IMacs be upgraded to giagbit ethernet

    We're moving our office and having new Categroy 6 cable pulled. Also buying a couple more G5 iMacs (isight) with gigabit ethernet capabilities. Can my older machines be upgraded to to support 10/100/1000? Thanks for any insights you may have. G5 iMac

  • Store a txt file in war

    Can i include a file.txt in war package and read it from servlet classes post deployment? I thow, but the jboss generate the error: file not found. What is the correct path specification?

  • BrowserLab problems - used to work, can no longer connect now

    I was using Browser Lab thru Dreamweaver CS5.5 (v11.5, build 5344) with no problems whatsoever until recently. For no apparent reason, it stopped working. Now when I try to connect, I just get that "preparing for preview..." progress bar that never g