List of usage examples for java.util Date setTime
public void setTime(long time)
From source file:org.apache.cxf.fediz.service.idp.beans.WfreshParser.java
public boolean authenticationRequired(String wfresh, String whr, RequestContext context) throws Exception { SecurityToken idpToken = (SecurityToken) WebUtils.getAttributeFromExternalContext(context, whr); if (idpToken.isExpired()) { LOG.info("[IDP_TOKEN=" + idpToken.getId() + "] is expired."); return true; }//from w w w .j av a2 s. c o m if (wfresh == null || wfresh.trim().isEmpty()) { return false; } long ttl; try { ttl = Long.parseLong(wfresh.trim()); } catch (Exception e) { LOG.info("wfresh value '" + wfresh + "' is invalid."); return false; } if (ttl == 0) { return true; } else if (ttl > 0) { Date createdDate = idpToken.getCreated(); if (createdDate != null) { Date expiryDate = new Date(); expiryDate.setTime(createdDate.getTime() + (ttl * 60L * 1000L)); if (expiryDate.before(new Date())) { LOG.info("[IDP_TOKEN=" + idpToken.getId() + "] is valid but relying party requested new authentication caused by wfresh=" + wfresh + " outdated."); return true; } } else { LOG.info("token creation date not set. Unable to check wfresh is outdated."); } } else { LOG.info("ttl value '" + ttl + "' is negative."); } return false; }
From source file:fedroot.dacs.http.DacsCookie.java
/** * Creates a new instance of DacsCookie from a javax.servlet.http.net.Cookie */// w ww . j a v a2s.c o m public DacsCookie(String domain, javax.servlet.http.Cookie cookie) throws DacsRuntimeException { // super(federationDomain, jcookie.getName(),jcookie.getValue(),"/", jcookie.getMaxAge(),jcookie.getSecure()); super(cookie.getName(), cookie.getValue()); if (!isDacsCookie(cookie)) { throw new DacsRuntimeException("invalid DACS cookie: " + cookie.getName()); } // the domain of a DACS federation never refers to a single host // if there is no leading dot we add one to the domain, // so a cookie with domain "foo.com" becomes a DACS // cookie with domain ".foo.com" causing user agents to send the cookie // to hosts foo.com, bar.foo.com, baz.foo.com etc setVersion(1); if (domain.startsWith(".")) { setDomain(domain); } else { setDomain("." + domain); } setPath("/"); if (cookie.getMaxAge() == -1) { } else { Date expires = new Date(); expires.setTime(expires.getTime() + cookie.getMaxAge()); setExpiryDate(expires); } setSecure(cookie.getSecure()); }
From source file:com.nextdoor.bender.monitoring.cw.CloudwatchReporter.java
@Override public void write(ArrayList<Stat> stats, long invokeTimeMs, Set<Tag> tags) { Date dt = new Date(); dt.setTime(invokeTimeMs); Collection<Dimension> parentDims = tagsToDimensions(tags); List<MetricDatum> metrics = new ArrayList<MetricDatum>(); /*/*from www .jav a2 s .c o m*/ * Create CW metric objects from bender internal Stat objects */ for (Stat stat : stats) { /* * Dimension are CW's version of metric tags. A conversion must be done. */ Collection<Dimension> metricDims = tagsToDimensions(stat.getTags()); metricDims.addAll(parentDims); MetricDatum metric = new MetricDatum(); metric.setMetricName(stat.getName()); // TODO: add units to Stat object SYSTEMS-870 metric.setUnit(StandardUnit.None); metric.setTimestamp(dt); metric.setDimensions(metricDims); metric.setValue((double) stat.getValue()); metrics.add(metric); } /* * Not very well documented in java docs but CW only allows 20 metrics at a time. */ List<List<MetricDatum>> chunks = ListUtils.partition(metrics, 20); for (List<MetricDatum> chunk : chunks) { PutMetricDataRequest req = new PutMetricDataRequest(); req.withMetricData(chunk); req.setNamespace(namespace); this.client.putMetricData(req); } }
From source file:Main.java
/** * For some reason, can't find this utility method in the java framework. * /* w w w. j ava 2 s.co m*/ * @param sDateTime * an xsd:dateTime string * @return an equivalent java.util.Date * @throws ParseException */ public static Date parseXsdDateTime(String sDateTime) throws ParseException { final DateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'"); int iDotPosition = NORMAL_IDOT_POSITION; if (sDateTime.charAt(0) == '-') { iDotPosition = IDOT_POSITION_IFNEG; } Date result; if (sDateTime.length() <= iDotPosition) { return format.parse(sDateTime + "Z"); } String millis = null; char c = sDateTime.charAt(iDotPosition); if (c == '.') { // if datetime has milliseconds, separate them int eoms = iDotPosition + 1; while (Character.isDigit(sDateTime.charAt(eoms))) { eoms += 1; } millis = sDateTime.substring(iDotPosition, eoms); sDateTime = sDateTime.substring(0, iDotPosition) + sDateTime.substring(eoms); c = sDateTime.charAt(iDotPosition); } if (c == '+' || c == '-') { format.setTimeZone(TimeZone.getTimeZone("GMT" + sDateTime.substring(iDotPosition))); sDateTime = sDateTime.substring(0, iDotPosition) + "Z"; } else if (c != 'Z') { throw new ParseException("Illegal timezone specification.", iDotPosition); } result = format.parse(sDateTime); if (millis != null) { result.setTime(result.getTime() + Math.round(Float.parseFloat(millis) * ONE_SEC_IN_MILLISECS)); } result = offsetDateFromGMT(result); return result; }
From source file:MainClass.java
public void run() { Date d = new Date(); DateFormat df = new SimpleDateFormat("HH:mm:ss:SSS"); long startTime = System.currentTimeMillis(); d.setTime(startTime); System.out.println("Starting task " + id + " at " + df.format(d)); fib(n);/*from w w w . j a v a 2s . c o m*/ long endTime = System.currentTimeMillis(); d.setTime(endTime); System.out.println( "Ending task " + id + " at " + df.format(d) + " after " + (endTime - startTime) + " milliseconds"); }
From source file:com.lang.pat.rabbitirc.Consumer.java
public void consume() { com.rabbitmq.client.Consumer consumer = new DefaultConsumer(channel) { @Override/*from ww w. j a va 2 s . c o m*/ public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException { String message = new String(body, "UTF-8"); JSONParser parse = new JSONParser(); SimpleDateFormat formatDate = new SimpleDateFormat("yy-MM-dd HH:mm:ss"); try { JSONObject JSONMessage = (JSONObject) parse.parse(message); Date sendDat = new Date(); sendDat.setTime((long) JSONMessage.get("timestamp")); System.out.println("[" + envelope.getRoutingKey() + "] " + "[" + JSONMessage.get("username") + "] " + JSONMessage.get("message") + " || " + formatDate.format(sendDat)); if (JSONMessage.get("username").toString().equals(ClientMain.USERNAME)) { if (!JSONMessage.get("token").toString().equals(ClientMain.token)) { System.out.print("! Duplicate username, please change to avoid conflict!"); } } System.out.print("> "); } catch (ParseException ex) { Logger.getLogger(Consumer.class.getName()).log(Level.SEVERE, null, ex); } } }; try { channel.basicConsume(ClientMain.QUEUENAME, true, consumer); } catch (IOException ex) { Logger.getLogger(Consumer.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:su.vistar.drivers.dao.driver.DriversMapDAO.java
private void fill(int driverCount) { final String[] surnames = new String[] { "", "", "", "" }; final String[] names = new String[] { "", "", "?", "" }; final String[] patronimycs = new String[] { "", "", "?", "" }; List<Category> allCategories = new ArrayList<>(categoriesDAO.getCategoriesList()); for (int i = 0; i < driverCount; i++) { Driver newDriver = new Driver(); newDriver.setSurname(surnames[randomInt(surnames.length - 1)]); newDriver.setName(names[randomInt(names.length - 1)]); newDriver.setPatronimyc(patronimycs[randomInt(patronimycs.length - 1)]); Date birthdate = new Date(); birthdate.setTime(randomInt(820452203) * 1000L); newDriver.setBirthdate(birthdate); newDriver.setGender(Gender.MALE); newDriver.setCategory(allCategories.get(randomInt(allCategories.size() - 1))); this.addDriver(newDriver); }/*from w w w . java 2 s . c o m*/ }
From source file:org.jfree.data.time.FixedMillisecondTest.java
/** * A check for immutability./* w w w.jav a 2 s.c om*/ */ @Test public void testImmutability() { Date d = new Date(20L); FixedMillisecond fm = new FixedMillisecond(d); d.setTime(22L); assertEquals(20L, fm.getFirstMillisecond()); }
From source file:com.lang.pat.kafkairc.Consumer.java
public void consume() throws ParseException, InterruptedException, Throwable { ConsumerIterator<byte[], byte[]> it = m_stream.iterator(); JSONParser parse = new JSONParser(); SimpleDateFormat formatDate = new SimpleDateFormat("yy-MM-dd HH:mm:ss"); while (it.hasNext() && listen) { if (ClientMain.ChannelList.contains(Topic)) { String temp = new String(it.next().message()); if (!temp.contains("{")) { System.out.println(temp); } else { JSONObject JSONMessage = (JSONObject) parse.parse(temp); Date sendDat = new Date(); sendDat.setTime((long) JSONMessage.get("timestamp")); System.out.println("[" + Topic + "] " + "[" + JSONMessage.get("username") + "] " + JSONMessage.get("message") + " || " + formatDate.format(sendDat)); if (JSONMessage.get("username").toString().equals(ClientMain.USERNAME)) { if (!JSONMessage.get("token").toString().equals(ClientMain.token)) { System.out.print("! Duplicate username, please change to avoid conflict!"); }/*from w w w. ja v a 2 s . c o m*/ } } System.out.print("> "); } else { listen = false; break; } } }
From source file:org.ado.minesync.minecraft.MinecraftData.java
/** * Returns a <code>MinecraftWorld</code> given the Minecraft directory name.<br/> * The <code>worldName</code> must be a valid directory under games/com.mojang/minecraftpe/minecraftWorlds. * * @param worldName the world's name./* ww w . j a v a2 s .c om*/ * @return the <code>MinecraftWorld</code> if found, otherwise <code>null</code>. * @since 1.2.0 */ public MinecraftWorld getWorld(String worldName) { notEmpty(worldName, "worldName cannot be empty"); File worldDirectory = new File(MINECRAFT_WORLDS, worldName); if (worldDirectory.isDirectory() && worldDirectory.exists()) { Date modificationDate = new Date(); modificationDate.setTime(getWorldsModificationDate(worldDirectory)); return new MinecraftWorld(worldDirectory.getName(), worldDirectory, getRecursiveFilesInDirectory(worldDirectory), modificationDate); } return null; }