Search in sources :

Example 1 with InputConnection

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;
}
Also used : InputConnection(javax.microedition.io.InputConnection) HttpConnection(javax.microedition.io.HttpConnection) DataInputStream(java.io.DataInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) IOException(java.io.IOException) IOException(java.io.IOException)

Aggregations

ByteArrayInputStream (java.io.ByteArrayInputStream)1 DataInputStream (java.io.DataInputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 HttpConnection (javax.microedition.io.HttpConnection)1 InputConnection (javax.microedition.io.InputConnection)1