Chilkat HOME ASP Visual Basic VB.NET C# Visual C++ C MFC Delphi FoxPro Java Perl PHP Python Ruby SQL Server VBScript
|
beginsWith -- Check if Byte Array Begins with Byte SequenceDetermine if a byte array begins with a specific byte sequence. 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.