Android™
Android™
Check if a File is in Gzip Format
See more Gzip Examples
This example demonstrates how to use the ExamineFile method to determine whether a file is in Gzip format.
The method inspects the contents of the specified file and returns true if the file is recognized as a valid Gzip file, or false if it is not. This is useful for validating input files before attempting to decompress them.
If the method fails (for example, if the file does not exist or cannot be accessed), the CHECK_SUCCESS macro reports the error.
Chilkat Android™ Downloads
// Important: Don't forget to include the call to System.loadLibrary
// as shown at the bottom of this code sample.
package com.test;
import android.app.Activity;
import com.chilkatsoft.*;
import android.widget.TextView;
import android.os.Bundle;
public class SimpleActivity extends Activity {
private static final String TAG = "Chilkat";
// Called when the activity is first created.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// This example demonstrates how to determine if a file is in Gzip format.
CkGzip gzip = new CkGzip();
// The file to examine:
String filePath = "test.gz";
// Check if the file is a valid Gzip file:
boolean isGzip = gzip.ExamineFile(filePath);
if (isGzip == true) {
Log.i(TAG, "The file is a valid Gzip file.");
}
else {
Log.i(TAG, "The file isnot a Gzip file.");
}
}
static {
System.loadLibrary("chilkat");
// Note: If the incorrect library name is passed to System.loadLibrary,
// then you will see the following error message at application startup:
//"The application <your-application-name> has stopped unexpectedly. Please try again."
}
}