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

Similar Messages

  • No manifiest section for signature file entry net/sf/acegisecurity/LockedE

    Hi,
    I am facing one problem when I try to execute jar file.
    Our requirement is to generate one jar file which will run our product. We have some dependent jarfiles like j2ee.jar, log4J.jar Spring.jar etc��
    I extracted all the above mentioned jars in to one common folder along with my code and created the new jar file. This new jar file have MANIFIST file with Main-Class: com.fmr.dcl.Cds.DclUi
    When I try to run new jar file on commandprompt (java -jar NewJar.jar) I am getting some security Exception.
    Exception in thread "main" java.lang.SecurityException: no manifiest section for signature file entry net/sf/acegisecurity/LockedException.class
    at sun.security.util.SignatureFileVerifier.verifySection(Unknown Source)
    at sun.security.util.SignatureFileVerifier.process0(Unknown Source)
    at sun.security.util.SignatureFileVerifier.process(Unknown Source)
    at java.util.jar.JarVerifier.processEntry(Unknown Source)
    at java.util.jar.JarVerifier.update(Unknown Source)
    at java.util.jar.JarFile.initializeVerifier(Unknown Source)
    at java.util.jar.JarFile.getInputStream(Unknown Source)
    at sun.misc.URLClassPath$5.getInputStream(Unknown Source)
    at sun.misc.Resource.getBytes(Unknown Source)
    at java.net.URLClassLoader.defineClass(Unknown Source)
    at java.net.URLClassLoader.access$100(Unknown Source)
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClassInternal(Unknown Source)
    Ashok

    his link contains tools for jar and signiture, maybe it helps
    http://www.syncedit.com/jedit_details.html
    it is very interesting

  • Set the password for zip file in unix

    Hi All,
    I have used the below command to zip the file and it is working fine.
    cd /YYYY;zip -r ZZZZ.zip ZZZZ.TXT
    While using the below command to set the password on zip file , I am getting error like "zip error: Invalid command arguments (encryption not supported)
    zip -P password -r ZZZZ.zip ZZZZ.TXT
    Can you please help me how to set the password for zip file in UNIX.
    Thanks,

    Do you use any characters in the password that might confuse the zip command? (like '-' or ';'?)
    If I use the command in RHEL4:
    cd /tmp
    zip -P password -r tt.zip gconfd-oracle
    adding: gconfd-oracle/ (stored 0%)
    adding: gconfd-oracle/lock/ (stored 0%)
    adding: gconfd-oracle/lock/ior (deflated 67%)

  • APEX Dicom Sample zip file is corrupt.

    The File dicom-1-133417.zip of DICOM samples in APEX packed applications is CORRUPT!
    This is the page (DICOM sample)
    http://www.oracle.com/technetwork/developer-tools/apex/application-express/packaged-apps-090453.html#DICOM
    Please , somebody from oracle can fix it? we are trying to make a presentation with 11gr2 and DICOM features, but without this we have to make all from scratch. Please help!.

    Zip file gets corrupt or damage due to malware infections, virus interruption, power failed and system suddenly shut-down etc. But you can get rid from corrupted errors of Zip files through: - ZIP Viewer Tool
    http://www.zip.viewertool.com/
    just read the details here:http://www.filerepairforum.com/forum/archives/archives-aa/winzip/1140-how-open-open-archive-without-winrar-or-7zip

  • JDeveloper Studio 10.1.3 zip file is corrupted

    Downloaded JDeveloper Studio 10.1.3 half dozen time over last week, but all downloaded zip file were corrupted. Has anyone got a good download? Or is there another mirror site I can grab the file from?
    Thanks!
    James

    The link I downloaded the file from:
    http://download.oracle.com/otn/java/jdeveloper/1013/jdevstudio1013.zip
    The file size after I download it:
    Size: 325 MB (341,247,683 bytes)
    Size on disk: 325 MB (341,250,048 bytes)
    Thanks,
    James

  • Best free / cheap software for zipping files?

    Is there any free / cheap software recommended for zipping files that works well with a Mac?

    OS X includes an utility to compress and decompress ZIP files. It's called "Archive Utility" and it's stored on /System/Library/CoreServices, but you have to modify some settings.
    To access to this utility, open a Finder window, select Go menu (on the menu bar) > Go to Folder, and type /System/Library/CoreServices. Then, open "Archive Utility".
    By default, this app compresses files in a CPGZ file, but you can modify this. Go to Archive Utility menu (on the menu bar) > Preferences, and choose "Zip archive" next to "Use archive format".
    Then, to compress files, just close the Preferences window, and go to File menu (on the menu bar) > Create Archive. Finally, choose with the Command key the files you want to compress, and press "Archive", so a ZIP file will be created

  • "no manifiest section for signature file entry" when run the Jar file

    I built an application by using JBuilder 8.0 and it works fine. But when I deploy it into a jar file, whenever I run it, the following exception appears:
    Exception in thread "main" java.lang.SecurityException: no manifiest section for signature file entry javax/security/cert/Certificate.class
    at sun.securtiy.util.SignatureFileVerifier.verifySection
    Because I didn't do anything about the security when build the application. I am really confused. Can somebody help?

    I had a similiar problem using NetBeans. There must be a way to view the properties of your jar from Jbuilder and set its manifest. I am very new to this myself, but all I did was edit another manifest and copied into mine. Here is my example manifest:
    Manifest-Version: 1.0
    Main-Class: J3Ed
    The first line is the default line for a manifest. It is very simple and there is much more that could be added, but is not always necessary. I recommend reading the documentation :
    http://developer.java.sun.com/developer/Books/javaprogramming/JAR/basics/manifest.html
    Also if you have an archiving utility such as powerarchiver or winzip, open your JAR and check to see that you have a MANIFEST.MF file. If you do then edit it where needed, if not create one and its relative location should be set to META-INF/MANIFEST.MF.
    Hope this helps.

  • No manifiest section for signature file entry iaik/utils/IaikSecurity.class

    Why I got this exception when running my jar with:
    java -jar My.jar
    Exception:
    Exception in thread "main" java.lang.SecurityException: no manifiest section for signature file entry iaik/utils/IaikSecurity.class
    at sun.security.util.SignatureFileVerifier.verifySection(SignatureFileVerifier.java:260)
    at sun.security.util.SignatureFileVerifier.process(SignatureFileVerifier.java:172)
    at java.util.jar.JarVerifier.processEntry(JarVerifier.java:239)
    at java.util.jar.JarVerifier.update(JarVerifier.java:194)
    at java.util.jar.JarFile.initializeVerifier(JarFile.java:300)
    at java.util.jar.JarFile.getInputStream(JarFile.java:362)
    at sun.misc.URLClassPath$5.getInputStream(URLClassPath.java:616)
    at sun.misc.Resource.getBytes(Resource.java:57)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:248)
    at java.net.URLClassLoader.access$100(URLClassLoader.java:55)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:194)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:187)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:289)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:274)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:235)
    at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:302)

    his link contains tools for jar and signiture, maybe it helps
    http://www.syncedit.com/jedit_details.html
    it is very interesting

  • Error while reading file entries from the database

    Hi there,
    We are running a instance of xmii 12 in a VM (VMware) and after somebody shutdown the host machine without shutting down the VM (great idea isn't it?) we keep getting this message when trying to access xMII:
    "Application cannot be started.
      Details:   com.sap.engine.services.deploy.container.ExceptionInfo: Error while reading file entries from the database."
    Any clue? Any suggestion on how we can recover from that?
    Thanks a whole lot,
    Dom
    Server log:
    #1.5 #000C29A3B1F20002000000C400000F2800044829A35270F8#1205243578005#/System/Server##com.sap.engine.services.dbpool.deploy.ContainerImpl####n/a##60152160ef7211dcb7a5000c29a3b1f2#SAPEngine_System_Thread[impl:5]_17##0#0#Info#1#com.sap.engine.services.dbpool.deploy.ContainerImpl#Plain###DataSources or DataSource aliases of 'sap.com/tcmonitoringsysteminfo' application started successfully.#
    #1.5 #000C29A3B1F20002000000C500000F2800044829A3527A6C#1205243578005#/System/Server##com.sap.engine.services.servlets_jsp.server.container.WebContainer####n/a##60152160ef7211dcb7a5000c29a3b1f2#SAPEngine_System_Thread[impl:5]_17##0#0#Info#1#com.sap.engine.services.servlets_jsp.server.container.WebContainer#Plain###application [] Start of application [sap.com/tcmonitoringsysteminfo] finished successfully on Web Container.#
    #1.5 #000C29A3B1F20002000000C600000F2800044829A3527DB5#1205243578005#/System/Server##com.sap.engine.services.deploy####n/a##60152160ef7211dcb7a5000c29a3b1f2#SAPEngine_System_Thread[impl:5]_17##0#0#Info#1#com.sap.engine.services.deploy#Plain###
    Operation startApp over application sap.com/tcmonitoringsysteminfo finished successfully on server 305221750#
    #1.5 #000C29A3B1F20002000000C700000F2800044829A3527E03#1205243578005#/System/Server##com.sap.engine.services.deploy####n/a##60152160ef7211dcb7a5000c29a3b1f2#SAPEngine_System_Thread[impl:5]_17##0#0#Info#1#com.sap.engine.services.deploy#Plain###
    Operation startApp on application sap.com/tcmonitoringsysteminfo finished on current cluster node for 221 ms.#
    #1.5 #000C29A3B1F20002000000C800000F2800044829A3528B49#1205243578005#/System/Server##com.sap.engine.services.deploy####n/a##60152160ef7211dcb7a5000c29a3b1f2#SAPEngine_System_Thread[impl:5]_17##0#0#Error#1#com.sap.engine.services.deploy#Plain###Error occurred while initially starting application sap.com/xappsxmiiear:Error while reading file entries from the database.#
    #1.5 #000C29A3B1F20002000000CA00000F2800044829A352922B#1205243578015#/System/Server##com.sap.engine.services.deploy####n/a##60152160ef7211dcb7a5000c29a3b1f2#SAPEngine_System_Thread[impl:5]_17##0#0#Info#1#com.sap.engine.services.deploy#Plain###The synchronization of applications with DB completed for 39304 ms.#
    #1.5 #000C29A3B1F200040000000200000F2800044829B290A4F8#1205243834341#/System/Server/SLDService##com.sap.sldserv.DataCollector####n/a##0da42150ef7311dcb908000c29a3b1f2#SAPEngine_System_Thread[impl:5]_7##0#0#Warning#1#com.sap.sldserv.DataCollector#Plain###Communication configuration is incomplete. No data transfer possible until corrected.#

    Well thanks for the hint. Actually, the DB was up but corrupted. I managed to solve the bug by re-deploying xMII (using the SDM tool) which kept all my data but redeployed both the config db of (x)mii and the class files.

  • When i double click itunes it doesn't open it just comes up with an error saying " The itunes library.itl file cannot be found or created. The default location for this file is in the 'itunes' folder in the 'music' folder". How can i fix this?

    When i double click itunes it doesn't open it just comes up with an error saying " The itunes library.itl file cannot be found or created. The default location for this file is in the 'itunes' folder in the 'music' folder. How can i fix this problem?

    Anyone can help to advice how to solve this issue ?

  • I have 3 older ext. hard drives that I've utilized many times. Today while searching for old files, one of the three is no longer recognized by my PowerMac.  Any suggestions?

    I have 3 older ext. hard drives that I've utilized many times. Today while searching for old files, one of the three is no longer recognized by my PowerMac. The drive is not listed in Disk Utility.  Any suggestions?

    Is the computer in you equipment line:
    Dual Core Intel Xenon
    (which is not a PowerMac but a Mac Pro) the one you are asking about, or do you have an older PowerMac?
    If a Mac Pro, their forums are here:
    Mac Pro
    and, as Mac Pros have a totally different architecture from the pre-2005 Macs this forum covers, you may not have the same issues that can affect the older models. If someone didn't notice your equipment line, you could get advice that doesn't apply.
    If you really have a pre-2005 PowerMac, read on.
    If the stubborn external is USB and does not have its own power brick (i.e., it gets power only from the computer's UBS ports--"bus powered"), it may not be getting enough power. As electric motors age, they can demand more power than when new, and the power available on any USB port is limited.
    The typical workabouts to making a computer recognize an aging, bus-powered USB drive are:
    Get a powered USB hub (has its own power brick
    Get a "Y" USB cable: 1 Meter USB 2.0 A to 5 Pin Mini B Cable - Auxiliary USB "Y" Power Design for external hard drives.
    The second gets power from two USB ports on the computer and often that's enough.
    Remember that the USB ports on your keyboard seldom provide enough power even for a thumb drive, so be sure to use the USB ports on the back of the computer.

  • I just upgraded my mac book to 10.6.8 and downloaded the new version of itunes. When I try to open it and error message appears saying, "The iTunes Library file cannot be found or created. The default location for this file is in the "iTunes" folder.

    I just upgraded my mac book to 10.6.8 and downloaded the new version of itunes. When I try to open it and error message appears saying, "The iTunes Library file cannot be found or created. The default location for this file is in the "iTunes" folder in the "Music" folder."
    I have tried a few things but iTunes closes right after i click okay. Anyone know anything?

    Look in your Home > Music folder.  There should be an iTunes folder there and it should have a number of files and folders including one called library.itl  You want to guide iTunes to that file.  If you don't see that file or folder then in your next post you will have to be very specific as to what you do see or how you have your iTunes set up because that's where it should be according to default settings.

  • I need help every time my iTunes library updates i get this error messege: The iTunes.itl file cannot be found or created. The default location for this file is in the "iTunes" folder in the "Music" folder. but the file should be there.

    Every time I have to upgrade iTunes it gives me this messege:'The default location for this file is in the "iTunes" folder in the "Music" folder.' the file should be there but I don't understand why it does this every time Apple upgrades the Itunes library. Its on the computer somewhere but it only affects this login on my computer (meaning on this Windows Account). Why does my iTunes do this? Then I have to spend hours placing all my libraries back together and all my music back into the library. Which usually takes me a few days to sort all out. What is wrong with my iTunes? The iTunes folder is a folder in my Music folder where I store the iTunes music/files/libraries at on my computer so I can have all of the iTunes files in one place on my computer.

    I have a Windows 7 operating system my computer runs from.

  • Itunes library.itl file cannot be found or created. The default location for this file is in the "iTunes" folder in the "Music" folder

    itunes library.itl file cannot be found or created. The default location for this file is in the "iTunes" folder in the "Music" folder, I keep getting this message everytime I try to install Itunes after having to remove windows 8.1 and go back to windows 8.  I have uninstalled and reinstalled and it keeps telling me the same thing. What do I do?

    Hi Renee31,
    If you are having issues with the library.itl file in iTunes, you may find the following articles helpful:
    iTunes: What are the iTunes library files?
    http://support.apple.com/kb/ht1660
    Apple Support: Removing and reinstalling iTunes and other software components for Windows Vista, Windows 7, or Windows 8
    http://support.apple.com/kb/HT1923
    Regards,
    - Brenden

  • TS1717 iTunes will not open.  I get a message that says, "The iTunes Library.itl file cannot be found or created.  The default location for this file is in the "iTunes" folder in the music folder."  How can I fixt this?

    iTunes will not open.  I get a message that says, "The iTunes Library.itl file cannot be found or created.  The default location for this file is in the "iTunes" folder in the music folder".  How can I fix this?

    Hi pgarard1,
    If you are having issues with launching iTunes after an update, you may want to take a look at the troubleshooting in the following article:
    iTunes for Windows: Doesn't open after upgrading in Windows Vista or Windows 7
    http://support.apple.com/kb/TS2363
    Regards,
    - Brenden

Maybe you are looking for