javax.microedition.io.InputConnection Java Examples

The following examples show how to use javax.microedition.io.InputConnection. 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: ConnectorServiceImpl.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public DataInputStream openDataInputStream(String name) throws IOException {
  Connection con = open(name, ConnectorService.READ, false);

  if (con instanceof InputConnection) {
    DataInputStream stream = ((InputConnection)con).openDataInputStream();
    con.close();
    return stream;
  }
  con.close();
  throw new IOException("Given scheme does not support input");
}
 
Example #3
Source File: ConnectorServiceImpl.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public InputStream openInputStream(String name) throws IOException {

    Connection con = open(name, ConnectorService.READ, false);

    if (con instanceof InputConnection) {
      InputStream stream = ((InputConnection)con).openInputStream();
      con.close();
      return stream;
    }

    con.close();
    throw new IOException("Given scheme does not support input");
  }
 
Example #4
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();
	}
}
 
Example #5
Source File: ConnectorAdapter.java    From J2ME-Loader with Apache License 2.0 4 votes vote down vote up
@Override
public DataInputStream openDataInputStream(String name) throws IOException {
	return ((InputConnection) open(name)).openDataInputStream();
}
 
Example #6
Source File: ConnectorAdapter.java    From J2ME-Loader with Apache License 2.0 4 votes vote down vote up
@Override
public InputStream openInputStream(String name) throws IOException {
	return ((InputConnection) open(name)).openInputStream();
}