Beispiel #1
0
 Term createIntegerOrLong(String x) throws ParseException {
   try {
     Term retval = null;
     if (x.endsWith("L") || x.endsWith("l")) {
       try {
         retval =
             TermWare.getInstance()
                 .getTermFactory()
                 .createLong(Long.decode(x.substring(0, x.length() - 1)));
       } catch (NumberFormatException ex) {
         // it can be just too big, becouse literals can be unsigned, while decode does not handle
         // unsogned,
         //  bigger then MAX
         // Here we will handle one case, which exists in JDK sources. (java/lang/Long.java)
         if (x.length() > 2) {
           char last = x.charAt(x.length() - 2);
           long l = Long.decode(x.substring(0, x.length() - 2));
           char x0 = x.charAt(0);
           char x1 = x.charAt(1);
           if (x0 == '0') {
             if (x1 == 'x' || x1 == 'X') {
               // hex
               int l1 = Character.digit(last, 16);
               l = ((l << 8) + l1);
             } else {
               // oct
               int l1 = Character.digit(last, 8);
               l = ((l << 4) + l1);
             }
           }
           retval = TermWare.getInstance().getTermFactory().createLong(l);
         } else {
           throw ex;
         }
       }
     } else {
       long l = Long.decode(x);
       retval = TermWare.getInstance().getTermFactory().createInt((int) l);
     }
     return retval;
   } catch (NumberFormatException ex) {
     throw new ParseException(
         "Can't read IntegerLiteral "
             + ex.getMessage()
             + "(s="
             + x
             + ") "
             + " in file "
             + inFname);
   }
 }
 static ThreadInfo getThreadInfo(String idToken) {
   ThreadInfo tinfo = null;
   if (idToken.startsWith("t@")) {
     idToken = idToken.substring(2);
   }
   try {
     long threadId = Long.decode(idToken).longValue();
     tinfo = getThreadInfo(threadId);
   } catch (NumberFormatException e) {
     tinfo = null;
   }
   return tinfo;
 }
Beispiel #3
0
  protected Entry getEntry(String id) {
    Entry entry = null;

    // check if numeric
    try {
      entry = dao.get(Long.decode(id));
    } catch (NumberFormatException nfe) {
      // fine to ignore
    }

    // check for part Id
    if (entry == null) entry = dao.getByPartNumber(id);

    // check for global unique id
    if (entry == null) entry = dao.getByRecordId(id);

    // get by unique name
    if (entry == null) return dao.getByUniqueName(id);

    return entry;
  }
Beispiel #4
0
 /**
  * Create and open a Connection. This Implementation only supports the <code>btl2cap://</code>
  * protocol schema. If url begins with <code>btl2cap://localhost</code>, this method call will
  * return a <code>javax.bluetooth.L2CAPConnectionNotifier</code>.
  *
  * @param url The URL for the connection.
  * @return A new <code>javax.bluetooth.L2CAPConnection</code> or a <code>
  *     javax.bluetooth.L2CAPConnectionNotifier</code>
  * @throws IllegalArgumentException If a parameter is invalid.
  * @throws IOException If some other kind of I/O error occurs.
  * @see javax.bluetooth.L2CAPConnection
  * @see javax.bluetooth.L2CAPConnectionNotifier
  */
 public static Connection open(String url) throws IOException {
   try {
     if (url.startsWith("btl2cap://localhost:")) {
       int endIndex = url.indexOf(';');
       String psmString = url.substring(20, endIndex);
       Short psmShort = Short.decode(psmString);
       short psm = psmShort.shortValue();
       return new JSR82ConnectionNotifier(psm);
     }
     if (url.startsWith("btl2cap://")) {
       byte[] bdAddrBytes = new byte[12];
       String bdAddrString = url.substring(10, 22);
       Long bdAddrLong = Long.decode("0x" + bdAddrString);
       long remoteAddrLong = bdAddrLong.longValue();
       int endIndex = url.indexOf(';', 22);
       String psmString = url.substring(23, endIndex);
       Short psmShort = Short.decode(psmString);
       short psm = psmShort.shortValue();
       BluetoothStack bluetooth = BluetoothStack.getBluetoothStack();
       LocalDevice localDev = LocalDevice.getLocalDevice();
       DiscoveryAgent discovery = localDev.getDiscoveryAgent();
       RemoteDevice remoteDevice = discovery.getRemoteDevice(remoteAddrLong);
       if (remoteDevice != null) {
         JSR82Channel channel = new JSR82Channel();
         bluetooth.connectL2CAPChannel(channel, remoteDevice, psm);
         return channel;
       } else throw new IllegalArgumentException("Unable to locate Bluetooth Device.");
     }
   } catch (BluetoothStateException e) {
     throw new IOException("" + e);
   } catch (HCIException e) {
     throw new IOException("" + e);
   }
   throw new IllegalArgumentException(
       "This implementation of Connector only supports btl2cap:// Connections.");
 }