Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8125625
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T06:52:49+00:00 2026-06-06T06:52:49+00:00

I am creating an archive on Android using the code like this: OutputStream os

  • 0

I am creating an archive on Android using the code like this:

    OutputStream os = new FileOutputStream(zipFile);
    ZipOutputStream zos = new ZipOutputStream(new BufferedOutputStream(os));
    try 
    {
        zos.setLevel(8);
        byte[] buffer = new byte[32768];
        for (VFile src : toPack)            
        {
            ZipEntry entry = new ZipEntry(src.name);
            zos.putNextEntry(entry);
            src.pushToStream(zos, buffer);
            src.close();
            zos.closeEntry();
        }
    }
    finally 
    {
        zos.close();
    }       

I found that there’s only one compression method available – DEFLATED (there’s only STORED alternative available). This means that archive is always compressed with one method.

If I run this code on Android 2.3.4 – I can decompress files in Windows using 7Zip; if I run this on Android 3 (or Samsung Galaxy Tab; not sure who makes it wrong) – 7Zip shows archive list, but cannot decompress file saying Unsupported compression method. At the same time 7Zip shows Deflate as a compression method on file which means it can treat it properly.

Did anyone has this problem?

Thanks.

UDP: Found another topic with similar issue (may be not same though).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T06:52:50+00:00Added an answer on June 6, 2026 at 6:52 am

    The @user1269737’s answer is correct; almost. But it only works for a single-file archives.
    Below is a code which parses the whole archive.

    /**
    * Replace wrong local file header byte
    * http://sourceforge.net/tracker/?func=detail&aid=3477810&group_id=14481&atid=114481
    * Applies to Android API 9-13
    * @param zip file
    * @throws IOException
    */
    private static void fixInvalidZipFile(File zip) throws IOException 
    {
        RandomAccessFile r = new RandomAccessFile(zip, "rw");
        try
        {
            long eocd_offset = findEOCDRecord(r);
    
            if (eocd_offset > 0)
            {
                r.seek(eocd_offset + 16);  // offset of first CDE in EOCD               
                long cde_offset = readInt(r);  // read offset of first Central Directory Entry
                long lfh_offset = 0;
                long fskip, dskip;
    
                while (true)
                {
                    r.seek(cde_offset);
                    if (readInt(r) != CDE_SIGNATURE)  // got off sync!
                        return;
    
                    r.seek(cde_offset + 20);  // compressed file size offset                
                    fskip = readInt(r);
    
                    // fix the header
                    //
                    r.seek(lfh_offset + 7);
                    short localFlagsHi = r.readByte();  // hi-order byte of local header flags (general purpose)
                    r.seek(cde_offset + 9);
                    short realFlagsHi = r.readByte();  // hi-order byte of central directory flags (general purpose)
                    if (localFlagsHi != realFlagsHi)
                    { // in latest versions this bug is fixed, so we're checking is bug exists.
                        r.seek(lfh_offset + 7);
                        r.write(realFlagsHi);
                    }
    
                    //  calculate offset of next Central Directory Entry
                    //
                    r.seek(cde_offset + 28);  // offset of variable CDE parts length in CDE
                    dskip = 46;  // length of fixed CDE part
                    dskip += readShort(r);  // file name
                    dskip += readShort(r);  // extra field
                    dskip += readShort(r);  // file comment
    
                    cde_offset += dskip;
                    if (cde_offset >= eocd_offset)  // finished!
                        break;              
    
                    // calculate offset of next Local File Header
                    //
                    r.seek(lfh_offset + 26);  // offset of variable LFH parts length in LFH
                    fskip += readShort(r);  // file name
                    fskip += readShort(r);  // extra field
                    fskip += 30;  // length of fixed LFH part
                    fskip += 16;  // length of Data Descriptor (written after file data)
    
                    lfh_offset += fskip;
                }
            }
        }
        finally
        {
            r.close();
        }
    }
    
    //http://www.pkware.com/documents/casestudies/APPNOTE.TXT
    private static final int LFH_SIGNATURE = 0x04034b50;
    private static final int DD_SIGNATURE = 0x08074b50;
    private static final int CDE_SIGNATURE = 0x02014b50;
    private static final int EOCD_SIGNATURE = 0x06054b50;
    
    /** Find an offset of End Of Central Directory record in file */
    private static long findEOCDRecord(RandomAccessFile f) throws IOException
    {
        long result = f.length() - 22; // 22 is minimal EOCD record length
        while (result > 0)
        {
            f.seek(result);
    
            if (readInt(f) == EOCD_SIGNATURE) return result;
    
            result--;
        }
        return -1;
    }
    
    /** Read a 4-byte integer from file converting endianness. */
    private static int readInt(RandomAccessFile f) throws IOException
    {
        int result = 0;
        result |= f.read();
        result |= (f.read() << 8);
        result |= (f.read() << 16);
        result |= (f.read() << 24);
        return result;
    }
    
    /** Read a 2-byte integer from file converting endianness. */
    private static short readShort(RandomAccessFile f) throws IOException
    {
        short result = 0;
        result |= f.read();
        result |= (f.read() << 8);
        return result;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm creating new Site Definitions using this method: http://weblogs.asp.net/paulballard/archive/2007/04/09/creating-a-custom-sharepoint-2007-portal-site-definition-using-the-portalprovisioningprovider-class.aspx and when they get created,
When creating zip archive using python ZipFile, how can i set file mime types?
When using Grails, when creating the WAR archive, I would like to apply a
I have an ant target for creating zip like this - <zip destfile=${dist}/myzip.zip> <zipfileset
I'm creating a gadjet for Blogger(blogspot), this widget will be placed on all pages(post,archive
I'm creating an archive of news articles in a sharepoint publishing site. users can
Creating a class at runtime is done as follows: klass = Class.new superclass, &block
(creating a separate question after comments on this: Javascript redeclared global variable overrides old
I am creating an app where i use a WebView this is how the
I am creating an Android board game similar to, for example, Bubble Pop where

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.