private static String generateToken() {
   final StringBuilder builder = new StringBuilder(260);
   while (builder.length() < 256) {
     builder.append(Long.toHexString(TOKEN_GENERATOR.nextLong()));
   }
   return builder.substring(0, 256);
 }
  public String getCompUniqueID() {
    UUID tempID = null;
    long longID = 0L;
    StringBuffer result = new StringBuffer();

    tempID = getId();

    result.append(Long.toHexString(tempID.getMostSignificantBits()));
    result.append(Long.toHexString(tempID.getLeastSignificantBits()));
    return result.toString();
  }
Example #3
0
 /**
  * @param file
  * @return
  * @throws IOException
  */
 static long readUnsignedLong(final ERandomAccessFile file) throws IOException {
   final long result = file.readLongE();
   if (result < 0) {
     throw new IOException(
         "Maximal file offset is "
             + Long.toHexString(Long.MAX_VALUE)
             + " given offset is "
             + Long.toHexString(result));
   }
   return result;
 }
  public String getCompUniqueID() {
    UUID tempID = null;
    long longID = 0L;
    StringBuffer result = new StringBuffer();

    tempID = getArg_id();

    if (IdAssigner.NULL_UUID.equals(tempID)) tempID = getArg_idCachedValue();
    result.append(Long.toHexString(tempID.getMostSignificantBits()));
    result.append(Long.toHexString(tempID.getLeastSignificantBits()));
    return result.toString();
  }
Example #5
0
 /**
  * @param ipV4Text - ip v4 address e.g. 10.0.10.1
  * @return
  */
 String convertIPtoBin(String ipV4Text) {
   String[] addrArray = ipV4Text.split("\\.");
   long num = 0;
   for (int i = 0; i < addrArray.length; i++) {
     System.out.println("(" + i + ") " + addrArray[i]);
     int power = 3 - i;
     num += ((Integer.parseInt(addrArray[i]) % 256 * Math.pow(256, power)));
   }
   System.out.println("ip: " + ipV4Text + " = " + num + ";  0x" + Long.toHexString(num));
   return Long.toHexString(
       num); // do not prefix "0x", leave it at Seagull script as extra syntax will be required
             // e.g. 0x0001[ip]
 }
Example #6
0
 public void dispatchEvent(XEvent ev) {
   super.dispatchEvent(ev);
   switch (ev.get_type()) {
     case XConstants.CreateNotify:
       XCreateWindowEvent cr = ev.get_xcreatewindow();
       if (xembedLog.isLoggable(PlatformLogger.FINEST)) {
         xembedLog.finest("Message on embedder: " + cr);
       }
       if (xembedLog.isLoggable(PlatformLogger.FINER)) {
         xembedLog.finer(
             "Create notify for parent "
                 + Long.toHexString(cr.get_parent())
                 + ", window "
                 + Long.toHexString(cr.get_window()));
       }
       embedChild(cr.get_window());
       break;
     case XConstants.DestroyNotify:
       XDestroyWindowEvent dn = ev.get_xdestroywindow();
       if (xembedLog.isLoggable(PlatformLogger.FINEST)) {
         xembedLog.finest("Message on embedder: " + dn);
       }
       if (xembedLog.isLoggable(PlatformLogger.FINER)) {
         xembedLog.finer("Destroy notify for parent: " + dn);
       }
       childDestroyed();
       break;
     case XConstants.ReparentNotify:
       XReparentEvent rep = ev.get_xreparent();
       if (xembedLog.isLoggable(PlatformLogger.FINEST)) {
         xembedLog.finest("Message on embedder: " + rep);
       }
       if (xembedLog.isLoggable(PlatformLogger.FINER)) {
         xembedLog.finer(
             "Reparent notify for parent "
                 + Long.toHexString(rep.get_parent())
                 + ", window "
                 + Long.toHexString(rep.get_window())
                 + ", event "
                 + Long.toHexString(rep.get_event()));
       }
       if (rep.get_parent() == getWindow()) {
         // Reparented into us - embed it
         embedChild(rep.get_window());
       } else {
         // Reparented out of us - detach it
         childDestroyed();
       }
       break;
   }
 }
