Advancing Water Resources Research and Management |
| Symposium on Water Resources and the World Wide Web |
|---|
| Seattle, Washington, December 5-9, 1999 |
String version = System.getProperty("java.version");
Debug.println("Java version is "+version);
if(version.indexOf("1.1") >= 0 ||
version.indexOf("2.") >= 0 ) {
//we are version 1.1
try {
Class lgz = Class.forName("LoadGZIP");
lgz.newInstance(); // load the gzipped file
bad_gz=false;
} catch (Exception e) {
Debug.println("Exception trying to find class Version11: "+e);
bad_gz=true;
}
} else {
Debug.println("Processing for java "+version);
bad_gz = true;
}
if(bad_gz) {
//get the station info the old way
etc...
And here is the class that implements the decompression:
import java.io.*;
import java.net.*;
import java.util.zip.*;
public class LoadGZIP {
// this java v 1.1 class is conditionally loaded by
// StationLoader.java.
//
// In order to be instantiated by java v 1.0.2 - compatible code by the
// newInstance() method, it must have a constructor with no args.
public LoadGZIP() {
try {
URL stationURL = new URL(ZoomMap.code_base,"station_info.gz");
URLConnection urlc = stationURL.openConnection();
urlc.setUseCaches(false);
InputStream fin = stationURL.openStream();
BufferedInputStream bfin = new BufferedInputStream(fin,4096);
// class GZIPInputStream is java v 1.1
GZIPInputStream zis= new GZIPInputStream(bfin);
StationLoader.in = new DataInputStream(zis);
Debug.println("Reading station_info.gz");
} catch (Error err) {
Debug.println("Error getting station_info.gz: "+err);
} catch (Exception ex) {
Debug.println("Exception finding station_info.gz: "+ex);
}
}
}
![]() | |
| Symposium TOC | AWRA Home page |
Maintainer: AWRA Webserver Team
Copyright © 1999 American Water Resources Association