Zip Utils (unzip problem )

Hi,
I have a problem with the ZIP, so i an array of bytes ziped in my database without problem,but after when i try
to extract this information i must to unziped it , the problem is that the unzip method replace the char "�" by
another char that cause a not well formedness of my xml file produced .
So if there is any solution to resolve this problem .
Thanks.

public static byte[] zip(byte[] input) throws IOException {
// Create the compressor with highest level of compression
Deflater compressor = new Deflater();
compressor.setLevel(Deflater.BEST_COMPRESSION);
// Give the compressor the data to compress
compressor.setInput(input);
compressor.finish();
// Create an expandable byte array to hold the compressed data.
// You cannot use an array that's the same size as the orginal because
// there is no guarantee that the compressed data will be smaller than
// the uncompressed data.
ByteArrayOutputStream bos = new ByteArrayOutputStream(input.length);
// Compress the data
byte[] buf = new byte[BUFFER];
while (!compressor.finished()) {
int count = compressor.deflate(buf);
bos.write(buf, 0, count);
try {
bos.close();
} catch (IOException e) {
// Get the compressed data
return bos.toByteArray();
public static byte[] unzip(byte[] compressedData) throws IOException {
// Create the decompressor and give it the data to compress
Inflater decompressor = new Inflater();
decompressor.setInput(compressedData);
// Create an expandable byte array to hold the decompressed data
ByteArrayOutputStream bos = new ByteArrayOutputStream(compressedData.length);
// Decompress the data
byte[] buf = new byte[BUFFER];
while (!decompressor.finished()) {
try {
int count = decompressor.inflate(buf);
bos.write(buf, 0, count);
} catch (DataFormatException e) {
try {
bos.close();
} catch (IOException e) {
// Get the decompressed data
return bos.toByteArray();

Similar Messages

  • Help:how to use java.util.jar to zip or unzip a binary file.

    how to use java.util.jar to zip or unzip a binary file or a file contain native code.

    It may help you to know how I add JARs
    1. I open my Project (myProject)
    2. I Mount the JAR to the FileSystem (like mypackages.jar = which includes com.mus.de.myClass.java)
    3. I Mount the File to the FileSystem (like c:\..myfiles..\myProject)
    3.1 I add the File to my Project
    4. I select File | New -> Classes | Main
    4.1 I typed "import com.mus.de.myClass.java" to refer to this package.
    4.2 I called some of the public methods
    thats it
    Andreas

  • Third party component for zipping and unzipping using password

    Hi EveryBody
    I am working on a project wherein i have to zip and unzip a file using password .I downloaded a java component ,but was unable to efficiently unzip my zip files using password.
    Can any body suggest me a java library/component that will accept a file and do zipping and unzipping with a password.
    I will also be really grateful ,if somebody suggest me a component that would do the same above functionality using Streams.
    Eagerly waiting for your replies ASAP.
    --Kiran                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

    HI
    I am also facing the same sort of problem. Could any body please give some solution for this.
    Ravi

  • Zipping  and Unzipping Directories and files both - URGENT PLEASE

    Hi friend,
    I tried for zipping and unzipping but it is not working still.
    and have to submit project tomorrow.
    so please as possible as fast just send me the source code that zip the file/folder and unzip in the same way as it was stored.
    ex : if we zip file c:/temp/myfolder/myfile.ppt to .zip
    unzip should c:/temp/myfolder/myfile.ppt
    thanks
    ghanshyam
    9879152949

    I believe (although I don't want to put words in his mouth) that Madan has run across a similar problem that I am trying to solve.
    For instance if I have the following files:
    c:\pic1.gif
    c:\pic2.gif
    c:\pic3.gifand I zip them in to a file called: pics.zip the will unzip just fine.
    However, if I have them in a directory:
    c:\pics\pic1.gif
    c:\pics\pic2.gif
    c:\pics\pic3.gifA listing of the zip files (all using java of-course) will show the files and dirs correctly:
    \pics\pic1.gif
      \pics\pic2.gif
      \pics\pic3.gifbut will give the following error if you try to un-zip them:
    "The system cannot find the path specified"The ZipEntry class has an 'isDirectory()' method, but it only returns true in the case of an EMPTY directory. If , as in my example, there is an actual file at the end of the entry, it returns false.
    So, at least in my case, I would be looking for advice on how to expand files that reside in directories within the zip file.
    Thank You for any help you can provide

  • Hello, I am attempting to install Camera raw from a .zip file provided via a link provided by adobe for a Nikon D810. The .zip file unzips fine and I moved the files to the recommended folder. But the operation is failing

    I am attempting to install Camera raw from a .zip file provided via a link provided by adobe for a Nikon D810. The .zip file unzips fine and I moved the files to the recommended folder. But the operation is failing

    Can you describe what “the operation is failing” means?  What is happening and how is it different than what you expect?
    Also, what product are you trying to update manually, and do you have a link to the page of instructions, so we know what your attempting to do?

  • Zip or unzip a payload in sender JMS channel

    Hi,
    My scenario is to unzip a payload in sender JMS channel and I have configured the sender JMS module in the below format,
    Processing sequence
    AF_Modules/PayloadZipBean Local Enterprise Bean    Local Enterprise Bean       zip
    SAP XI JMS Adapter/ConvertJMSMessageToBinary     Local Enterprise Bean       convert_JMS2Bin
    SAP XI JMS Adapter/ConvertBinaryToXMBMessage     Local Enterprise Bean       convert_Bin2XI
    CallSapAdapter                                                         Local Enterprise Bean      call_AF_MS
    Module Configuration
    Modulekey            Parameter Name                    Parameter Value
    zip                        zip.mode                                unzip
    I have tried this format also,but it is not working
    SAP XI JMS Adapter/ConvertJMSMessageToBinary     Local Enterprise Bean       convert_JMS2Bin
    SAP XI JMS Adapter/ConvertBinaryToXMBMessage     Local Enterprise Bean       convert_Bin2XI
    AF_Modules/PayloadZipBean Local Enterprise Bean    Local Enterprise Bean       zip
    CallSapAdapter                                                         Local Enterprise Bean      call_AF_MS
    (or)
    SAP XI JMS Adapter/ConvertJMSMessageToBinary     Local Enterprise Bean       convert_JMS2Bin
    AF_Modules/PayloadZipBean Local Enterprise Bean    Local Enterprise Bean       zip
    SAP XI JMS Adapter/ConvertBinaryToXMBMessage     Local Enterprise Bean       convert_Bin2XI
    CallSapAdapter                                                         Local Enterprise Bean      call_AF_MS
    While performing testing,it throws the below error in sender JMS channel,
    The detailed error (if any) is :  com.sap.aii.adapter.jms.api.channel.filter.MessageFilterException: while trying to invoke the method java.lang.String.length() of a null object loaded from local variable pattern: NullPointerException: while trying to invoke the method java.lang.String.length() of a null object loaded from local variable 'pattern'at com.sap.aii.adapter.jms.core.channel.filter.TxManagerFilter.filterSend(TxManagerFilter.java:185)
    Can someone help me on how to extract a payload in sender JMS channel.
    Also please guide me on how to extract a multiple payloads in one zip file in sender JMS channel.

    Hi,
    Your module sequence seems to be incorrect.
    Try like this,
    SAP XI JMS Adapter/ConvertJMSMessageToBinary     Local Enterprise Bean       convert_JMS2Bin
    SAP XI JMS Adapter/ConvertBinaryToXMBMessage     Local Enterprise Bean       convert_Bin2XI
    AF_Modules/PayloadZipBean Local Enterprise Bean    Local Enterprise Bean       zip
    CallSapAdapter                                                         Local Enterprise Bean      call_AF_MS
    (or)
    SAP XI JMS Adapter/ConvertJMSMessageToBinary     Local Enterprise Bean       convert_JMS2Bin
    AF_Modules/PayloadZipBean Local Enterprise Bean    Local Enterprise Bean       zip
    SAP XI JMS Adapter/ConvertBinaryToXMBMessage     Local Enterprise Bean       convert_Bin2XI
    CallSapAdapter                                                         Local Enterprise Bean      call_AF_MS
    Regards,
    Praveen Gujjeti

  • Zip and Unzip files in PlayBook

    Hello all,
    Just a heads up, File Browser for PlayBook will shortly be getting an update that will allow the users to zip and unzip files. Network browsing is planned for the update after this one (free upgrade ofcourse). 
    Here is a link to the app: File Browser
    My apps: Offline Viewer and FlashLight

    that'd be great, I hope that the wait is worthy!

  • Zip utility

    hi i am new to java zip utility.
    i would like to know how to add a particular file residing in hard-disk to a zip file which is also in the hard-disk and store it as a zip file. please reply to this message or reply to my email id([email protected]).thank you.

    public class ZipIt {
         public static void main(String[] args) {
    //          These are the files to include in the ZIP file
         String[] filenames = new String[]{"C:\\projects\\testing\\testing\\test.txt"};
         // Create a buffer for reading the files
         byte[] buf = new byte[1024];
         try {
         // Create the ZIP file
         String outFilename = "outfile.zip";
         ZipOutputStream out = new ZipOutputStream(new FileOutputStream(outFilename));
         // Compress the files
         for (int i=0; i<filenames.length; i++) {
         FileInputStream in = new FileInputStream(filenames);
         // Add ZIP entry to output stream.
         out.putNextEntry(new ZipEntry(filenames[i]));
         // Transfer bytes from the file to the ZIP file
         int len;
         while ((len = in.read(buf)) > 0) {
         out.write(buf, 0, len);
         // Complete the entry
         out.closeEntry();
         in.close();
         // Complete the ZIP file
         out.close();
         } catch (IOException e) {

  • Problem in deleting Zip files unzipped using java.util.zip

    I have a static methos for unzipping a zip file. after unzipping the file when i am trying to delete that file using File.delete()its not getting deleted. but when methods like exist(). canRead(), canWrite() methods are returning true what can be the possible problem ? i had closed all the streams after unzipping operation Please go through the following code.
    public static boolean unzipZipFile(String dir_name, String zipFileName) {
    try {
    ZipFile zip = new ZipFile(zipFileName);
    Enumeration entries = zip.entries();
    while (entries.hasMoreElements()) {
    ZipEntry entry = (ZipEntry) entries.nextElement();
    // got all the zip entries here
    // now has to process all the files
    // first all directories
    // then all the files
    if (entry.isDirectory()) {
    // now the directories are created
    File buf=new File(dir_name,entry.getName());
    buf.mkdirs();
    continue;
    }// now got the dirs so process the files
    entries = zip.entries();
    while(entries.hasMoreElements()) {
    // now to process the files
    ZipEntry entry = (ZipEntry) entries.nextElement();
    if (!entry.isDirectory()){
    File buf=new File(dir_name,entry.getName());
    copyInputStream(
    zip.getInputStream(entry),
    new BufferedOutputStream(
    new FileOutputStream(buf)));}
    } catch (IOException e) {
    e.printStackTrace();
    return false;
    return true;
    now i am trying to call this method to unzip a zip file
    public static void main (String arg[]){
    unzipZipFile("C:/temp","C:/tmp.zip");
    java.io.File filer = new File("C:/tmp.zip");
    System.out.println (filer.canRead());
    System.out.println (filer.canWrite());
    System.out.println (filer.delete());
    Please tell me where my program is going wrong ?

    Thanks .. the problem is solved... i was not closing the Zip file .. rather i was trying to close all the other streams that i used for IO operaion ... thanks a lot

  • Unzip problem for psoracle816nt.zip (PO8i)

    i downloaded psoracle816nt.zip (Personal Oracle 8i) to install on my win2000 machine. when i tried to unzip the file with WinZip, it told me that the file may be corrupted and to dl it again. after i downloaded the file again, i encountered the same problem.
    does anyone know if winzip is the right unzip utility? Thanks, Jason.

    Hii Guys ,one more prb,
    I need to develop a file uploading utility in struts to upload ZIP files(only ZIP), and i sucseeded to do it using the commons.fileupload which comes along with the WSAD5.1(examples), but the prb is i need to chek for the MIME type and need to reject if its not a zip file, if i do this in actionclass, its waiting till the uploading process of the file is finished and finally its displaying file is not the a ZIP, i need to do this validation as the request comes to the server side, i cant not do this in clint side cause my design should not allow me to use any java script..so please let me know is there any way to specify in the controller it self .
    thanx in advance

  • Zip/unzip problem

    I have a problem unzipping Objects that i've zipped earlier.
    The situation is as follows:
    a RMI server zips a tree of Objects. The client side of the program tries to unzip the data and form it back to the Object (a DefaultMutableTreeNode) that is should be. However...
    The zip part goes without any problems. The unzipping however gives me a StreamCorruptedException.
    I have an object called ZipObject and it contains the size (int) of the zipped data and the size (int) of the uncompressed data. It also holds the data itself.
    my zip/unzip methods are as can be seen at:
    http://www.next-element.nl/~orchid/zip.html
    if anyone can help me...i'd be very grateful.
    thanx in advance.

    Oh yes i checked the ingoing and outgoing size of bytes...
    they are perfectly the same.
    The problem lies more in the in.readObject() method.
    when i dump the bytes that i receive to a File (which i do not want to do in the application) i can actually unzip it with unzip from my Linux system! But in my app. i don't write the objects to file...i just need the object back. but the data comes in clean.

  • Problems on zipping and unzipping class files

    I am trying to add a class file to a new jar file using FileInputStream and JarOutputStream.
    I am getting a very unique problems.
    when I read a class file using FileInputStream from my local hard disk I am getting 30 bytes less than then actual file size (the difference in bytes is exactly 30 bytes for any file, either class or xml or java, I dont understand this concept). after reading the contents I am writing the bytes read to a jar file using JarOutputStream. This all gets done fine. But when I extract the class file written into the jar file and try to run the class it is giving me the exception as follows:
    java.lang.ClassNotFoundException: com.wipro.flowbrix.plugins.factory.NewClass
    Exception in thread "main" java.lang.ClassFormatError: com/wipro/flowbrix/plugins/factory/NewClass (Bad magic number)
    at java.lang.ClassLoader.defineClass0(Native Method)
    at java.lang.ClassLoader.defineClass(Unknown Source)
    at java.security.SecureClassLoader.defineClass(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.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClassInternal(Unknown Source)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Unknown Source)
    The classpath to the folder from where I am running the file is set. I have double checked the classpath.
    any information or solutions regarding this would be of great help.

    A "magic number" is a short sequence of data at the beginning of a file used to identify the file. ".class" files, for instance, always start with OxCA, 0xFE, 0xBA and 0xBE.
    If the 30 bytes missing are at the beginning of your file, there's nothing suprising in getting a "ClassFormatError" exception.
    I think we should concentrate on your first problem. Can you post the code used to add the class file, please?
    /Stephane

  • Jar (or Zip) file with problems in accents, special characters

    Hi! I've a servlet that creates a jar (or zip) file and then send it. My problem is that when I create an entry in which the filename has special characters such as accents, when I unjar or unzip de file, it brings a lot of garbage characters. For example, the nex entry:
    Ex�menes.doc
    when unzipped is:
    Ex?�menes.doc
    I've tried a lot of things:
    -Setting the locale to ES, MX
    -Replacing all the letters with special characters with its unicode (like s.replace('�','\u00E1')
    -Trying to convert it to UTF8 (new String(path.getBytes(),"UTF8") )
    -Replacing the file separator char (according to a workaround that I found in the bug database)
    But nothing of this worked, alone or together. I've read that this is (or was) a bug in the API, but don't know if a solution has been found.
    Any help will be greatly appreciated!

    It's not clear what you are asking. Maybe this will help
    http://www.cfdev.com/code_samples/code.cfm/CodeID/83/Java/Simple_Ant_build_xml_Build_Task

  • Unzipping problems

    So that we may better diagnose DOWNLOAD problems, please provide the following information.
    - Server name
    - Filename
    - Date/Time
    - Browser + Version
    - O/S + Version
    - Error Msg
    After downloading Oracle 9i I was unable to unzip the files, for they have not been recognised as legal zip archives.

    Please try unzipping the content to a folder location with less character length say c:\Champs\CS4WP 
    Current folder length C:\Documents and Settings\Champs\Mis documentos\Adobe CS4 Web Premium   subsequently followed by biggest folder length inside the zipped content might be creating the problem here.
    regards
    Aj

  • Unzip problem

    So that we may better diagnose DOWNLOAD problems, please provide the following information.
    Downloaded the following files last night, 5/16/02.
    9011NTSrv_Disk1.zip
    9011NTSrv_Disk2.zip
    9011NTSrv_Disk3.zip
    WinZip cannot unzip any of them.
    Error message is: "Cannot openfile: it does not appear to be a valid archive."
    Tried PKUnzip from a dos prompt on 9011NTSrv_Disk3.zip.
    Error message is: "Warning! I don't know how to handle: readme.txt"
    I'm running W2K.
    - Server name
    - Filename
    - Date/Time
    - Browser + Version
    - O/S + Version
    - Error Msg

    Oh yes i checked the ingoing and outgoing size of bytes...
    they are perfectly the same.
    The problem lies more in the in.readObject() method.
    when i dump the bytes that i receive to a File (which i do not want to do in the application) i can actually unzip it with unzip from my Linux system! But in my app. i don't write the objects to file...i just need the object back. but the data comes in clean.

Maybe you are looking for

  • How to calculate Age ?

    I have 2 date fields, date1=01-Aug-70, date2=01-Aug-05, when I use the following statement : ROUND((date2 - date1) / 365), the result is -64...if seems than system don't know 70=1970 and 05=2005.... How to solve this problems ?..... Thanks, Urgent!

  • Can't Activate iPhone 3GS after doing an update software to 6.0.1

    I dont think it was jailbreaked or anything it was unlocked when i bought it and after i did a update it wouldn't active it gets me a error saying to try again later,IMEI:01 285400 522628 3

  • Very Basic Question - Resizing Image

    Cannot believe I am having to ask such a basic question, but in order to scan and send documents to a particular database, there are two requirements: 1) 200 dpi, and 2) Greyscale The greyscale I found quickly enough by going to image adjustments ---

  • Crash when opening Block Diagram

    I am converting a Windows .dll based program to an event driven state machine using my Mac (LV2010) as a development computer.  The final program will run in the development environment on a Windows computer.  When I reach a certain point in the conv

  • How do I access Photoshop CC to begin?

    HI - I just installed photoshop cc on my computer. how do I access it to begin? I clicked on the adobe creative cloud icon on my desktop and it just take me to this screen? Is there a way to have a shortcut on my desktop so I can just access it? Than