Пример #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;
    }
  }
Пример #2
0
  private static void printEndpoint(int indent, Endpoint e) {
    if (e == null) {
      indentLine(indent, "<!-- endpoint not available -->");
      return;
    }

    indentLine(
        indent,
        "<endpoint addr='"
            + e.getEndpointAddress()
            + "' direction='"
            + (e.isInput() ? "in" : "out")
            + "' type='"
            + e.getType()
            + "'");
    indentLine(
        indent + 4,
        "attributes='"
            + Integer.toHexString(e.getAttributes())
            + "' maxpacket='"
            + e.getMaxPacketSize()
            + "' interval='"
            + e.getInterval()
            // XXX two "extra" bytes in audio endpoints ...
            + "'/>");
    maybePrintDescriptors(indent, e.nextDescriptor());
  }