List of usage examples for java.lang Long toHexString
public static String toHexString(long i)
From source file:net.unicon.academus.apps.briefcase.Kernel.java
private static String getActualPath(final String path, long factory_id) { // create the directories if they don't exist new File(path).mkdirs(); String hexId = Long.toHexString(factory_id); if (hexId.length() < HASH_LEVELS) for (int i = hexId.length(); i < HASH_LEVELS; i++) hexId = "0" + hexId; String nPath = path;/*from w w w . jav a 2 s . c om*/ for (int i = 0; i < HASH_LEVELS; i++) { nPath = nPath + "/" + hexId.charAt(i); } nPath = nPath + "/fac" + factory_id; new File(nPath).mkdirs(); return nPath; }
From source file:com.mellanox.jxio.EventQueueHandler.java
/** * Constructor of EventQueueHandler//from ww w . j ava2 s. co m * * @param callbacks - - * implementation of Interface EventQueueHandler.Callbacks */ public EventQueueHandler(Callbacks callbacks) { if (LOG.isDebugEnabled()) { LOG.debug("EQH CTOR entry"); } DataFromC dataFromC = new DataFromC(); Bridge.createCtx(this, eventQueueSize, dataFromC); this.eventQueue = dataFromC.eventQueue; this.refToCObject = dataFromC.getPtrCtx(); this.elapsedTime = new ElapsedTimeMeasurement(); this.callbacks = callbacks; this.name = "jxio.EQH[" + Long.toHexString(this.refToCObject) + "]"; this.nameForLog = this.name + ": "; if (LOG.isDebugEnabled()) { LOG.debug(this.toLogString() + "EQH CTOR done"); } }
From source file:com.navercorp.pinpoint.web.vo.AgentActiveThreadDump.java
public String createDumpMessage(TThreadDump threadDump) { // set threadName StringBuilder message = new StringBuilder("\"" + threadDump.getThreadName() + "\""); // set threadId String hexStringThreadId = Long.toHexString(threadId); message.append(" Id=0x" + hexStringThreadId); // set threadState message.append(" " + threadState.name()); if (!StringUtils.isBlank(threadDump.getLockName())) { message.append(" on ").append(threadDump.getLockName()); }//from ww w . ja v a 2s .c o m if (!StringUtils.isBlank(threadDump.getLockOwnerName())) { message.append(" owned by \"").append(threadDump.getLockOwnerName()).append("\" Id=") .append(threadDump.getLockOwnerId()); } if (threadDump.isSuspended()) { message.append(" (suspended)"); } if (threadDump.isInNative()) { message.append(" (in native)"); } message.append(LINE_SEPARATOR); // set StackTrace for (int i = 0; i < threadDump.getStackTraceSize(); i++) { String stackTrace = threadDump.getStackTrace().get(i); message.append(TAB_SEPARATOR + "at ").append(stackTrace); message.append(LINE_SEPARATOR); if (i == 0 && !StringUtils.isBlank(threadDump.getLockName())) { switch (threadState) { case BLOCKED: message.append(TAB_SEPARATOR + "- blocked on ").append(threadDump.getLockName()); message.append(LINE_SEPARATOR); break; case WAITING: message.append(TAB_SEPARATOR + "- waiting on ").append(threadDump.getLockName()); message.append(LINE_SEPARATOR); break; case TIMED_WAITING: message.append(TAB_SEPARATOR + "- waiting on ").append(threadDump.getLockName()); message.append(LINE_SEPARATOR); break; default: } } if (threadDump.getLockedMonitors() != null) { for (TMonitorInfo lockedMonitor : threadDump.getLockedMonitors()) { if (lockedMonitor.getStackDepth() == i) { message.append(TAB_SEPARATOR + "- locked ").append(lockedMonitor.getStackFrame()); message.append(LINE_SEPARATOR); } } } } // set Locks List<String> lockedSynchronizers = threadDump.getLockedSynchronizers(); if (lockedSynchronizers != null) { if (!lockedSynchronizers.isEmpty()) { message.append(LINE_SEPARATOR + TAB_SEPARATOR + "Number of locked synchronizers = ") .append(lockedSynchronizers.size()); message.append(LINE_SEPARATOR); for (String lockedSynchronizer : lockedSynchronizers) { message.append(TAB_SEPARATOR + "- ").append(lockedSynchronizer); message.append(LINE_SEPARATOR); } } } message.append(LINE_SEPARATOR); return message.toString(); }
From source file:org.lilyproject.util.zookeeper.StateWatchingZooKeeper.java
public StateWatchingZooKeeper(String connectString, int sessionTimeout, int startupTimeOut) throws IOException { super(connectString, sessionTimeout); this.requestedSessionTimeout = sessionTimeout; this.sessionTimeout = sessionTimeout; ZooKeeper zk = new ZooKeeper(connectString, sessionTimeout, new MyWatcher()); setDelegate(zk);/* ww w. ja v a2 s . com*/ ready = true; // Wait for connection to come up: if we fail to connect to ZK now, we do not want to continue // starting up the Lily node. long waitUntil = System.currentTimeMillis() + startupTimeOut; int count = 0; while (zk.getState() != CONNECTED && waitUntil > System.currentTimeMillis()) { try { Thread.sleep(100); } catch (InterruptedException e) { break; } count++; if (count == 30) { // Output a message every 3s log.info("Waiting for ZooKeeper connection to be established"); count = 0; } } if (zk.getState() != CONNECTED) { stopping = true; try { zk.close(); } catch (Throwable t) { // ignore } throw new IOException("Failed to connect with Zookeeper within timeout " + startupTimeOut + ", connection string: " + connectString); } log.info("ZooKeeper session ID is 0x" + Long.toHexString(zk.getSessionId())); }
From source file:com.igormaznitsa.mvngolang.GolangMvnInstallMojo.java
@Nonnull private File compressProjectFiles() throws IOException { final Artifact artifact = this.project.getArtifact(); final File resultZip = new File(this.project.getBuild().getDirectory(), artifact.getArtifactId() + '-' + artifact.getVersion() + '.' + artifact.getType()); if (resultZip.isFile() && !resultZip.delete()) { throw new IOException("Can't delete file : " + resultZip); }/*from w ww.j ava 2 s . co m*/ final File folderToPack = new File( ".tmp_pack_folder_" + Long.toHexString(System.currentTimeMillis()).toUpperCase(Locale.ENGLISH)); if (folderToPack.isDirectory()) { FileUtils.deleteDirectory(folderToPack); } if (!folderToPack.mkdirs()) { throw new IOException("Can't create temp folder : " + folderToPack); } try { saveEffectivePom(folderToPack); FileUtils.copyFileToDirectory(this.project.getFile(), folderToPack); safeCopyDirectory(this.project.getBuild().getSourceDirectory(), folderToPack); safeCopyDirectory(this.project.getBuild().getTestSourceDirectory(), folderToPack); for (final Resource res : this.project.getBuild().getResources()) { safeCopyDirectory(res.getDirectory(), folderToPack); } for (final Resource res : this.project.getBuild().getTestResources()) { safeCopyDirectory(res.getDirectory(), folderToPack); } if (getLog().isDebugEnabled()) { getLog().debug(String.format("Packing folder %s to %s", folderToPack.getAbsolutePath(), resultZip.getAbsolutePath())); } ZipUtil.pack(folderToPack, resultZip, Math.min(9, Math.max(1, this.compression))); } finally { FileUtils.deleteQuietly(folderToPack); } return resultZip; }
From source file:org.mitre.math.linear.RandomMatrixExample.java
public String localTmpFile() { long now = System.currentTimeMillis(); return "RandomMatrixExample_" + Long.toHexString(now); }
From source file:com.predic8.membrane.core.http.ChunkedBody.java
protected int getRawLength() throws IOException { if (chunks.isEmpty()) return 0; int length = getLength(); for (Chunk chunk : chunks) { length += Long.toHexString(chunk.getLength()).getBytes(Constants.UTF_8_CHARSET).length; length += 2 * Constants.CRLF_BYTES.length; }/* ww w. j a v a2s. c o m*/ length += "0".getBytes(Constants.UTF_8_CHARSET).length; length += 2 * Constants.CRLF_BYTES.length; return length; }
From source file:com.ngdata.hbaseindexer.util.zookeeper.StateWatchingZooKeeper.java
public StateWatchingZooKeeper(String connectString, int sessionTimeout, int startupTimeOut) throws IOException { this.requestedSessionTimeout = sessionTimeout; this.sessionTimeout = sessionTimeout; ZooKeeper zk = new ZooKeeper(connectString, sessionTimeout, new MyWatcher()); setDelegate(zk);//w w w . ja va2s. co m ready = true; // Wait for connection to come up: if we fail to connect to ZK now, we do not want to continue // starting up the Indexer node. long waitUntil = System.currentTimeMillis() + startupTimeOut; int count = 0; while (zk.getState() != CONNECTED && waitUntil > System.currentTimeMillis()) { try { Thread.sleep(100); } catch (InterruptedException e) { break; } count++; if (count == 30) { // Output a message every 3s log.info("Waiting for ZooKeeper connection to be established"); count = 0; } } if (zk.getState() != CONNECTED) { stopping = true; try { zk.close(); } catch (Throwable t) { // ignore } throw new IOException("Failed to connect with Zookeeper within timeout " + startupTimeOut + ", connection string: " + connectString); } log.info("ZooKeeper session ID is 0x" + Long.toHexString(zk.getSessionId())); }
From source file:count.ly.messaging.ConnectionProcessor.java
URLConnection urlConnectionForEventData(final String eventData) throws IOException { String urlStr = serverURL_ + "/i?"; if (!eventData.contains("&crash=")) urlStr += eventData;/* w w w.ja va 2 s .c o m*/ final URL url = new URL(urlStr); final HttpURLConnection conn; if (Countly.publicKeyPinCertificates == null) { conn = (HttpURLConnection) url.openConnection(); } else { HttpsURLConnection c = (HttpsURLConnection) url.openConnection(); c.setSSLSocketFactory(sslContext_.getSocketFactory()); conn = c; } conn.setConnectTimeout(CONNECT_TIMEOUT_IN_MILLISECONDS); conn.setReadTimeout(READ_TIMEOUT_IN_MILLISECONDS); conn.setUseCaches(false); conn.setDoInput(true); String picturePath = UserData.getPicturePathFromQuery(url); if (Countly.sharedInstance().isLoggingEnabled()) { Log.d(Countly.TAG, "Got picturePath: " + picturePath); } if (!picturePath.equals("")) { //Uploading files: //http://stackoverflow.com/questions/2793150/how-to-use-java-net-urlconnection-to-fire-and-handle-http-requests File binaryFile = new File(picturePath); conn.setDoOutput(true); // Just generate some unique random value. String boundary = Long.toHexString(System.currentTimeMillis()); // Line separator required by multipart/form-data. String CRLF = "\r\n"; String charset = "UTF-8"; conn.setRequestProperty("Content-Type", "multipart/form-data; boundary=" + boundary); OutputStream output = conn.getOutputStream(); PrintWriter writer = new PrintWriter(new OutputStreamWriter(output, charset), true); // Send binary file. writer.append("--" + boundary).append(CRLF); writer.append("Content-Disposition: form-data; name=\"binaryFile\"; filename=\"" + binaryFile.getName() + "\"").append(CRLF); writer.append("Content-Type: " + URLConnection.guessContentTypeFromName(binaryFile.getName())) .append(CRLF); writer.append("Content-Transfer-Encoding: binary").append(CRLF); writer.append(CRLF).flush(); FileInputStream fileInputStream = new FileInputStream(binaryFile); byte[] buffer = new byte[1024]; int len; while ((len = fileInputStream.read(buffer)) != -1) { output.write(buffer, 0, len); } output.flush(); // Important before continuing with writer! writer.append(CRLF).flush(); // CRLF is important! It indicates end of boundary. fileInputStream.close(); // End of multipart/form-data. writer.append("--" + boundary + "--").append(CRLF).flush(); } else if (eventData.contains("&crash=")) { if (Countly.sharedInstance().isLoggingEnabled()) { Log.d(Countly.TAG, "Using post because of crash"); } conn.setDoOutput(true); conn.setRequestMethod("POST"); OutputStream os = conn.getOutputStream(); BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(os, "UTF-8")); writer.write(eventData); writer.flush(); writer.close(); os.close(); } else { conn.setDoOutput(false); } return conn; }
From source file:simpleserver.thread.Statistics.java
private void getSessionId() { WorldFile world = null;//ww w.ja v a 2s . c o m try { world = new WorldFile(server); } catch (Exception ex) { } long seed = world.seed(); JSONObject data = new JSONObject(); JSONObject stats = new JSONObject(); JSONObject options = new JSONObject(); try { data.put("options", options); data.put("stats", stats); data.put("version", Main.version); options.put("jar", server.options.get("alternateJarFile")); options.put("onlineMode", server.config.properties.getBoolean("onlineMode")); options.put("custAuth", server.config.properties.getBoolean("custAuth")); options.put("maxPlayers", server.config.properties.getInt("maxPlayers")); stats.put("registeredPlayers", server.data.players.count()); stats.put("totalHours", server.data.players.stats.totalHours()); JSONObject response = getRemoteJSONObject(data, "connect", Long.toHexString(seed)); id = response.getInt("id"); } catch (Exception e) { run = false; } }