Esempio n. 1
0
  private void init(Interface intf) throws IOException {
    if (intf == null || intf.getNumEndpoints() != 2) throw new IllegalArgumentException();

    // XXX presumably this handles the "multiple devfs claims" case; check.

    intf.claim();
    this.intf = intf;

    try {
      for (int i = 0; i < intf.getNumEndpoints(); i++) {
        Endpoint ep = intf.getEndpoint(i);

        if (!"bulk".equals(ep.getType())) throw new IllegalArgumentException();
        if (ep.isInput()) in = ep.getInputStream();
        else out = ep.getOutputStream();
      }
      if (in == null || out == null) throw new IllegalArgumentException();
    } catch (IOException e) {
      try {
        close();
      } catch (Exception x) {
        intf = null;
      }
      throw e;
    } catch (RuntimeException e) {
      try {
        close();
      } catch (Exception x) {
        intf = null;
      }
      throw e;
    }
  }
Esempio n. 2
0
  public void close() throws IOException {
    in = null;
    out = null;

    if (random != null) {
      random.close();
      random = null;
    } else if (socket != null) {
      socket.close();
      socket = null;
    }
  }
Esempio n. 3
0
 /**
  * Finalization releases the interface, if it has not already been released by invoking close().
  */
 protected void finalize() throws IOException {
   close();
 }