Java Examples

ChilkatHOMEASPVisual BasicVB.NETC#Visual C++CMFCDelphiFoxProJavaPerlPHPPythonRubySQL ServerVBScript

Java Examples

Quick Start
Unicode
Bz2
Certificates
CSV
Email
Encryption
FTP
HTML-to-XML
HTTP
IMAP
MHT
MIME
POP3
RSA
S/MIME
SFTP
Signatures
SMTP
Socket / SSL
Spider
SSH
SSH Key
SSH Tunnel
Tar
Upload
XML
XMP
Zip

More Examples...
Email Object
FileAccess
RSS
Atom
String
Byte Array
Self-Extractor
Service
PPMD
Deflate
DH Key Exchange
DSA

Unreleased...
Bzip2
LZW
Icon

 

 

 

 

 

 

 

How to read a binary structure (.zip header)

Demonstrates calling methods such as getUInt, getUShort, etc. to read integers in a binary structure. In this case, a .zip file is opened and the 1st local file header is examined.

Download Chilkat Java Library

import com.chilkatsoft.*;

public class ChilkatExample {

  static {
    try {
        System.loadLibrary("chilkat");
    } catch (UnsatisfiedLinkError e) {
      System.err.println("Native code library failed to load.\n" + e);
      System.exit(1);
    }
  }

  public static void main(String argv[])
  {
    CkByteData zipData = new CkByteData();

    boolean success;

    success = zipData.loadFile("dude.zip");
    if (success != true) {
        System.out.println("Failed to load file");
        return;
    }

    int offset;
    offset = (int) 0;

    int filenameLen;
    filenameLen = (int) zipData.getUShort(26);

    System.out.println(zipData.getRangeStr(30,filenameLen));

    int compressedSize;
    int uncompressedSize;

    compressedSize = (int) zipData.getUInt(18);
    uncompressedSize = (int) zipData.getUInt(22);

    System.out.println(compressedSize);
    System.out.println(uncompressedSize);

    //  Note: Zip File Structure:
    //  see: http://www.pkware.com/documents/casestudies/APPNOTE.TXT

    //   Overall .ZIP file format:

    //     [local file header 1]
    //     [file data 1]
    //     [data descriptor 1]
    //     .
    //     .
    //     .
    //     [local file header n]
    //     [file data n]
    //     [data descriptor n]
    //     [archive decryption header]
    //     [archive extra data record]
    //     [central directory]
    //     [zip64 end of central directory record]
    //     [zip64 end of central directory locator]
    //     [end of central directory record]

    //   A.  Local file header:

    //         local file header signature     4 bytes  (0x04034b50)
    //         version needed to extract       2 bytes
    //         general purpose bit flag        2 bytes
    //         compression method              2 bytes
    //         last mod file time              2 bytes
    //         last mod file date              2 bytes
    //         crc-32                          4 bytes
    //         compressed size                 4 bytes
    //         uncompressed size               4 bytes
    //         file name length                2 bytes
    //         extra field length              2 bytes

    //         file name (variable size)
    //         extra field (variable size)

    //  ...

  }
}

 

Need a specific example? Send a request to support@chilkatsoft.com

© 2000-2008 Chilkat Software, Inc. All Rights Reserved.