You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@geronimo.apache.org by Aaron Mulder <am...@alumni.princeton.edu> on 2004/11/04 19:02:36 UTC

Zip Files and Endian-ness

	I'm trying to detect a Zip file.  On an Intel/AMD platform, the 
first 4 bytes are (hex) 50-4b-03-04.  I wonder if the order is different 
on a differently-endian platform.  Can someone look at a ZIP file on, 
what, a Solaris box I guess, and let me know what order the first 4 bytes 
are?  Maybe a Mac is different?  I forget.  Here's a little test class.

Thanks,
	Aaron

import java.io.*;
public class ZipTest {
    public static void main(String[] args) {
        try {
            FileInputStream in = new FileInputStream(args[0]);
            System.out.println("B1: "+Integer.toHexString(in.read()));
            System.out.println("B2: "+Integer.toHexString(in.read()));
            System.out.println("B3: "+Integer.toHexString(in.read()));
            System.out.println("B4: "+Integer.toHexString(in.read()));
            in.close();
            in = new FileInputStream(args[0]);
            System.out.println("Int: "+Integer.toHexString(
                new DataInputStream(in).readInt()));
            in.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

PC Results
----------
B1: 50
B2: 4b
B3: 3
B4: 4
Int: 504b0304

Re: Zip Files and Endian-ness

Posted by Dain Sundstrom <ds...@gluecode.com>.
The endianness should not matter when reading the byte, but I could be 
wrong.  Anyway, I got the same results on my mac:

B1: 50
B2: 4b
B3: 3
B4: 4
Int: 504b0304

-dain

--
Dain Sundstrom
Chief Architect
Gluecode Software
310.536.8355, ext. 26

On Nov 4, 2004, at 10:02 AM, Aaron Mulder wrote:

> 	I'm trying to detect a Zip file.  On an Intel/AMD platform, the
> first 4 bytes are (hex) 50-4b-03-04.  I wonder if the order is 
> different
> on a differently-endian platform.  Can someone look at a ZIP file on,
> what, a Solaris box I guess, and let me know what order the first 4 
> bytes
> are?  Maybe a Mac is different?  I forget.  Here's a little test class.
>
> Thanks,
> 	Aaron
>
> import java.io.*;
> public class ZipTest {
>     public static void main(String[] args) {
>         try {
>             FileInputStream in = new FileInputStream(args[0]);
>             System.out.println("B1: "+Integer.toHexString(in.read()));
>             System.out.println("B2: "+Integer.toHexString(in.read()));
>             System.out.println("B3: "+Integer.toHexString(in.read()));
>             System.out.println("B4: "+Integer.toHexString(in.read()));
>             in.close();
>             in = new FileInputStream(args[0]);
>             System.out.println("Int: "+Integer.toHexString(
>                 new DataInputStream(in).readInt()));
>             in.close();
>         } catch (IOException e) {
>             e.printStackTrace();
>         }
>     }
> }
>
> PC Results
> ----------
> B1: 50
> B2: 4b
> B3: 3
> B4: 4
> Int: 504b0304