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

 

 

 

 

 

 

 

beginsWith -- Check if Byte Array Begins with Byte Sequence

Determine if a byte array begins with a specific byte sequence.

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();
    CkByteData gifData = new CkByteData();

    boolean success;

    //  Zip files begin with these 4 bytes:
    byte[] zipBegin_bytes = { (byte)0x50, (byte)0x4B, (byte)3, (byte)4};
    CkByteData zipBegin = new CkByteData();
    zipBegin.appendByteArray(zipBegin_bytes);

    //  GIF files begin with "GIF89", which is this byte sequence:
    byte[] gifBegin_bytes = { (byte)0x47, (byte)0x49, (byte)0x46, (byte)0x38, (byte)0x39};
    CkByteData gifBegin = new CkByteData();
    gifBegin.appendByteArray(gifBegin_bytes);

    success = zipData.loadFile("dude.zip");
    if (success == true) {
        if (zipData.beginsWith(zipBegin)) {
            System.out.println("Yes, this is a .zip archive!");
        }
        else {
            System.out.println("No, this is not a .zip archive.");
        }

    }
    else {
        System.out.println("Failed to load dude.zip");
    }

    success = gifData.loadFile("dude.gif");
    if (success == true) {
        if (gifData.beginsWith(gifBegin)) {
            System.out.println("Yes, this is a GIF image!");
        }
        else {
            System.out.println("No, this is not a GIF image.");
        }

    }
    else {
        System.out.println("Failed to load dude.gif");
    }

  }
}

 

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

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