Troubleshooting guide

63
2: Using graphics and multimedia
}
public InputStream getInputStream(String uri, ConnectionInfo info)
throws IOException, MediaException {
if (uri.startsWith(“myprotocol://”)) {
// Perform special tasks.
info.setConnection(new MyProtocolConnection());
info.setContentType(“application/x-vnd.rim.pme”);
// OpenMyInputStream() is a custom method that opens
//stream for “myprotocol://”
input = openMyInputStream(uri);
} else {
input = delegate.getInputStream(uri, info);
}
return input;
}
private InputStream openMyInputStream(String uri) {
InputStream input = null;
// @todo: open stream here
return input;
}
public void releaseConnection(ConnectionInfo info)
throws IOException, MediaException {
Object o = info.getConnection();
if (o instanceof MyProtocolConnection) {
((MyProtocolConnection)o).close(); // Perform cleanup.
} else {
delegate.releaseConnection(info);
}
}
public void setProperty(String property, String value) {
delegate.setProperty(property, value);
}
// Inner class that defines the connection class.
public static class MyProtocolConnection {
public MyProtocolConnection() {
// ...
}
public void close() {
// ...
}
}
}