public class HapiClient
extends java.lang.Object
Modifier and Type | Method and Description |
---|---|
protected static long |
cacheAgeLimitMillis()
allow cached files to be used for no more than 1 hour.
|
static int |
dayOfYear(int year,
int month,
int day)
return the doy of year of the month and day for the year.
|
static org.json.JSONObject |
getCatalog(java.net.URL server)
return the catalog as a JSONObject.
|
static java.lang.String[] |
getCatalogIdsArray(java.net.URL server)
return the catalog as a String array.
|
static java.util.Iterator<HapiRecord> |
getData(java.net.URL server,
java.lang.String id,
java.lang.String startTime,
java.lang.String endTime)
return the data record-by-record
|
static java.util.Iterator<HapiRecord> |
getData(java.net.URL server,
java.lang.String id,
java.lang.String parameters,
java.lang.String startTime,
java.lang.String endTime)
return the data record-by-record
|
static java.util.Iterator<HapiRecord> |
getDataCSV(java.net.URL server,
java.lang.String id,
java.lang.String startTime,
java.lang.String endTime)
return the data record-by-record, using the CSV response.
|
static java.util.Iterator<HapiRecord> |
getDataCSV(java.net.URL server,
java.lang.String id,
java.lang.String parameters,
java.lang.String startTime,
java.lang.String endTime)
return the data record-by-record, using the CSV response.
|
static org.json.JSONObject |
getInfo(java.net.URL server,
java.lang.String id)
get the info for the id
|
static JSONObject |
getInfo(java.net.URL server,
java.lang.String id,
java.lang.String parameters)
get the info for the id, for a subset of the parameters.
|
static java.lang.String[] |
getInfoParametersArray(java.net.URL server,
java.lang.String id)
return a list of the parameters for the id, as a String array.
|
static int[] |
isoTimeToArray(java.lang.String time)
return array [ year, months, days, hours, minutes, seconds, nanoseconds ]
|
static java.lang.String |
readFromCachedURL(java.net.URL url,
java.lang.String type)
return the resource, if cached, or null if the data is not cached.
|
static java.lang.String |
readFromFile(java.io.File f)
read the file into a string.
|
static java.lang.String |
readFromURL(java.net.URL url,
java.lang.String type)
read data from the URL.
|
static long |
toMillisecondsSince1970(java.lang.String time)
return the time as milliseconds since 1970-01-01T00:00Z.
|
protected static boolean |
useCache()
use cache of HAPI responses, to allow for use in offline mode.
|
static void |
writeToCachedURL(java.net.URL url,
java.lang.String type,
java.lang.String data)
write the data (for example, an info response) to a cache file.
|
protected static boolean useCache()
protected static long cacheAgeLimitMillis()
public static java.lang.String readFromFile(java.io.File f) throws java.io.IOException
f
- non-empty filejava.io.IOException
public static java.lang.String readFromCachedURL(java.net.URL url, java.lang.String type) throws java.io.IOException
url
- type
- "json" (the extension) or "" for no additional extension.java.io.IOException
public static void writeToCachedURL(java.net.URL url, java.lang.String type, java.lang.String data) throws java.io.IOException
url
- the resource location, query param id is handled specially,
but others are ignored.type
- "json" (the extension), or "" if no extension should be added.data
- the data.java.io.IOException
public static java.lang.String readFromURL(java.net.URL url, java.lang.String type) throws java.io.IOException
url
- the URL to read fromtype
- the extension to use for the cache file (JSON, bin, txt).java.io.IOException
public static org.json.JSONObject getCatalog(java.net.URL server) throws java.io.IOException, JSONException
jo= getCatalog( URL( "https://jfaden.net/HapiServerDemo/hapi/catalog" ) )
print jo.get('HAPI') # "2.0"
catalog= jo.getJSONArray( 'catalog' )
for i in range(catalog.length()):
print catalog.getJSONObject(i).get('id')
server
- java.io.IOException
org.json.JSONException
JSONException
getCatalogIdsArray(java.net.URL)
public static java.lang.String[] getCatalogIdsArray(java.net.URL server) throws java.io.IOException, JSONException
catalog= getCatalogIdsArray( URL( "https://jfaden.net/HapiServerDemo/hapi/catalog" ) )
for s in catalog:
print s
server
- java.io.IOException
JSONException
public static org.json.JSONObject getInfo(java.net.URL server, java.lang.String id) throws java.io.IOException, JSONException
server
- id
- HAPI dataset identifier, matching [a-zA-Z_]+[a-zA-Z0-9_/]*java.io.IOException
org.json.JSONException
JSONException
public static JSONObject getInfo(java.net.URL server, java.lang.String id, java.lang.String parameters) throws java.io.IOException, JSONException
server
- id
- HAPI dataset identifier, matching [a-zA-Z_]+[a-zA-Z0-9_/]*parameters
- comma-separated list of parameter names.java.io.IOException
org.json.JSONException
JSONException
public static java.lang.String[] getInfoParametersArray(java.net.URL server, java.lang.String id) throws java.io.IOException, JSONException
server
- id
- java.io.IOException
JSONException
getInfo(java.net.URL, java.lang.String)
public static java.util.Iterator<HapiRecord> getDataCSV(java.net.URL server, java.lang.String id, java.lang.String startTime, java.lang.String endTime) throws java.io.IOException, JSONException
server
- id
- startTime
- endTime
- java.io.IOException
org.json.JSONException
- should the server return an invalid response.JSONException
public static java.util.Iterator<HapiRecord> getDataCSV(java.net.URL server, java.lang.String id, java.lang.String parameters, java.lang.String startTime, java.lang.String endTime) throws java.io.IOException, JSONException
server
- id
- parameters
- startTime
- endTime
- java.io.IOException
org.json.JSONException
- should the server return an invalid response.JSONException
public static java.util.Iterator<HapiRecord> getData(java.net.URL server, java.lang.String id, java.lang.String startTime, java.lang.String endTime) throws java.io.IOException, JSONException
server
- the HAPI serverid
- the dataset idstartTime
- the start timeendTime
- the end timejava.io.IOException
org.json.JSONException
- should the server return an invalid responseJSONException
public static java.util.Iterator<HapiRecord> getData(java.net.URL server, java.lang.String id, java.lang.String parameters, java.lang.String startTime, java.lang.String endTime) throws java.io.IOException, JSONException
server
- the HAPI serverid
- the dataset idparameters
- a comma-separated list of parameter namesstartTime
- the start timeendTime
- the end timejava.io.IOException
org.json.JSONException
- should the server return an invalid responseJSONException
public static long toMillisecondsSince1970(java.lang.String time)
from org.hapiserver.HapiClient import *
x= toMillisecondsSince1970('2000-01-02T00:00:00.0Z')
print x / 86400000 # 10958.0 days
print x % 86400000 # and no milliseconds
time
- public static int dayOfYear(int year, int month, int day)
from org.hapiserver.HapiClient import *
print dayOfYear( 2000, 5, 29 ) # 150
year
- the yearmonth
- the month, from 1 to 12.day
- the day in the month.public static int[] isoTimeToArray(java.lang.String time)
time
-