List of usage examples for java.lang Long toString
public String toString()
From source file:edu.ucsd.crbs.cws.App.java
License:asdf
public static void getWorkflowAsJson(OptionSet optionSet) throws Exception { WorkflowRestDAOImpl workflowDAO = new WorkflowRestDAOImpl(); workflowDAO.setRestURL((String) optionSet.valueOf(URL_ARG)); User u = getUserFromOptionSet(optionSet); workflowDAO.setUser(u);//from www . j av a 2 s . c o m Long wfid = (Long) optionSet.valueOf(GET_WORKFLOW_ARG); Workflow w = workflowDAO.getWorkflowById(wfid.toString(), u); if (w != null) { ObjectMapper om = new ObjectMapper(); ObjectWriter ow = om.writerWithDefaultPrettyPrinter(); System.out.println(ow.writeValueAsString(w)); } else { System.err.println("Unable to retreive WorkspaceFile with id: " + wfid.toString()); System.exit(1); } }
From source file:org.flite.cach3.test.l2.L2ReadThroughSingleTest.java
@Test public void test() { final TestSvc test = (TestSvc) context.getBean("testSvc"); final String g1 = RandomStringUtils.randomAlphabetic(4) + "-"; final List<Long> ids = new ArrayList<Long>(); final long base = System.currentTimeMillis() - 200000; for (int ix = 0; ix < 10; ix++) { final long id = base + ix; ids.add(id);//ww w. j av a2 s . c o m assertTrue(test.getL2SingleDelta(id, g1).startsWith(g1)); } final String g2 = RandomStringUtils.randomAlphabetic(6) + "-"; final List<Long> addls = new ArrayList<Long>(); addls.addAll(ids); for (int ix = 0; ix < 10; ix++) { addls.add(1000L + ix); } Collections.shuffle(addls); final List<String> results = test.getL2MultiAlpha(addls, g2); for (int ix = 0; ix < addls.size(); ix++) { final Long key = addls.get(ix); final String result = results.get(ix); System.out.println(result); assertTrue(StringUtils.contains(result, key.toString())); assertTrue(result.startsWith(ids.contains(key) ? g1 : g2)); } }
From source file:com.example.getstarted.basicactions.CreateBookServlet.java
@Override public void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { assert ServletFileUpload.isMultipartContent(req); CloudStorageHelper storageHelper = (CloudStorageHelper) getServletContext().getAttribute("storageHelper"); String newImageUrl = null;//from w ww.j a v a 2 s. c o m Map<String, String> params = new HashMap<String, String>(); try { FileItemIterator iter = new ServletFileUpload().getItemIterator(req); while (iter.hasNext()) { FileItemStream item = iter.next(); if (item.isFormField()) { params.put(item.getFieldName(), Streams.asString(item.openStream())); } else if (!Strings.isNullOrEmpty(item.getName())) { newImageUrl = storageHelper.uploadFile(item, getServletContext().getInitParameter("bookshelf.bucket")); } } } catch (FileUploadException e) { throw new IOException(e); } String createdByString = ""; String createdByIdString = ""; HttpSession session = req.getSession(); if (session.getAttribute("userEmail") != null) { // Does the user have a logged in session? createdByString = (String) session.getAttribute("userEmail"); createdByIdString = (String) session.getAttribute("userId"); } Book book = new Book.Builder().author(params.get("author")).description(params.get("description")) .publishedDate(params.get("publishedDate")).title(params.get("title")) .imageUrl(null == newImageUrl ? params.get("imageUrl") : newImageUrl).createdBy(createdByString) .createdById(createdByIdString).build(); BookDao dao = (BookDao) this.getServletContext().getAttribute("dao"); try { Long id = dao.createBook(book); logger.log(Level.INFO, "Created book {0}", book); resp.sendRedirect("/read?id=" + id.toString()); // read what we just wrote } catch (Exception e) { throw new ServletException("Error creating book", e); } }
From source file:org.telegram.telegrambots.api.methods.games.SetGameScore.java
public SetGameScore setChatId(Long chatId) { Objects.requireNonNull(chatId); this.chatId = chatId.toString(); return this; }
From source file:com.appdynamics.monitors.boundary.BoundaryWrapper.java
/** * Retrieves network traffic data in the past minute from Boundary * @param observationIds A comma separated list of valid observationIds needed to make the historical API REST request * @return responseData A JsonArray containing all the ip_addresses, and their respective network traffic metrics *///www. ja v a2 s .c om private JsonArray getResponseData(String observationIds) throws Exception { String metricsURL = constructMetricsURL(); HttpPost httpPost = new HttpPost(metricsURL); httpPost.addHeader(BasicScheme.authenticate(new UsernamePasswordCredentials(apiKey, ""), "UTF-8", false)); // Request parameters and other properties. List<NameValuePair> params = new ArrayList<NameValuePair>(2); params.add(new BasicNameValuePair("aggregations", "observationDomainId")); params.add(new BasicNameValuePair("observationDomainIds", observationIds)); Long currentTime = System.currentTimeMillis(); Long oneMinuteAgo = currentTime - 60000; params.add(new BasicNameValuePair("from", oneMinuteAgo.toString())); params.add(new BasicNameValuePair("to", currentTime.toString())); httpPost.setEntity(new UrlEncodedFormEntity(params, "UTF-8")); HttpClient httpClient = new DefaultHttpClient(); HttpResponse response = httpClient.execute(httpPost); HttpEntity entity = response.getEntity(); BufferedReader bufferedReader2 = new BufferedReader(new InputStreamReader(entity.getContent())); StringBuilder responseString = new StringBuilder(); String line = ""; while ((line = bufferedReader2.readLine()) != null) { responseString.append(line); } JsonObject responseObject = new JsonParser().parse(responseString.toString()).getAsJsonObject(); JsonArray responseData = responseObject.getAsJsonArray("data"); return responseData; }
From source file:greensopinion.restexample.web.BlogServiceClient.java
@Override public Blog getBlog(Long blogId) { Map<String, String> variables = new HashMap<String, String>(); variables.put("blogId", blogId.toString()); Result result = template.getForObject(computeUrl("blog/{blogId}"), Result.class, variables); if (result.getBlog() != null) { return result.getBlog(); }/*from w w w . ja va2s.c o m*/ throw new IllegalStateException("Unexpected result"); }
From source file:io.stallion.secrets.SecretsVault.java
public void save() { Long version = Long.parseLong(secrets.getOrDefault("version", "1")) + 1L; secrets.put("version", version.toString()); String encrypted = dumpAndEncrypt(); File file = new File(secretsPath); try {//w w w . jav a2s. c o m FileUtils.write(file, encrypted, UTF8); } catch (IOException e) { throw new RuntimeException(e); } }
From source file:org.flite.cach3.test.InvalidateSingleCacheTest.java
@Test public void testVelocity() { final TestSvc test = (TestSvc) context.getBean("testSvc"); final StubInvalidateSingleCacheListenerImpl listener = (StubInvalidateSingleCacheListenerImpl) context .getBean("stubIS"); final String original = RandomStringUtils.randomAlphanumeric(4); final String replace = RandomStringUtils.randomAlphanumeric(6); final String finish = RandomStringUtils.randomAlphanumeric(8); final Long first = System.currentTimeMillis() + 3600000; final Long second = first + 1337; final String baseKey = first.toString() + "&&" + second.toString(); final String r1 = test.getCompoundString(first, original, second); assertEquals(r1, original);/*from ww w.jav a2 s . c o m*/ final String r2 = test.getCompoundString(first, replace, second); assertEquals(r2, original); final int previous = listener.getTriggers().size(); test.invalidateCompoundString(second, first); // Make sure the listener is getting triggered. // Testing that the listener got invoked as required. assertTrue("Doesn't look like the listener got called.", listener.getTriggers().size() == previous + 1); final String expected = StubInvalidateSingleCacheListenerImpl.formatTriggers(TestDAOImpl.COMPOUND_NAMESPACE, TestDAOImpl.COMPOUND_PREFIX, baseKey, null, new Object[] { second, first }); assertEquals(expected, listener.getTriggers().get(listener.getTriggers().size() - 1)); // Now, by retrieving again we ensure the invalidate actually took place. final String r3 = test.getCompoundString(first, finish, second); assertEquals(r3, finish); }
From source file:org.flite.cach3.test.l2.CombinedLevelsTest.java
@Test public void test() throws Exception { final TestSvc test = (TestSvc) context.getBean("testSvc"); final String key = RandomStringUtils.randomAlphanumeric(12); final long start = System.currentTimeMillis(); final Long initial = test.getCombinedData(key); final long initialValue = initial.longValue(); assertEquals(4, initial.toString().length()); // For the first little bit, make sure that both levels of caching are returning the same info. while (System.currentTimeMillis() - start < 1500) { // System.out.println("1 - 2nd: " + test.getCombinedData(key).longValue()); // System.out.println("1 - 1st: " + test.getL1Data(key).longValue()); assertEquals(initialValue, test.getCombinedData(key).longValue()); assertEquals(initialValue, test.getL1Data(key).longValue()); Thread.sleep(200);/*from www . j a va 2 s . c o m*/ } // Now force an update to the Level 1 cache, but don't have it get in the L2 cache final Long update = test.updateL1Data(key); final long updateValue = update.longValue(); assertEquals(6, update.toString().length()); // Make sure the values continue to diverge while the L2 cache window is still open (< 4.75sec) while (System.currentTimeMillis() - start < 4750) { // System.out.println("2 - 2nd: " + test.getCombinedData(key).longValue()); // System.out.println("2 - 1st: " + test.getL1Data(key).longValue()); assertEquals(initialValue, test.getCombinedData(key).longValue()); assertEquals(updateValue, test.getL1Data(key).longValue()); Thread.sleep(500); } // Wait until the L2 cache timeout of 5sec is good and expired, now try again. Thread.sleep(1000); // We expect the L2 cache to fall through to the V1 cache, which still has a good value. final long lastValue = test.getCombinedData(key).longValue(); assertEquals(updateValue, lastValue); // System.out.println("3 - 2nd: " + test.getCombinedData(key).longValue()); // System.out.println("3 - 1st: " + test.getL1Data(key).longValue()); }
From source file:com.redhat.rhn.frontend.action.multiorg.ExtAuthenticationAction.java
private void setupForm(HttpServletRequest request, DynaActionForm form) { RequestContext ctx = new RequestContext(request); User user = ctx.getCurrentUser();/* w w w .ja v a 2s. c om*/ Boolean useOrgUnit = SatConfigFactory.getSatConfigBooleanValue(SatConfigFactory.EXT_AUTH_USE_ORGUNIT); form.set("use_ou", useOrgUnit); DataList<OrgDto> dr = OrgManager.activeOrgs(user); List<LabelValueBean> orgs = new LinkedList<LabelValueBean>(); orgs.add(lv(LocalizationService.getInstance().getMessage("message.ext_auth_disable"), null)); for (OrgDto orgDto : dr) { orgs.add(lv(orgDto.getName(), orgDto.getId().toString())); } request.setAttribute("orgs", orgs); Long actOrgId = SatConfigFactory.getSatConfigLongValue(SatConfigFactory.EXT_AUTH_DEFAULT_ORGID); if (actOrgId != null) { form.set("to_org", actOrgId.toString()); } else { form.set("to_org", null); } Boolean keepRoles = SatConfigFactory.getSatConfigBooleanValue(SatConfigFactory.EXT_AUTH_KEEP_ROLES); form.set("keep_roles", keepRoles); }