Example #7
0
 public void addFile(String name, String file) throws IOException {
   if (boundary == null) {
     boundary =
         Long.toHexString(System.currentTimeMillis()); // Just generate some unique random value.
   }
   files.put(name, file);
 }
Example #8
0
  private String fetchInstanceID(final LocalDB localDB, final PwmApplication pwmApplication) {
    String newInstanceID =
        pwmApplication.getConfig().readSettingAsString(PwmSetting.PWM_INSTANCE_NAME);

    if (newInstanceID != null && newInstanceID.trim().length() > 0) {
      return newInstanceID;
    }

    newInstanceID = readAppAttribute(AppAttribute.INSTANCE_ID);

    if (newInstanceID == null || newInstanceID.length() < 1) {
      newInstanceID = Long.toHexString(PwmRandom.getInstance().nextLong()).toUpperCase();
      LOGGER.info("generated new random instanceID " + newInstanceID);

      if (localDB != null) {
        writeAppAttribute(AppAttribute.INSTANCE_ID, newInstanceID);
      }
    } else {
      LOGGER.trace("retrieved instanceID " + newInstanceID + "" + " from localDB");
    }

    if (newInstanceID.length() < 1) {
      newInstanceID = DEFAULT_INSTANCE_ID;
    }

    return newInstanceID;
  }
 protected ResponseEntity<String> checkStateOfTheTraceId(long traceId) {
   URI uri = URI.create(getZipkinTraceQueryUrl() + Long.toHexString(traceId));
   log.info(
       "Sending request to the Zipkin query service [{}]. Checking presence of trace id [{}]",
       uri,
       traceId);
   return exchangeRequest(uri);
 }
 public void xRequestFocus() {
   XToolkit.awtLock();
   try {
     if (focusLog.isLoggable(Level.FINER))
       focusLog.finer("XSetInputFocus on " + Long.toHexString(getWindow()));
     XlibWrapper.XSetInputFocus(XToolkit.getDisplay(), getWindow());
   } finally {
     XToolkit.awtUnlock();
   }
 }
Example #11
0
 protected File createTempFile(String prefex, File dir) {
   long t = System.currentTimeMillis();
   File f = null;
   do {
     String fn = prefex + Long.toHexString(t);
     t = t + 1;
     f = new File(dir, fn);
   } while (f.exists());
   return f;
 }
Example #12
0
 void endDispatching() {
   xembedLog.fine("End dispatching for " + Long.toHexString(xembed.handle));
   XToolkit.awtLock();
   try {
     XDropTargetRegistry.getRegistry().unregisterXEmbedClient(getWindow(), xembed.handle);
     // We can't deselect input since someone else might be interested in it
     XToolkit.removeEventDispatcher(xembed.handle, xembed);
   } finally {
     XToolkit.awtUnlock();
   }
 }
 private void markAndTraverse(OopHandle handle) {
   try {
     markAndTraverse(heap.newOop(handle));
   } catch (AddressException e) {
     System.err.println(
         "RevPtrs analysis: WARNING: AddressException at 0x"
             + Long.toHexString(e.getAddress())
             + " while traversing oop at "
             + handle);
   } catch (UnknownOopException e) {
     System.err.println(
         "RevPtrs analysis: WARNING: UnknownOopException for " + "oop at " + handle);
   }
 }
