List of usage examples for java.lang Long toHexString
public static String toHexString(long i)
From source file:com.trsst.ui.AppServlet.java
@Override public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException { // FLAG: limit access only to local clients if (restricted && !request.getRemoteAddr().equals(request.getLocalAddr())) { response.sendError(HttpServletResponse.SC_FORBIDDEN, "Non-local clients are not allowed."); return;//from ww w . j av a2s. c om } // in case of any posted files InputStream inStream = null; // determine if supported command: pull, push, post String path = request.getPathInfo(); System.err.println(new Date().toString() + " " + path); if (path != null) { // FLAG: limit only to pull and post if (path.startsWith("/pull/") || path.startsWith("/post")) { // FLAG: we're sending the user's keystore // password over the wire (over SSL) List<String> args = new LinkedList<String>(); if (path.startsWith("/pull/")) { path = path.substring("/pull/".length()); response.setContentType("application/atom+xml; type=feed; charset=utf-8"); // System.out.println("doPull: " + // request.getParameterMap()); args.add("pull"); if (request.getParameterMap().size() > 0) { boolean first = true; for (Object name : request.getParameterMap().keySet()) { // FLAG: don't allow "home" (server-abuse) // FLAG: don't allow "attach" (file-system access) if ("decrypt".equals(name) || "pass".equals(name)) { for (String value : request.getParameterValues(name.toString())) { args.add("--" + name.toString()); args.add(value); } } else { for (String value : request.getParameterValues(name.toString())) { if (first) { path = path + '?'; first = false; } else { path = path + '&'; } path = path + name + '=' + value; } } } } args.add(path); } else if (path.startsWith("/post")) { // System.out.println("doPost: " + // request.getParameterMap()); args.add("post"); try { // h/t http://stackoverflow.com/questions/2422468 List<FileItem> items = new ServletFileUpload(new DiskFileItemFactory()) .parseRequest(request); for (FileItem item : items) { if (item.isFormField()) { // process regular form field String name = item.getFieldName(); String value = item.getString("UTF-8").trim(); // System.out.println("AppServlet: " + name // + " : " + value); if (value.length() > 0) { // FLAG: don't allow "home" (server-abuse) // FLAG: don't allow "attach" (file-system // access) if ("id".equals(name)) { if (value.startsWith("urn:feed:")) { value = value.substring("urn:feed:".length()); } args.add(value); } else if (!"home".equals(name) && !"attach".equals(name)) { args.add("--" + name); args.add(value); } } else { log.debug("Empty form value for name: " + name); } } else if (item.getSize() > 0) { // process form file field (input type="file"). // String filename = FilenameUtils.getName(item // .getName()); if (item.getSize() > 1024 * 1024 * 10) { throw new FileUploadException("Current maximum upload size is 10MB"); } String name = item.getFieldName(); if ("icon".equals(name) || "logo".equals(name)) { args.add("--" + name); args.add("-"); } inStream = item.getInputStream(); // NOTE: only handles one file! } else { log.debug("Ignored form field: " + item.getFieldName()); } } } catch (FileUploadException e) { response.sendError(HttpServletResponse.SC_BAD_REQUEST, "Could not parse multipart request: " + e); return; } } // send post data if any to command input stream if (inStream != null) { args.add("--attach"); } //System.out.println(args); // make sure we don't create another local server args.add("--host"); args.add(request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + "/feed"); PrintStream outStream = new PrintStream(response.getOutputStream(), false, "UTF-8"); int result = new Command().doBegin(args.toArray(new String[0]), outStream, inStream); if (result != 0) { response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Internal error code: " + result); } else { outStream.flush(); } return; } // otherwise: determine if static resource request if (path.startsWith("/")) { path = path.substring(1); } byte[] result = resources.get(path); String mimetype = null; if (result == null) { // if ("".equals(path) || path.endsWith(".html")) { // treat all html requests with index doc result = resources.get("index.html"); mimetype = "text/html"; // } } if (result != null) { if (mimetype == null) { if (path.endsWith(".html")) { mimetype = "text/html"; } else if (path.endsWith(".css")) { mimetype = "text/css"; } else if (path.endsWith(".js")) { mimetype = "application/javascript"; } else if (path.endsWith(".png")) { mimetype = "image/png"; } else if (path.endsWith(".jpg")) { mimetype = "image/jpeg"; } else if (path.endsWith(".jpeg")) { mimetype = "image/jpeg"; } else if (path.endsWith(".gif")) { mimetype = "image/gif"; } else { mimetype = new Tika().detect(result); } } if (request.getHeader("If-None-Match:") != null) { // client should always use cached version log.info("sending 304"); response.setStatus(304); // Not Modified return; } // otherwise allow ETag/If-None-Match response.setHeader("ETag", Long.toHexString(path.hashCode())); if (mimetype != null) { response.setContentType(mimetype); } response.setContentLength(result.length); response.getOutputStream().write(result); return; } } // // otherwise: 404 Not Found // response.sendError(HttpServletResponse.SC_NOT_FOUND); }
From source file:org.dspace.identifier.DOIIdentifierProviderTest.java
@Test public void testGet_DOI_out_of_item_metadata() throws SQLException, AuthorizeException, IOException, IdentifierException, IllegalAccessException, WorkflowException { Item item = newItem();/*from w w w. j a va2s . com*/ String doi = DOI.SCHEME + PREFIX + "/" + NAMESPACE_SEPARATOR + Long.toHexString(new Date().getTime()); context.turnOffAuthorisationSystem(); itemService.addMetadata(context, item, DOIIdentifierProvider.MD_SCHEMA, DOIIdentifierProvider.DOI_ELEMENT, DOIIdentifierProvider.DOI_QUALIFIER, null, doiService.DOIToExternalForm(doi)); itemService.update(context, item); context.restoreAuthSystemState(); assertTrue("Failed to recognize DOI in item metadata.", doi.equals(provider.getDOIOutOfObject(item))); }
From source file:org.apache.james.mime4j.util.MimeUtil.java
/** * Creates a new unique message boundary string that can be used as boundary * parameter for the Content-Type header field of a message. * //from w ww . j av a 2 s . com * @return a new unique message boundary string. */ public static String createUniqueBoundary() { StringBuffer sb = new StringBuffer(); sb.append("-=Part."); sb.append(Integer.toHexString(nextCounterValue())); sb.append('.'); sb.append(Long.toHexString(random.nextLong())); sb.append('.'); sb.append(Long.toHexString(System.currentTimeMillis())); sb.append('.'); sb.append(Long.toHexString(random.nextLong())); sb.append("=-"); return sb.toString(); }
From source file:com.gitblit.tests.TicketServiceTest.java
@Test public void testPriorityAndSeverity() throws Exception { // C1: create and insert a ticket Change c1 = newChange("testPriorityAndSeverity() " + Long.toHexString(System.currentTimeMillis())); TicketModel ticket = service.createTicket(getRepository(), c1); assertTrue(ticket.number > 0);//from w w w . j a v a 2s. c o m assertEquals(TicketModel.Priority.Normal, ticket.priority); assertEquals(TicketModel.Severity.Unrated, ticket.severity); TicketModel constructed = service.getTicket(getRepository(), ticket.number); compare(ticket, constructed); // C2: Change Priority max Change c2 = new Change("C2"); c2.setField(Field.priority, TicketModel.Priority.Urgent); constructed = service.updateTicket(getRepository(), ticket.number, c2); assertNotNull(constructed); assertEquals(2, constructed.changes.size()); assertEquals(TicketModel.Priority.Urgent, constructed.priority); assertEquals(TicketModel.Severity.Unrated, constructed.severity); // C3: Change Severity max Change c3 = new Change("C3"); c3.setField(Field.severity, TicketModel.Severity.Catastrophic); constructed = service.updateTicket(getRepository(), ticket.number, c3); assertNotNull(constructed); assertEquals(3, constructed.changes.size()); assertEquals(TicketModel.Priority.Urgent, constructed.priority); assertEquals(TicketModel.Severity.Catastrophic, constructed.severity); // C4: Change Priority min Change c4 = new Change("C3"); c4.setField(Field.priority, TicketModel.Priority.Low); constructed = service.updateTicket(getRepository(), ticket.number, c4); assertNotNull(constructed); assertEquals(4, constructed.changes.size()); assertEquals(TicketModel.Priority.Low, constructed.priority); assertEquals(TicketModel.Severity.Catastrophic, constructed.severity); }
From source file:com.mellanox.jxio.EventQueueHandler.java
void addEventable(Eventable eventable) { if (LOG.isDebugEnabled()) { LOG.debug(this.toLogString() + "adding " + Long.toHexString(eventable.getId()) + " to map"); }//from ww w . ja v a 2 s .c o m // add lock synchronized (eventables) { if (eventable.getId() != 0) { eventables.put(eventable.getId(), eventable); } } }
From source file:net.wastl.webmail.server.WebMailServer.java
public static String generateMessageID(String user) { long time = System.currentTimeMillis(); String msgid = Long.toHexString(time) + ".JavaWebMail." + VERSION + "." + user; try {/*from w w w . j av a 2s . c o m*/ msgid += "@" + InetAddress.getLocalHost().getHostName(); } catch (Exception ex) { } return msgid; }
From source file:org.springframework.cloud.sleuth.annotation.SleuthSpanCreatorAspectFluxTests.java
private static String toHexString(long value) { return StringUtils.leftPad(Long.toHexString(value), 16, '0'); }
From source file:com.hichinaschool.flashcards.libanki.Utils.java
/** * IDs//from www .j a v a2 s. com * *********************************************************************************************** */ public static String hexifyID(long id) { return Long.toHexString(id); }
From source file:org.dspace.identifier.DOIIdentifierProviderTest.java
@Test public void testRemove_DOI_from_item_metadata() throws SQLException, AuthorizeException, IOException, IdentifierException, WorkflowException, IllegalAccessException { Item item = newItem();//from ww w. ja v a 2 s .c o m String doi = DOI.SCHEME + PREFIX + "/" + NAMESPACE_SEPARATOR + Long.toHexString(new Date().getTime()); context.turnOffAuthorisationSystem(); itemService.addMetadata(context, item, DOIIdentifierProvider.MD_SCHEMA, DOIIdentifierProvider.DOI_ELEMENT, DOIIdentifierProvider.DOI_QUALIFIER, null, doiService.DOIToExternalForm(doi)); itemService.update(context, item); provider.removeDOIFromObject(context, item, doi); context.restoreAuthSystemState(); List<MetadataValue> metadata = itemService.getMetadata(item, DOIIdentifierProvider.MD_SCHEMA, DOIIdentifierProvider.DOI_ELEMENT, DOIIdentifierProvider.DOI_QUALIFIER, null); boolean foundDOI = false; for (MetadataValue id : metadata) { if (id.getValue().equals(doiService.DOIToExternalForm(doi))) { foundDOI = true; } } assertFalse("Cannot remove DOI from item metadata.", foundDOI); }
From source file:com.alibaba.wasp.zookeeper.ZooKeeperWatcher.java
/** * Called when there is a connection-related event via the Watcher callback. * <p>/*from w w w .j ava 2s. c o m*/ * If Disconnected or Expired, this should shutdown the cluster. But, since we * send a KeeperException.SessionExpiredException along with the abort call, * it's possible for the Abortable to catch it and try to create a new session * with ZooKeeper. This is what the client does in HCM. * <p> * @param event */ private void connectionEvent(WatchedEvent event) { switch (event.getState()) { case SyncConnected: // Now, this callback can be invoked before the this.zookeeper is set. // Wait a little while. long finished = System.currentTimeMillis() + this.conf.getLong("hbase.zookeeper.watcher.sync.connected.wait", 2000); while (System.currentTimeMillis() < finished) { Threads.sleep(1); if (this.recoverableZooKeeper != null) break; } if (this.recoverableZooKeeper == null) { LOG.error( "ZK is null on connection event -- see stack trace " + "for the stack trace when constructor was called on this zkw", this.constructorCaller); throw new NullPointerException("ZK is null"); } this.identifier = this.identifier + "-0x" + Long.toHexString(this.recoverableZooKeeper.getSessionId()); // Update our identifier. Otherwise ignore. LOG.debug(this.identifier + " connected"); break; case AuthFailed: if (ZKUtil.isSecureZooKeeper(this.conf)) { // We could not be authenticated, but clients should proceed anyway. // Only access to znodes that require SASL authentication will be // denied. The client may never need to access them. saslLatch.countDown(); } break; // Abort the server if Disconnected or Expired case Disconnected: LOG.debug(prefix("Received Disconnected from ZooKeeper, ignoring")); break; case Expired: if (ZKUtil.isSecureZooKeeper(this.conf)) { // We consider Expired equivalent to AuthFailed for this // connection. Authentication is never going to complete. The // client should proceed to do cleanup. saslLatch.countDown(); } String msg = prefix(this.identifier + " received expired from " + "ZooKeeper, aborting"); // TODO: One thought is to add call to ZooKeeperListener so say, // ZooKeeperNodeTracker can zero out its data values. if (this.abortable != null) this.abortable.abort(msg, new KeeperException.SessionExpiredException()); break; default: throw new IllegalStateException("Received event is not valid."); } }