Problems with CRC in some windows app's whit zip files generated with Java

Hello,
That is very strange but, we have an app for compressing a folder into a zip. For making, we use the Java.Util.Zip API. Our zip file looks fine, we can unzip the files into another folder without problems, even we can open the file with Winzip or Winrar.
But, we had encountered problems with anothers win apps like "Recovery ToolBox", or another win app built with the "Dynazip.dll" library. This apps give us the next error.
"Bad Crc".
But if we unzip this "corrupt" file and we zip the content again, all work without errors.
[http://img297.imageshack.us/i/dibujoou.jpg/]
Our code (this function only zips a single file):
    public static File zipFile(String sFile, String sNameFileIn, String sFileOut)
            throws IOException {
        File file = new File(sFile);
        FileOutputStream out = new FileOutputStream(sFileOut);
        FileInputStream fin = new FileInputStream(file);
        byte[] fileContent = new byte[(int) file.length()];
        fin.read(fileContent);
        ByteArrayOutputStream bout = new ByteArrayOutputStream();
        ZipOutputStream zout = new ZipOutputStream(bout);
        ZipEntry zipEntry = new ZipEntry(sNameFileIn);
        zout.putNextEntry(zipEntry);
        zout.write(fileContent, 0, fileContent.length);
        zout.closeEntry();
        zout.finish();
        zout.flush();
        zout.close();
        out.write(bout.toByteArray());
        out.flush();
        out.close();
        File fich = new File(sFileOut);
        fin.close();
        return fich;
    }I try to calculate the crc number for my own without success... I don't know what's happening
Thanks in advance

FileOutputStream out = new FileOutputStream(sFileOut);ZipOutputStream zout = new ZipOutputStream(new FileOutputStream(sFileOut));
byte[] fileContent = new byte[(int) file.length()];Here you are assuming the file size is <= Integer.MAX_VALUE. What if it isn't? Remove.
fin.read(fileContent);Here you are assuming you filled the buffer. There is nothing in the API specification to warrant that assumption. Remove. See below.
ByteArrayOutputStream bout = new ByteArrayOutputStream();
ZipOutputStream zout = new ZipOutputStream(bout);Remove.
ZipEntry zipEntry = new ZipEntry(sNameFileIn);
zout.putNextEntry(zipEntry);Correct.
zout.write(fileContent, 0, fileContent.length);int count;
byte[] buffer = new byte[8192];
while ((count = fin.read(buffer)) > 0)
zout.write(buffer, 0, count);
zout.closeEntry();Correct.
zout.finish();
zout.flush();Redundant but not incorrect.
zout.close();Correct.
out.write(bout.toByteArray());
out.flush();
out.close();Remove.
File fich = new File(sFileOut);
fin.close();
return fich;I don't know why this method returns a File constructed out of one of its own arguments, which the caller could equally well do for himself, otherwise OK.

Similar Messages

  • Cannot open zip file generated with java

    Hello everybody !
    I work on a web application ( servlet, JSP... ).
    I generate a zip file containing only one file corresponding to a JSP page but when I try to open it thanks to Winzip 8.0, I have the following message :
    Error : invalid compressed data to inflate.
    The zipped file is not empty, does anybody know what is the problem, here is the source code of my servlet :
    public void trt (HttpServletRequest req, HttpServletResponse res)     throws ServletException, IOException
    URL l_JspPage;
    String temp;
    ByteArrayOutputStream l_ByteArrayOutputStream = new ByteArrayOutputStream();
    ZipOutputStream l_ZipOutputStream = new ZipOutputStream(l_ByteArrayOutputStream);
    l_ZipOutputStream.setMethod(ZipOutputStream.DEFLATED);
    ServletOutputStream out = res.getOutputStream();
    ServletContext servletContext = getServletContext();
    if ((temp=req.getParameter("url"))!=null)
    try
    l_JspPage = new URL(temp);
    DataInputStream l_DataInputStream = new DataInputStream(l_JspPage.openStream());
    int l_iBufferSize = l_DataInputStream.available();
    byte l_byJspPageData[] = new byte[l_iBufferSize];
    l_DataInputStream.read(l_byJspPageData, 0, l_iBufferSize);
    l_ZipOutputStream.putNextEntry(new ZipEntry("file.html"));
    l_ZipOutputStream.write(l_byJspPageData,0,l_iBufferSize);
    l_ZipOutputStream.closeEntry();
    l_ZipOutputStream.finish();
    String zip=l_ByteArrayOutputStream.toString();
    res.setContentType("application/zip");
    res.setHeader("Content-Disposition","inline; filename=output.zip;");
    out.println(zip);
    out.flush();
    Thanks for your help.

    Your code is somewhat obscure, but it appears that you are writing a zip file to a byte array, converting the byte array to a string, and writing the string to "out" - whatever that is.
    I'm not sure why you are going through all this, but in any case the string conversion is probably a wrong step. Zipping results in binary data, and string conversion will probably result in changes to the binary values.

  • Internal Microphone not working with Quicktime and some other apps, yet it does for Skype.

    Internal Microphone not working with Quicktime and some other apps, yet it does for Skype. 
    Microphone works fine with Quictime on another mac, so I do know how to use it. The one where it is not working (A) had an external microphone and camera attached earlier, and indeed it does work with that external microphone, but not with the internal microphone selected; and (B) had RealPlayer installed previously.
    Any suggestions, please?

    Hi,
    Download Audio driver from here.
    Intructions how to install it in Vista/Win7.
    Extract this driver with Winrar.
    Open Device manager and expand the Sound, video and game controllers section.
    Right click on Either the High Definition Audio Device if you have the generic Microsoft drivers, or the Conexant High Definition SmartAudio 221 if you have older Conexant drivers and choose "Update Driver Software..."
    Click Browse my computer for driver software, then click "Let me pick from a list of device drivers on my computer"
    Click "Have Disk..." then Browse to the folder where the drivers were extracted  .......\V64 for 64-bit Vista/Win7. Click OK.
    Select one of the "Conexant High Definition SmartAudio 221" models in the list, there will be multiple identical entries.
    Click Next, and you're done.
    I'm not sure which one from the list will work for You.
    This drivers weren't test. So if You will try them and it will work for You let us now about.
    ** Say thanks by clicking the "Thumb up" icon which is on the left. **
    ** Make it easier for other people to find solutions, by marking my answer with "Accept as Solution" if it solves your issue. **

  • When I went to turn the desktop on, the start up sound came on.  Then the screen was white with an icon flashing. The icon is a file folder with a question mark on it.  I cannot get it to fully turn on.  HELP

    When I went to turn the desktop on, the start up sound came on.  Then the screen was white with an icon flashing. The icon is a file folder with a question mark on it.  I cannot get it to fully turn on.  HELP

    Run a disk repair tool on the hard disk or install a new OS.
    (59898)

  • Lightroom 5.6 does not recognize nef (RAW) image files generated with the new Nikon D750: who can help here or knows what to do? Thanks, Peter

    New Nikon D750:
    Lightroom 5.6 does not recognize nef (RAW) image files generated with the new Nikon D750: who can help here or knows what to do? Thanks, Peter

    LR 5.6 doesn't support the new Nikon D750. You have to wait to the next update.
    You con also install the release candidate of the DNG converter and convert your NEF files to dng.
    http://blogs.adobe.com/lightroomjournal/2014/10/1366.html
    Axel

  • Problem in scrolling in a windows app, which is de...

    I am developing a windows app using phonegap and it works properly until I attach a banner ad at the bottom of the layout( using native code for banner ad) and after adding the banner ad the scrolling does not work (which works properly before adding banner ad)and the total application becomes slower. I have used the following code for scrolling
           style="overflow: scroll; -webkit-overflow-scrolling: touch;"
     I just want to know how to solve the problem using phonegap?

    Try developer.nokia.com
    Click on the blue Star Icon below if my advice has helped you or press the 'Accept As Solution' link if I solved your problem..

  • Zip files compatible with windows

    window error when using Mac zip file "too many files"

    If you select a single text file, then right-click on it and select Compress, I would expect this to produce a ZIP file containing just a single file i.e. the text file.
    If however you select a folder then the ZIP file would contain not only the folder, the obvious files in the folder, but may also contain some invisible files like .DS_Store
    Ok, the above is what I expected, I have just been testing this and this is actually what happens. A single file e.g. a text file when made in to a ZIP by right-clicking and selecting compress produces a ZIP file which contains the following
    thetextfile.txt <--- (the text file)
    __MACOSX <--- (an invisible folder)
    __MACOSX/._thetextfile.txt (an invisible file in the invisible folder, this is not the text file itself)
    So, yes it is more than one file in the ZIP file. By the way, you can 'see' what is in a ZIP file by using Terminal.app and typing the following
    zipinfo nameofzip.zip
    You can use Terminal.app also to create a 'clean' ZIP file containing just the text file the command looks like this
    zip nameofzip.zip thetextfile.txt
    Then to check do the zipinfo command again.
    There is also a a commercial tool do simplify doing this, funnily enough it specifically mentions the __MACOSX folder etc. See http://gotoes.org/sales/Zip_Mac_Files_For_PC/

  • Zipped files created with Java won't unzip with Java

    Hello there,
    I have written a class for unzipping a zip file using the 'ZipFile' class. It works perfectly fine when I extract zip files that have been created with XP, Winzip, or Winrar.
    I am now experimenting with creating zip files using the ZipOutputStream (http://forum.java.sun.com/thread.jspa?forumID=256&threadID=366550 by author smeee). The code works great for creating the zip file, but when I try and unzip it with the zipfile class mentioned above it throws an exception.
    The error that the following code gives me when it tries to convert an element from the enumeration to a ZipEntry is this: java.io.FileNotFoundException: C:\testfiles\out\high\BAUMAN\00001.jpg (The system cannot find the path specified)
    NOTE: The file is there by the way!!! :-)
    See the code for extracting here:
    try {
                 zippy = new ZipFile(fileName);
                 Enumeration all = zippy.entries();
                 while (all.hasMoreElements()) {//loop through all zip entries
                              getFile((ZipEntry)all.nextElement()); <<<=====FAILS HERE
    } catch (IOException err) {
                 System.err.println(err.toString());
                 return;
    }Now if I extract the zip file with winzip, then rezip it with winzip and run the above method again it works with no errors. Any thoughts. Any help would be greatly appreciated.
    Jared

    Hello All,
    For anyone else who use the forum posting by smeee as a guide to create a zipper (http://forum.java.sun.com/thread.jspa?forumID=256&threadID=366550 by author smeee).
    I was tracing through the code and found that there is a statement that adds 1 character (strSource.length()+1) to the source path. This was causing the following bug:
    In windows it was placing objects like this \myfolder\myfile.txt
    In unix it was placing objects like this yfolder\myfile.txt
    Naturally a path like \myfolder... in the zip index was causing problems. I have added a case statement that tests the OS and then adds two chars if windows to compensate for the 'C:' and does nothing if Unix. The code now runs perfectly on either OS.
    Thanks for your response guys!
    Jared

  • .zip files opening with iTunes

    When I double-click a .zip file, it opens in iTunes. How do I get it to unzip?
    Thanks

    Welcome to the forums!
    Highlight the .zip file, do a Get Info on it, look for the Open with triangle, select Othere, find BOMArchive Helper in...
    /System/Library/CoreServices/BOMArchiveHelper.app
    Stuffit will work too, then click the Change All button.

  • I cant get camera raw update 8.7.1 to work with lightroom 5.7 after downloading and opening zip file

    When I try to open a raw file from lightroom 5.7 I get a message that I need camera raw 8.7.1. I downloaded the update as a zip file I extracted file then went through the install wizard process but still I cant get it to work. If I go to photoshop cs5 and open a raw file. canon crw. It will open in camera raw 6.7. can anyone help?

    update your lr:
    Downloadable installation files available:
    Suites and Programs:  CC 2014 | CC | CS6 | CS5.5 | CS5 | CS4, CS4 Web Standard | CS3
    Acrobat:  XI, X | 9,8 | 9 standard
    Premiere Elements:  13 | 12 | 11, 10 | 9, 8, 7 win | 8 mac | 7 mac
    Photoshop Elements:  13 |12 | 11, 10 | 9,8,7 win | 8 mac | 7 mac
    Lightroom:  5.7.1| 5 | 4 | 3
    Captivate:  8 | 7 | 6 | 5.5, 5 | 1
    Contribute:  CS5 | CS4, CS3 | 3,2
    FrameMaker:  12, 11, 10, 9, 8, 7.2
    Download and installation help for Adobe links
    Download and installation help for Prodesigntools links are listed on most linked pages.  They are critical; especially steps 1, 2 and 3.  If you click a link that does not have those steps listed, open a second window using the Lightroom 3 link to see those 'Important Instructions'.

  • 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

  • Can anyone recommend an app that opens zip files?

    Can anyone recommend me an app that I can use to open zip files (mainly photos) and them store them accordingly in files appertaining to content.

    The Archive Browser 1.9.1

  • Windows Pro upgrade with Hyper-V for Windows App development

    Hi
    I am just starting to develop my first windows phone app. I dowloaded Visual studio 2013 express on my windows 8 machine. I started to follow the Microsoft Virtual Academy, Develop Windows phone apps for Beginners with Bob Tabor.
    Anyway, when i try to run the Emulator, it tells me i need Hyper-V which my version of windows doesn't have. Apparently i need Windows Professional. Anyway, this costs about £100 to upgrade. Also, for the emulator i am told i need 4gb of RAM.
    Question 1: My laptop is an i5, 64bit machine, windows 8.1 normal edition, with 4gb of RAM. It says of which 3.88gb of ram is usable. Whatever that means?
    The minimum requirement for the emulator is 4gb, will it work on my machine which apparently has 3.88 ?
    Question 2: I already own a nokia windows 8.1 phone. A basic enough model. Instead of buying the upgrade for windows pro, is it a big hassle to run my test apps on that phone? How difficult is it to run a test build of an app on my phone? Can i run it via
    the inside of visual studio? Or do i need to go to file explorer, copy and paste files over to the phone, disconnect it from the laptop etc. How many steps are involved? If its a load of hassle i might be safer to just bite the bullet and buy the Windows pro
    upgrade.
    (although i am aware the emulator can't test some things that the actual phone can..eg near field communication etc.)
    Any advice?
    Regards
    Conor

    It's not that big of a hassle to debug your app by deploying it on your phone. It's just a matter of choosing Device instead of Emulator when you start debugging in VS.
    Some of the downsides are that your phone's screen must be on and not showing the lock screen, and the fact that you can only have a maximum of 2 apps installed on your phone for debugging purposes. If you start developing and debugging a third app, then
    you must first uninstall one of the other 2 apps to be able to deploy the third app to your phone. To my knowledge the emulator does not have such a limit. I believe there's a paid developer account option available somewhere if you want to raise the limit
    beyond 2 apps.
    Other than that, being tied to a single resolution as Dave mentioned is another downside to using a device.

  • Problems with Adobe Reader in Windows 8. Is there a conflict with Windows 8 Modern Reader.

    When I have Adobe Reader 11 installed on my Windows 8 laptop, PDF documents partially download then stop. Removing Adobe Reader ends the problem and allows viewing via Modern Reader.   However,  I need Adobe Reader to read documents on some websites. Unfortunately when the program has been on the computer for some time the documents stop displaying. Removing and reinstalling the Adobe Reader allows me to view these documents again, for a time, and then the documents stop displaying. Any ideas?

    What browser are you using?
    Does the same thing happen if you download the PDF docs to your local disk, then open them from there?

  • Windows 7 won't allow file association with CC apps.  Why?

    The title says it all.  Any app I installed that replaced a prior version won't link.  I go in manually and attempt to create a file type association and Windows simply ignores the request.  There are no error messages.  I hestitate to dive into regedit with really knowing what I am doing but I did look and see that Photoshop is showing 2 versions (12 with a path to CS5 and 70 with a path to CC).  Indesign has no folders and apaprently no value set and the same is true of LR.  Acrobat on the other hand, works fine.  All programs function correctly as long as I open the program first and then open the file.
    I realize thids is a relatively minor thing but I teach these programs and have to download the files from a university website shell.  Having to manually do this with 30 files/assignment is a royal pain.
    Thanks for any suggestions,
    Steve

    Hi Steve1904,
    So you have use the backup and Restore to restore your files from Windows XP to Windows 7 directly?
    This should be considered not work.
    If you would like to transfer files between Windows XP and Windows 7, you need another tool called Windows Easy Transfer.
    See the article below if you would like to upgrade from Windows XP to Windows 7:
    Upgrading from Windows XP to Windows 7
    If possible, follow the steps there, then things should be OK.
    Best regards
    Michael Shao
    TechNet Community Support

Maybe you are looking for

  • ITunes & QuickTime will install but not open after Windows XP laptop crash

    Alright, this may be a repeat question from a long time ago, but I don't have the time to dig through 1,000+ posts so I'll just put it out there. Here's the situation: *Backed up my entire hard drive including iTunes 8.1 and library to external drive

  • Add skype button onto website?

    I've been trying to get a skype button for my website, so that clients can call/chat to me directly but keep on getting an error message http://developer.skype.com/skype-uris/generator Any ideas what's going on?  Seemed to be an easy thing to do a li

  • Best Practices for Loading Data in 0SD_C03

    Hi, Guru, I want to know which is the best practice to have information about Sales, billing, delivery. I know it has this Datasources. • Sales Order Item Data - 2LIS_11_VAITM • Billing Document Data: Items - 2LIS_13_VDITM • Billing Document Header D

  • WebDynpro: ALV: LinktoURL depending on row

    Hello all, I need to integrate a LinkToURL UIElement to a column in an ALV. The column is AUFNR and the link is depending on the number of the order. f.e. www.sdn.sap.com?id=<AUFNR>. Anybody could tell me if its possible with WebDynpro for ABAP? Than

  • Where is the document.write calling file?

    I an new on the job and still finding my way around the files. I need to edit an html file. I find the file, (or, what I think is the file) but it is a document.write calling another page. I can't find the actual page of code to edit. It is a simple