コード例 #1
0
  /**
   * Parses standard hex and sortable url safe base64
   *
   * @param s
   * @param offset
   * @param len
   * @return
   * @see TimeUUIDUtils#toSortableUrlSafeBase64(UUID)
   */
  public static UUID parse(CharSequence s, int offset, int len) {

    // if (!isValid(s, offset, len))
    // throw new IllegalArgumentException("invalid TimeUUID ["
    // + s.subSequence(offset, offset + len) + "]");

    UUID retval = null;
    if (len == 32) {
      long msb = Hex.parseLong(s.subSequence(offset, offset + len));
      long lsb = Hex.parseLong(s.subSequence(offset + 16, offset + 32));
      retval = new UUID(msb, lsb);
    } else if (len == 36) {
      long msb = Hex.parseLong(s.subSequence(offset, offset + len));
      long lsb = Hex.parseLong(s.subSequence(offset + 19, offset + 36));
      retval = new UUID(msb, lsb);
    } else if (len == 22) {
      retval = TimeUUIDUtils.fromSortableUrlSafeBase64(s, offset);
    }

    if (retval == null) {
      throw new IllegalArgumentException(
          "String not in expected format [" + s.subSequence(offset, offset + len) + "]");
    }
    return retval;
  }
コード例 #2
0
ファイル: UUID.java プロジェクト: josephks/akka
 /**
  * Appends a String representation of this object to the given {@link Appendable} object.
  *
  * <p>For reasons I'll probably never understand, Sun has decided to have a number of I/O classes
  * implement Appendable which forced them to destroy an otherwise nice and simple interface with
  * {@link IOException}s.
  *
  * <p>I decided to ignore any possible IOExceptions in this method.
  *
  * @param a the Appendable object, may be <code>null</code>
  * @return an Appendable object, defaults to a {@link StringBuilder} if <code>a</code> is <code>
  *     null</code>
  */
 public Appendable toAppendable(Appendable a) {
   Appendable out = a;
   if (out == null) {
     out = new StringBuilder(36);
   }
   try {
     Hex.append(out, (int) (time >> 32)).append('-');
     Hex.append(out, (short) (time >> 16)).append('-');
     Hex.append(out, (short) time).append('-');
     Hex.append(out, (short) (clockSeqAndNode >> 48)).append('-');
     Hex.append(out, clockSeqAndNode, 12);
   } catch (IOException ex) {
     // What were they thinking?
   }
   return out;
 }
コード例 #3
0
ファイル: UUID.java プロジェクト: josephks/akka
 /**
  * Parses a textual representation of a UUID.
  *
  * <p>No validation is performed. If the {@link CharSequence} is shorter than 36 characters,
  * {@link ArrayIndexOutOfBoundsException}s will be thrown.
  *
  * @param s the {@link CharSequence}, may not be <code>null</code>
  */
 public UUID(CharSequence s) {
   this(Hex.parseLong(s.subSequence(0, 18)), Hex.parseLong(s.subSequence(19, 36)));
 }