List of usage examples for java.util Date toString
public String toString()
where:dow mon dd hh:mm:ss zzz yyyy
From source file:com.aol.webservice_base.cache.CacheManager.java
/** * Send whatever needs to be cached (key, value) * The data is expired after the configured time * /*from www . j a va2s .co m*/ * @param key * @param value */ public void set(String key, Object value) { StringBuilder keyBuilder = new StringBuilder(32); keyBuilder.append(keyPrefix).append(key); Date now = new Date(); Date expiresAt = new Date(now.getTime() + expireMs.longValue()); if (logger.isDebugEnabled()) logger.debug( "Creating a Memcache entry: " + keyBuilder.toString() + " Expiring at " + expiresAt.toString()); key = keyBuilder.toString(); mc.set(ensureKeySafe(key, false), new CacheContainer(key, value), expiresAt); }
From source file:com.mothsoft.alexis.engine.numeric.President2012DataSetImporter.java
private void save(final Map<Date, PollResults> pollResultsByDate) { this.transactionTemplate.execute(new TransactionCallbackWithoutResult() { @Override//from w w w . j a v a 2 s . c o m protected void doInTransactionWithoutResult(final TransactionStatus txStatus) { final Map<String, DataSet> dataSets = new HashMap<String, DataSet>(); for (final Map.Entry<Date, PollResults> entry : pollResultsByDate.entrySet()) { final Date date = entry.getKey(); logger.debug("Date: " + date.toString()); final PollResults pollResults = entry.getValue(); for (final String choice : pollResults.getAvailableChoices()) { // use data set if cached DataSet dataSet = dataSets.get(choice); // find or create the data set if (dataSet == null) { dataSet = findOrCreateDataSet(choice); dataSets.put(choice, dataSet); } logger.debug(String.format("%s => %f", choice, pollResults.valueOf(choice))); // save the value final DataSetPoint point = new DataSetPoint(dataSet, date, pollResults.valueOf(choice)); President2012DataSetImporter.this.dataSetPointDao.add(point); } } } }); }
From source file:eionet.rod.countrysrv.Extractor.java
private String cDT() { Date d = new Date(); return new String("[" + d.toString() + "] "); }
From source file:br.fapesp.myutils.MyUtils.java
/** * Get current timestamp of the system/*w w w . j a v a2 s . c o m*/ * @return timestamp with the format: dow mon dd hh:mm:ss zzz yyyy */ public static String getCurrentTimestamp() { Date d = new Date(); return d.toString(); }
From source file:org.artifactory.webapp.wicket.page.home.WelcomeBorder.java
private void addLastLoginLabel() { SerializablePair<String, Long> lastLoginInfo = null; boolean authenticated = authorizationService.isAuthenticated(); boolean anonymousLoggedIn = authorizationService.isAnonymous(); //If a user (not anonymous) is logged in if (authenticated && !anonymousLoggedIn) { String username = authorizationService.currentUsername(); if (!StringUtils.isEmpty(username)) { //Try to get last login info lastLoginInfo = ArtifactoryWebSession.get().getLastLoginInfo(); }/*from w ww. ja v a 2s . com*/ } final boolean loginInfoValid = lastLoginInfo != null && lastLoginInfo.isNotNull(); Label lastLogin = new Label("lastLogin", new Model()); lastLogin.setVisible(loginInfoValid); add(lastLogin); if (loginInfoValid) { Date date = new Date(lastLoginInfo.getSecond()); String clientIp = lastLoginInfo.getFirst(); PrettyTime prettyTime = new PrettyTime(); lastLogin.setDefaultModelObject("Last logged in: " + prettyTime.format(date) + " (" + date.toString() + "), from " + clientIp + "."); } }
From source file:org.kalypso.ogc.sensor.adapter.NativeObservationDWD5minAdapter.java
@Override protected List<NativeObservationDataSet> parse(final File source, final TimeZone timeZone, final boolean continueWithErrors, final IStatusCollector stati) throws IOException { final List<NativeObservationDataSet> datasets = new ArrayList<>(); final SimpleDateFormat sdf = new SimpleDateFormat("yyMMdd"); //$NON-NLS-1$ sdf.setTimeZone(timeZone);// w ww . ja v a2 s.c o m final FileReader fileReader = new FileReader(source); final LineNumberReader reader = new LineNumberReader(fileReader); try { String lineIn = null; int valuesLine = 0; int step = SEARCH_BLOCK_HEADER; final StringBuffer buffer = new StringBuffer(); long startDate = 0; while ((lineIn = reader.readLine()) != null) { if (!continueWithErrors && getErrorCount() > getMaxErrorCount()) return datasets; switch (step) { case SEARCH_BLOCK_HEADER: final Matcher matcher = DWD_BLOCK_PATTERN.matcher(lineIn); if (matcher.matches()) { // String DWDID = matcher.group( 1 ); final String startDateString = matcher.group(2); final Matcher dateMatcher = DATE_PATTERN.matcher(startDateString); if (dateMatcher.matches()) { // System.out.println( "Startdatum Header:" + startDateString ); try { final Date parseDate = sdf.parse(startDateString); startDate = parseDate.getTime(); } catch (final ParseException e) { e.printStackTrace(); stati.add(IStatus.WARNING, String.format(Messages.getString("NativeObservationDWD5minAdapter_0"), //$NON-NLS-1$ reader.getLineNumber(), startDateString, DATE_PATTERN.toString()), e); tickErrorCount(); } } else { stati.add(IStatus.INFO, String.format(Messages.getString("NativeObservationDWD5minAdapter_0"), //$NON-NLS-1$ reader.getLineNumber(), startDateString, DATE_PATTERN.toString())); } } else { stati.add(IStatus.WARNING, String.format(Messages.getString("NativeObservationDWD5minAdapter_1"), //$NON-NLS-1$ reader.getLineNumber(), lineIn)); tickErrorCount(); } step++; break; case SEARCH_VALUES: valuesLine = valuesLine + 1; for (int i = 0; i < 16; i++) { final String valueString = lineIn.substring(i * 5, 5 * (i + 1)); Double value = new Double(Double.parseDouble(valueString)) / 1000; // TODO: Write status String src = SOURCE_ID; if (value > 99.997) { value = 0.0; src = SOURCE_ID_MISSING_VALUE; } // Datenfilter fr 0.0 - um Datenbank nicht mit unntigen Werten zu fllen (Zur Zeit nicht verwendet, da // Rohdaten bentigt) buffer.append(" "); // separator //$NON-NLS-1$ final Date valueDate = new Date( startDate + i * m_timeStep + (valuesLine - 1) * 16 * m_timeStep); buffer.append(valueDate.toString()); datasets.add(new NativeObservationDataSet(valueDate, value, toStatus(src), src)); } if (valuesLine == 18) { step = SEARCH_BLOCK_HEADER; valuesLine = 0; } break; default: break; } } } finally { IOUtils.closeQuietly(reader); } return datasets; }
From source file:com.jaeksoft.searchlib.crawler.mailbox.crawler.MailboxAbstractCrawler.java
final public void readMessage(IndexDocument crawlIndexDocument, IndexDocument parserIndexDocument, Folder folder, Message message, String id) throws Exception { crawlIndexDocument.addString(MailboxFieldEnum.message_id.name(), id); crawlIndexDocument.addString(MailboxFieldEnum.message_number.name(), Integer.toString(message.getMessageNumber())); if (message instanceof MimeMessage) crawlIndexDocument.addString(MailboxFieldEnum.content_id.name(), ((MimeMessage) message).getContentID()); crawlIndexDocument.addString(MailboxFieldEnum.subject.name(), message.getSubject()); putAddresses(crawlIndexDocument, message.getFrom(), MailboxFieldEnum.from_address.name(), MailboxFieldEnum.from_personal.name()); putAddresses(crawlIndexDocument, message.getReplyTo(), MailboxFieldEnum.reply_to_address.name(), MailboxFieldEnum.reply_to_personal.name()); putAddresses(crawlIndexDocument, message.getRecipients(RecipientType.TO), MailboxFieldEnum.recipient_to_address.name(), MailboxFieldEnum.recipient_to_personal.name()); putAddresses(crawlIndexDocument, message.getRecipients(RecipientType.CC), MailboxFieldEnum.recipient_cc_address.name(), MailboxFieldEnum.recipient_cc_personal.name()); putAddresses(crawlIndexDocument, message.getRecipients(RecipientType.BCC), MailboxFieldEnum.recipient_bcc_address.name(), MailboxFieldEnum.recipient_bcc_personal.name()); Date dt = message.getSentDate(); if (dt != null) crawlIndexDocument.addString(MailboxFieldEnum.send_date.name(), dt.toString()); dt = message.getReceivedDate();/*from w ww . j a v a2 s .c o m*/ if (dt != null) crawlIndexDocument.addString(MailboxFieldEnum.received_date.name(), dt.toString()); if (message.isSet(Flag.ANSWERED)) crawlIndexDocument.addString(MailboxFieldEnum.flags.name(), "ANSWERED"); if (message.isSet(Flag.DELETED)) crawlIndexDocument.addString(MailboxFieldEnum.flags.name(), "DELETED"); if (message.isSet(Flag.DRAFT)) crawlIndexDocument.addString(MailboxFieldEnum.flags.name(), "DRAFT"); if (message.isSet(Flag.FLAGGED)) crawlIndexDocument.addString(MailboxFieldEnum.flags.name(), "FLAGGED"); if (message.isSet(Flag.SEEN)) crawlIndexDocument.addString(MailboxFieldEnum.flags.name(), "SEEN"); if (message instanceof MimeMessage) { MimeMessageParser mimeMessageParser = new MimeMessageParser((MimeMessage) message).parse(); crawlIndexDocument.addString(MailboxFieldEnum.html_content.name(), mimeMessageParser.getHtmlContent()); crawlIndexDocument.addString(MailboxFieldEnum.plain_content.name(), mimeMessageParser.getPlainContent()); for (DataSource dataSource : mimeMessageParser.getAttachmentList()) { crawlIndexDocument.addString(MailboxFieldEnum.email_attachment_name.name(), dataSource.getName()); crawlIndexDocument.addString(MailboxFieldEnum.email_attachment_type.name(), dataSource.getContentType()); if (parserSelector == null) continue; Parser attachParser = parserSelector.parseStream(null, dataSource.getName(), dataSource.getContentType(), null, dataSource.getInputStream(), null, null, null); if (attachParser == null) continue; List<ParserResultItem> parserResults = attachParser.getParserResults(); if (parserResults != null) for (ParserResultItem parserResult : parserResults) crawlIndexDocument.addFieldIndexDocument(MailboxFieldEnum.email_attachment_content.name(), parserResult.getParserDocument()); } } }
From source file:org.apache.nifi.processors.aws.s3.PutS3Object.java
@Override public void onTrigger(final ProcessContext context, final ProcessSession session) { FlowFile flowFile = session.get();/*from w ww. j a va 2s . c o m*/ if (flowFile == null) { return; } final long startNanos = System.nanoTime(); final String bucket = context.getProperty(BUCKET).evaluateAttributeExpressions(flowFile).getValue(); final String key = context.getProperty(KEY).evaluateAttributeExpressions(flowFile).getValue(); final AmazonS3Client s3 = getClient(); final FlowFile ff = flowFile; final Map<String, String> attributes = new HashMap<>(); attributes.put(S3_BUCKET_KEY, bucket); attributes.put(S3_OBJECT_KEY, key); try { session.read(flowFile, new InputStreamCallback() { @Override public void process(final InputStream rawIn) throws IOException { try (final InputStream in = new BufferedInputStream(rawIn)) { final ObjectMetadata objectMetadata = new ObjectMetadata(); objectMetadata.setContentDisposition(ff.getAttribute(CoreAttributes.FILENAME.key())); objectMetadata.setContentLength(ff.getSize()); final String expirationRule = context.getProperty(EXPIRATION_RULE_ID) .evaluateAttributeExpressions(ff).getValue(); if (expirationRule != null) { objectMetadata.setExpirationTimeRuleId(expirationRule); } final Map<String, String> userMetadata = new HashMap<>(); for (final Map.Entry<PropertyDescriptor, String> entry : context.getProperties() .entrySet()) { if (entry.getKey().isDynamic()) { final String value = context.getProperty(entry.getKey()) .evaluateAttributeExpressions(ff).getValue(); userMetadata.put(entry.getKey().getName(), value); } } if (!userMetadata.isEmpty()) { objectMetadata.setUserMetadata(userMetadata); } final PutObjectRequest request = new PutObjectRequest(bucket, key, in, objectMetadata); request.setStorageClass( StorageClass.valueOf(context.getProperty(STORAGE_CLASS).getValue())); final AccessControlList acl = createACL(context, ff); if (acl != null) { request.setAccessControlList(acl); } final PutObjectResult result = s3.putObject(request); if (result.getVersionId() != null) { attributes.put(S3_VERSION_ATTR_KEY, result.getVersionId()); } attributes.put(S3_ETAG_ATTR_KEY, result.getETag()); final Date expiration = result.getExpirationTime(); if (expiration != null) { attributes.put(S3_EXPIRATION_ATTR_KEY, expiration.toString()); } if (result.getMetadata().getRawMetadata().keySet().contains(S3_STORAGECLASS_META_KEY)) { attributes.put(S3_STORAGECLASS_ATTR_KEY, result.getMetadata().getRawMetadataValue(S3_STORAGECLASS_META_KEY).toString()); } if (userMetadata.size() > 0) { List<String> pairs = new ArrayList<String>(); for (String userKey : userMetadata.keySet()) { pairs.add(userKey + "=" + userMetadata.get(userKey)); } attributes.put(S3_USERMETA_ATTR_KEY, StringUtils.join(pairs, ", ")); } } } }); if (!attributes.isEmpty()) { flowFile = session.putAllAttributes(flowFile, attributes); } session.transfer(flowFile, REL_SUCCESS); final String url = s3.getResourceUrl(bucket, key); final long millis = TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - startNanos); session.getProvenanceReporter().send(flowFile, url, millis); getLogger().info("Successfully put {} to Amazon S3 in {} milliseconds", new Object[] { ff, millis }); } catch (final ProcessException | AmazonClientException pe) { getLogger().error("Failed to put {} to Amazon S3 due to {}", new Object[] { flowFile, pe }); flowFile = session.penalize(flowFile); session.transfer(flowFile, REL_FAILURE); } }
From source file:org.artifactory.webapp.wicket.page.home.WelcomeBorder.java
@SuppressWarnings({ "UnusedDeclaration" }) private void addLastAccessLabel() { SerializablePair<String, Long> lastAccessInfo = null; boolean authenticated = authorizationService.isAuthenticated(); boolean anonymousLoggedIn = authorizationService.isAnonymous(); //If a user (not anonymous) is logged in if (authenticated && !anonymousLoggedIn) { String username = authorizationService.currentUsername(); if (!StringUtils.isEmpty(username)) { //Try to get last login info lastAccessInfo = securityService.getUserLastAccessInfo(username); }//from w ww .j av a 2s . com } final boolean lastAccessValid = (lastAccessInfo != null); Label lastAccess = new Label("lastAccess", new Model()) { @Override public boolean isVisible() { return lastAccessValid; } }; add(lastAccess); if (lastAccessValid) { Date date = new Date(lastAccessInfo.getSecond()); String clientIp = lastAccessInfo.getFirst(); PrettyTime prettyTime = new PrettyTime(); lastAccess.setDefaultModelObject("Last access in: " + prettyTime.format(date) + " (" + date.toString() + "), from " + clientIp + "."); } }
From source file:org.eclipse.jubula.client.core.businessprocess.AbstractXMLReportGenerator.java
/** * @param resultNode//from ww w. j ava2 s .co m * the actual node * @param insertInto * where to insert elements in xml */ private void getTimestampFromResultNode(TestResultNode resultNode, Element insertInto) { Element timestampEL = insertInto.addElement("timestamp"); //$NON-NLS-1$ Date time = resultNode.getTimeStamp(); if (time != null) { String timestamp = time.toString(); timestampEL.addText(timestamp); } else { timestampEL.addText(StringConstants.EMPTY); } }