use of javax.microedition.io.InputConnection in project J2ME-Loader by nikita36078.
the class Loader method getHttpInputStream.
/*
* InputStream-related helper functions
*/
/**
* Open a HTTP stream and check its MIME type
*
* @param name Resource name
* @return a http stream and checks the MIME type
*/
private InputStream getHttpInputStream(String name) throws IOException {
InputConnection ic = (InputConnection) Connector.open(name);
// Content-Type is available for http and https connections
if (ic instanceof HttpConnection) {
HttpConnection hc = (HttpConnection) ic;
// Check MIME type
String type = hc.getHeaderField("Content-Type");
if (type != null && !type.equals("application/m3g") && !type.equals("image/png") && !type.equals("image/jpeg")) {
throw new IOException("Wrong MIME type: " + type + ".");
}
}
InputStream is;
try {
is = ic.openInputStream();
} finally {
try {
ic.close();
} catch (Exception e) {
e.printStackTrace();
}
}
return is;
}
Aggregations