Java Code Examples for javax.microedition.io.InputConnection#openInputStream()

The following examples show how to use javax.microedition.io.InputConnection#openInputStream() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Loader.java    From J2ME-Loader with Apache License 2.0 5 votes vote down vote up
/**
 * 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;
}
 
Example 2
Source File: MicroeditionConnector.java    From blucat with GNU General Public License v2.0 5 votes vote down vote up
public static InputStream openInputStream(String name) throws IOException {
	InputConnection con = ((InputConnection) openImpl(name, READ, false, false));
	try {
		return con.openInputStream();
	} finally {
		con.close();
	}
}