FileDocCategorySizeDatePackage
ContentInfo.javaAPI DocExample1711Thu Feb 16 11:34:22 GMT 2006None

ContentInfo

public class ContentInfo extends MIDlet implements CommandListener

Fields Summary
private Display
display
private TextBox
textBox
Constructors Summary
Methods Summary
public voidcommandAction(Command command, Displayable displayable)

    // Network operations should not run in this same thread
    Thread t = new Thread(
       new Runnable() {
         public void run() {
           display.setCurrent(getInfo());
         }
       }
     );
     t.start();
  
public voiddestroyApp(boolean unconditional)

private FormgetInfo()


    Form form = new Form("Content Info");
    ContentConnection conn = null;
    try {
      conn = (ContentConnection) Connector.open(textBox.getString());
      String type = conn.getType();
      String encoding = conn.getEncoding();
      long length = conn.getLength();
      
      form.append("Media type: " + type + "\r\n");
      if (encoding != null) form.append("Encoding: " + encoding + "\r\n");
      form.append("Length: " + String.valueOf(length));
    }
    catch (IOException ex) {
      form.append(ex.getMessage());
    }
    finally {
      try {
        if (conn != null) conn.close();
      }
      catch (IOException ex) { /* Oh well. we tried.*/ }
    }
    return form;
  
public voidpauseApp()

public voidstartApp()

    display = Display.getDisplay(this);

    if (textBox == null) {
      textBox = new TextBox("URL", "http://", 255, TextField.URL);
    }
    display.setCurrent(textBox);

    Command getInfo = new Command("Get Info", Command.OK, 10);
    textBox.addCommand(getInfo);
    textBox.setCommandListener(this);