Example #14
0
  public static void main(String[] args) throws Exception {
    if (args.length != 1) {
      System.err.println("Usage: test file");
      System.exit(1);
    }
    File f = new File(args[0]);
    // First: read just keys
    System.out.println("Loading keys...");
    KeyEntry[] entries = shuffleEntries(loadKeys(f, KEY_SAMPLING_RATIO));
    // Then build tries
    System.out.println("Building raw trie data...");
    VIntValueReader kr = new VIntValueReader(f);
    SimpleVIntTrieBuilder b = new SimpleVIntTrieBuilder(kr);
    // To re-order or not? Reordering increases speed by ~10%:
    final boolean REORDER = true;
    System.out.println("Reorder entries: " + REORDER);
    b.setReorderEntries(REORDER);
    byte[] rawTrie = b.build().serialize();
    b = null; // just ensure we can GC interemediate stuff
    TrieLookup<Long> arrayBased = new ByteArrayVIntTrieLookup(rawTrie);
    ByteBuffer buffer = ByteBuffer.allocateDirect((int) rawTrie.length);
    System.out.println("ByteBuffer: is-direct? " + buffer.isDirect());
    buffer.put(rawTrie);

    TrieLookup<Long> bufferBased = new ByteBufferVIntTrieLookup(buffer, rawTrie.length);
    VIntSpeedTest test = new VIntSpeedTest(entries);
    for (int i = 0; true; ++i) {
      long start = System.currentTimeMillis();
      TrieLookup<Long> trie;
      switch (i % 2) {
        case 1:
          trie = bufferBased;
          break;
        default:
          trie = arrayBased;
      }
      long result = test.test(trie);
      long time = System.currentTimeMillis() - start;
      System.out.println(
          "Took "
              + time
              + " msecs for "
              + trie.getClass()
              + " (result "
              + Long.toHexString(result)
              + ")");
      Thread.sleep(100L);
    }
  }
 @Override
 public void meet(BNodeGenerator gen) throws RuntimeException {
   if (gen.getNodeIdExpr() != null) {
     // get value of argument and express it as string
     optypes.push(ValueType.STRING);
     gen.getNodeIdExpr().visit(this);
     optypes.pop();
   } else {
     builder
         .append("'")
         .append(
             Long.toHexString(System.currentTimeMillis())
                 + Integer.toHexString(anonIdGenerator.nextInt(1000)))
         .append("'");
   }
 }
Example #16
0
 public String getName() {
   if (name != null) {
     return name;
   } else {
     CompilerDirectives.transferToInterpreter();
     if (givenBaseName != null) {
       return Layouts.MODULE.getFields(lexicalParent).getName() + "::" + givenBaseName;
     } else if (getLogicalClass()
         == rubyModuleObject) { // For the case of class Class during initialization
       return "#<cyclic>";
     } else {
       return "#<"
           + Layouts.MODULE.getFields(getLogicalClass()).getName()
           + ":0x"
           + Long.toHexString(ObjectIDOperations.verySlowGetObjectID(rubyModuleObject))
           + ">";
     }
   }
 }
Example #17
0
  void initDispatching() {
    if (xembedLog.isLoggable(PlatformLogger.FINE))
      xembedLog.fine("Init embedding for " + Long.toHexString(xembed.handle));
    XToolkit.awtLock();
    try {
      XToolkit.addEventDispatcher(xembed.handle, xembed);
      XlibWrapper.XSelectInput(
          XToolkit.getDisplay(),
          xembed.handle,
          XConstants.StructureNotifyMask | XConstants.PropertyChangeMask);

      XDropTargetRegistry.getRegistry().registerXEmbedClient(getWindow(), xembed.handle);
    } finally {
      XToolkit.awtUnlock();
    }
    xembed.processXEmbedInfo();

    notifyChildEmbedded();
  }
Example #18
0
  /** creates new file */
  public GlyphFile(File a_dir, String a_name, long a_unicode) throws FileNotFoundException {
    super();

    m_fileName = createFileName(a_dir, a_name);

    init(getClass().getResource(s_emptyFileName));
    setGlyphTitle(a_name);
    setUnicode(Long.toHexString(a_unicode));

    /*int eastAsianWidth = UCharacter.getIntPropertyValue(
    (int) a_unicode,
    0x1004); //UProperty.EAST_ASIAN_WIDTH);
         */
    int eastAsianWidth = 5; // ??
    if (eastAsianWidth == 5 || eastAsianWidth == 1) {
      setAdvanceWidth(k_fullWidth);
    } // if

    saveGlyphFile();
  }
Example #19
0
 void detachChild() {
   if (xembedLog.isLoggable(PlatformLogger.FINE))
     xembedLog.fine("Detaching child " + Long.toHexString(xembed.handle));
   /**
    * XEmbed specification: "The embedder can unmap the client and reparent the client window to
    * the root window. If the client receives an ReparentNotify event, it should check the parent
    * field of the XReparentEvent structure. If this is the root window of the window's screen,
    * then the protocol is finished and there is no further interaction. If it is a window other
    * than the root window, then the protocol continues with the new parent acting as the embedder
    * window."
    */
   XToolkit.awtLock();
   try {
     XlibWrapper.XUnmapWindow(XToolkit.getDisplay(), xembed.handle);
     XlibWrapper.XReparentWindow(
         XToolkit.getDisplay(), xembed.handle, XToolkit.getDefaultRootWindow(), 0, 0);
   } finally {
     XToolkit.awtUnlock();
   }
   endDispatching();
   xembed.handle = 0;
 }
Example #20
0
    List<String> calc(String str_date) {
      long myDateMillis = 0;
      long d1900 = 0;
      Date myDate = null;
      List<String> ls = new ArrayList<String>();
      try {

        myDate = parseDate(str_date);
        System.out.println(printDate(myDate) + " // orig date");
        //
        Calendar cal = Calendar.getInstance();

        cal.setTime(myDate);
        cal.add(Calendar.HOUR, -5);
        cal.add(Calendar.MINUTE, -30);
        myDate = cal.getTime(); // Update date to -5:30
        //
        Calendar c = Calendar.getInstance();
        c.clear();
        c.setTimeZone(TimeZone.getTimeZone("GMT"));
        c.set(1900, 0, 1, 0, 0, 0);
        d1900 = c.getTimeInMillis();
        System.out.println(printDate(c.getTime()) + " // 1900");

        for (int i = 0; i < 10; i++) {
          long durInSec = (cal.getTimeInMillis() - d1900) / 1000;
          String durInSecHex = Long.toHexString(durInSec);
          System.out.println(printDate(cal.getTime()) + " " + durInSec + " " + durInSecHex);
          ls.add(durInSecHex);
          cal.add(Calendar.SECOND, +50);
        }

      } catch (ParseException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }
      return ls;
    } // DateCalc constructor
Example #21
0
  private String substitute(String spec, long n) throws IOException {
    boolean escaped = false;
    byte[] str = spec.getBytes();
    StringBuffer sb = new StringBuffer();

    for (int i = 0; i < str.length; i++) {
      char c = (char) (str[i] & 0xFF);
      if (escaped) {
        sb.append(c);
        escaped = false;
      } else if (c == '\\') {
        if (i + 1 == str.length) throw new TextParseException("invalid escape character");
        escaped = true;
      } else if (c == '$') {
        boolean negative = false;
        long offset = 0;
        long width = 0;
        long base = 10;
        boolean wantUpperCase = false;
        if (i + 1 < str.length && str[i + 1] == '$') {
          // '$$' == literal '$' for backwards
          // compatibility with old versions of BIND.
          c = (char) (str[++i] & 0xFF);
          sb.append(c);
          continue;
        } else if (i + 1 < str.length && str[i + 1] == '{') {
          // It's a substitution with modifiers.
          i++;
          if (i + 1 < str.length && str[i + 1] == '-') {
            negative = true;
            i++;
          }
          while (i + 1 < str.length) {
            c = (char) (str[++i] & 0xFF);
            if (c == ',' || c == '}') break;
            if (c < '0' || c > '9') throw new TextParseException("invalid offset");
            c -= '0';
            offset *= 10;
            offset += c;
          }
          if (negative) offset = -offset;

          if (c == ',') {
            while (i + 1 < str.length) {
              c = (char) (str[++i] & 0xFF);
              if (c == ',' || c == '}') break;
              if (c < '0' || c > '9') throw new TextParseException("invalid width");
              c -= '0';
              width *= 10;
              width += c;
            }
          }

          if (c == ',') {
            if (i + 1 == str.length) throw new TextParseException("invalid base");
            c = (char) (str[++i] & 0xFF);
            if (c == 'o') base = 8;
            else if (c == 'x') base = 16;
            else if (c == 'X') {
              base = 16;
              wantUpperCase = true;
            } else if (c != 'd') throw new TextParseException("invalid base");
          }

          if (i + 1 == str.length || str[i + 1] != '}')
            throw new TextParseException("invalid modifiers");
          i++;
        }
        long v = n + offset;
        if (v < 0) throw new TextParseException("invalid offset expansion");
        String number;
        if (base == 8) number = Long.toOctalString(v);
        else if (base == 16) number = Long.toHexString(v);
        else number = Long.toString(v);
        if (wantUpperCase) number = number.toUpperCase();
        if (width != 0 && width > number.length()) {
          int zeros = (int) width - number.length();
          while (zeros-- > 0) sb.append('0');
        }
        sb.append(number);
      } else {
        sb.append(c);
      }
    }
    return sb.toString();
  }
Example #22
0
 public static final String toHex(long addr) {
   return "0x" + Long.toHexString(addr);
 }
Example #23
0
 /**
  * converts a long value to a hexadecimal String
  *
  * @param value the long value to be converted
  * @return the hexadecimal string representation of the long value
  */
 public static String toHexString(long value) {
   return Long.toHexString(value);
 }
Example #24
0
 void childDestroyed() {
   xembedLog.fine("Child " + Long.toHexString(xembed.handle) + " has self-destroyed.");
   endDispatching();
   xembed.handle = 0;
 }
  /** Throws an exception if the blocks difficulty is not correct. */
  private void checkDifficultyTransitions(StoredBlock storedPrev, StoredBlock storedNext)
      throws BlockStoreException, VerificationException {
    Block prev = storedPrev.getHeader();
    Block next = storedNext.getHeader();
    // Is this supposed to be a difficulty transition point?
    if ((storedPrev.getHeight() + 1) % params.interval != 0) {
      // No ... so check the difficulty didn't actually change.
      if (next.getDifficultyTarget() != prev.getDifficultyTarget())
        throw new VerificationException(
            "Unexpected change in difficulty at height "
                + storedPrev.getHeight()
                + ": "
                + Long.toHexString(next.getDifficultyTarget())
                + " vs "
                + Long.toHexString(prev.getDifficultyTarget()));
      return;
    }

    // We need to find a block far back in the chain. It's OK that this is expensive because it only
    // occurs every
    // two weeks after the initial block chain download.
    long now = System.currentTimeMillis();
    StoredBlock cursor = blockStore.get(prev.getHash());
    for (int i = 0; i < params.interval - 1; i++) {
      if (cursor == null) {
        // This should never happen. If it does, it means we are following an incorrect or busted
        // chain.
        throw new VerificationException(
            "Difficulty transition point but we did not find a way back to the genesis block.");
      }
      cursor = blockStore.get(cursor.getHeader().getPrevBlockHash());
    }
    log.info("Difficulty transition traversal took {}msec", System.currentTimeMillis() - now);

    Block blockIntervalAgo = cursor.getHeader();
    int timespan = (int) (prev.getTime() - blockIntervalAgo.getTime());
    // Limit the adjustment step.
    if (timespan < params.targetTimespan / 4) timespan = params.targetTimespan / 4;
    if (timespan > params.targetTimespan * 4) timespan = params.targetTimespan * 4;

    BigInteger newDifficulty = Utils.decodeCompactBits(blockIntervalAgo.getDifficultyTarget());
    newDifficulty = newDifficulty.multiply(BigInteger.valueOf(timespan));
    newDifficulty = newDifficulty.divide(BigInteger.valueOf(params.targetTimespan));

    if (newDifficulty.compareTo(params.proofOfWorkLimit) > 0) {
      log.warn("Difficulty hit proof of work limit: {}", newDifficulty.toString(16));
      newDifficulty = params.proofOfWorkLimit;
    }

    int accuracyBytes = (int) (next.getDifficultyTarget() >>> 24) - 3;
    BigInteger receivedDifficulty = next.getDifficultyTargetAsInteger();

    // The calculated difficulty is to a higher precision than received, so reduce here.
    BigInteger mask = BigInteger.valueOf(0xFFFFFFL).shiftLeft(accuracyBytes * 8);
    newDifficulty = newDifficulty.and(mask);

    if (newDifficulty.compareTo(receivedDifficulty) != 0)
      throw new VerificationException(
          "Network provided difficulty bits do not match what was calculated: "
              + receivedDifficulty.toString(16)
              + " vs "
              + newDifficulty.toString(16));
  }