本文整理汇总了Java中com.amazonaws.util.DateUtils类的典型用法代码示例。如果您正苦于以下问题:Java DateUtils类的具体用法?Java DateUtils怎么用?Java DateUtils使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DateUtils类属于com.amazonaws.util包,在下文中一共展示了DateUtils类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: serialize
import com.amazonaws.util.DateUtils; //导入依赖的package包/类
@Override
public void serialize(
DateTime value,
JsonGenerator jgen,
SerializerProvider provider) throws IOException {
jgen.writeString(DateUtils.formatISO8601Date(value));
}
示例2: testNeedsToLoadCredentialsMethod
import com.amazonaws.util.DateUtils; //导入依赖的package包/类
/** Tests that the credentials provider reloads credentials appropriately */
@Test
public void testNeedsToLoadCredentialsMethod() throws Exception {
TestCredentialsProvider credentialsProvider = new TestCredentialsProvider();
// The provider should not refresh credentials when they aren't close to expiring and are recent
stubForSuccessResonseWithCustomExpirationDate(200, DateUtils.formatISO8601Date(new Date(System.currentTimeMillis() + ONE_MINUTE * 60 * 24)).toString());
credentialsProvider.getCredentials();
assertFalse(credentialsProvider.needsToLoadCredentials());
// The provider should refresh credentials when they aren't close to expiring, but are more than an hour old
stubForSuccessResonseWithCustomExpirationDate(200, DateUtils.formatISO8601Date(new Date(System.currentTimeMillis() + ONE_MINUTE * 16)).toString());
credentialsProvider.getCredentials();
credentialsProvider.setLastInstanceProfileCheck(new Date(System.currentTimeMillis() - ONE_MINUTE * 61));
assertTrue(credentialsProvider.needsToLoadCredentials());
// The provider should refresh credentials when they are close to expiring
stubForSuccessResonseWithCustomExpirationDate(200, DateUtils.formatISO8601Date(new Date(System.currentTimeMillis() + ONE_MINUTE * 14)).toString());
credentialsProvider.getCredentials();
assertTrue(credentialsProvider.needsToLoadCredentials());
}
示例3: isTimestampValid
import com.amazonaws.util.DateUtils; //导入依赖的package包/类
/**
* Checks to see if the request has valid timestamp. If given timestamp
* falls in 30 mins window from current server timestamp
*/
public static boolean isTimestampValid(String timestamp) {
long timestampLong = 0L;
final long window = 15 * 60 * 1000L;
if (null == timestamp) {
return false;
}
timestampLong = DateUtils.parseISO8601Date(timestamp).getTime();
Long now = new Date().getTime();
long before15Mins = new Date(now - window).getTime();
long after15Mins = new Date(now + window).getTime();
return (timestampLong >= before15Mins && timestampLong <= after15Mins);
}
示例4: isTimestampValid
import com.amazonaws.util.DateUtils; //导入依赖的package包/类
/**
* Checks to see if the request has valid timestamp. If given timestamp
* falls in 30 mins window from current server timestamp
*/
public static boolean isTimestampValid(String timestamp) {
long timestampLong = 0L;
final long window = 15 * 60 * 1000L;
if (null == timestamp) {
return false;
}
try {
timestampLong = new DateUtils().parseIso8601Date(timestamp).getTime();
} catch (ParseException exception) {
log.warning("Error parsing timestamp sent from client : " + timestamp);
return false;
}
Long now = new Date().getTime();
long before15Mins = new Date(now - window).getTime();
long after15Mins = new Date(now + window).getTime();
return (timestampLong >= before15Mins && timestampLong <= after15Mins);
}
示例5: unmarshall
import com.amazonaws.util.DateUtils; //导入依赖的package包/类
public Date unmarshall(StaxUnmarshallerContext unmarshallerContext) throws Exception {
String dateString = unmarshallerContext.readText();
if (dateString == null) return null;
try {
return DateUtils.parseISO8601Date(dateString);
} catch (Exception e) {
log.warn("Unable to parse date '" + dateString + "': " + e.getMessage(), e);
return null;
}
}
示例6: writeValue
import com.amazonaws.util.DateUtils; //导入依赖的package包/类
@Override
public StructuredJsonGenerator writeValue(Date date) {
try {
generator.writeNumber(DateUtils.formatServiceSpecificDate(date));
} catch (IOException e) {
throw new JsonGenerationException(e);
}
return this;
}
示例7: parseClockSkewOffset
import com.amazonaws.util.DateUtils; //导入依赖的package包/类
/**
* Returns the difference between the client's clock time and the service clock time in unit
* of seconds.
*/
private int parseClockSkewOffset(org.apache.http.HttpResponse response,
SdkBaseException exception) {
final long currentTimeMilli = System.currentTimeMillis();
Date serverDate;
String serverDateStr = null;
Header[] responseDateHeader = response.getHeaders("Date");
try {
if (responseDateHeader.length == 0) {
// SQS doesn't return Date header
final String errmsg = exception.getMessage();
serverDateStr = getServerDateFromException(errmsg);
if (serverDateStr == null) {
log.warn("Unable to parse clock skew offset from errmsg: " + errmsg);
return 0;
}
serverDate = DateUtils.parseCompressedISO8601Date(serverDateStr);
} else {
serverDateStr = responseDateHeader[0].getValue();
serverDate = DateUtils.parseRFC822Date(serverDateStr);
}
} catch (RuntimeException e) {
log.warn("Unable to parse clock skew offset from response: " + serverDateStr, e);
return 0;
}
long diff = currentTimeMilli - serverDate.getTime();
return (int) (diff / 1000);
}
示例8: deriveSigningKey
import com.amazonaws.util.DateUtils; //导入依赖的package包/类
/**
* Step 3 of the AWS Signature version 4 calculation. It involves deriving
* the signing key and computing the signature. Refer to
* http://docs.aws.amazon
* .com/general/latest/gr/sigv4-calculate-signature.html
*/
private final byte[] deriveSigningKey(AWSCredentials credentials,
AWS4SignerRequestParams signerRequestParams) {
final String cacheKey = computeSigningCacheKeyName(credentials,
signerRequestParams);
final long daysSinceEpochSigningDate = DateUtils
.numberOfDaysSinceEpoch(signerRequestParams
.getSigningDateTimeMilli());
SignerKey signerKey = signerCache.get(cacheKey);
if (signerKey != null) {
if (daysSinceEpochSigningDate == signerKey
.getNumberOfDaysSinceEpoch()) {
return signerKey.getSigningKey();
}
}
if (log.isDebugEnabled()) {
log.debug("Generating a new signing key as the signing key not available in the cache for the date "
+ TimeUnit.DAYS.toMillis(daysSinceEpochSigningDate));
}
byte[] signingKey = newSigningKey(credentials,
signerRequestParams.getFormattedSigningDate(),
signerRequestParams.getRegionName(),
signerRequestParams.getServiceName());
signerCache.add(cacheKey, new SignerKey(
daysSinceEpochSigningDate, signingKey));
return signingKey;
}
示例9: doEndElement
import com.amazonaws.util.DateUtils; //导入依赖的package包/类
@Override
protected void doEndElement(String uri, String name, String qName) {
if (in("ListAllMyBucketsResult", "Owner")) {
if (name.equals("ID")) {
bucketsOwner.setId(getText());
} else if (name.equals("DisplayName")) {
bucketsOwner.setDisplayName(getText());
}
}
else if (in("ListAllMyBucketsResult", "Buckets")) {
if (name.equals("Bucket")) {
buckets.add(currentBucket);
currentBucket = null;
}
}
else if (in("ListAllMyBucketsResult", "Buckets", "Bucket")) {
if (name.equals("Name")) {
currentBucket.setName(getText());
} else if (name.equals("CreationDate")) {
Date creationDate = DateUtils.parseISO8601Date(getText());
currentBucket.setCreationDate(creationDate);
}
}
}
示例10: created
import com.amazonaws.util.DateUtils; //导入依赖的package包/类
@Override
public Date created() throws IOException {
final Date dat;
if (this.meta.getRawMetadataValue(Headers.DATE) == null) {
dat = this.meta.getLastModified();
} else {
dat = DateUtils.cloneDate(
(Date) this.meta.getRawMetadataValue(Headers.DATE)
);
}
return dat;
}
示例11: getDateSSUnmarshaller
import com.amazonaws.util.DateUtils; //导入依赖的package包/类
public static SSUnmarshaller getDateSSUnmarshaller() {
return new SSUnmarshaller() {
@Override
public Object unmarshall(final AttributeValue value) throws ParseException {
final Set<Date> argument = new HashSet<Date>();
for (final String s : value.getSS()) {
argument.add(DateUtils.parseISO8601Date(s));
}
return argument;
}
};
}
示例12: getDateSUnmarshaller
import com.amazonaws.util.DateUtils; //导入依赖的package包/类
public static SUnmarshaller getDateSUnmarshaller() {
return new SUnmarshaller() {
@Override
public Object unmarshall(final AttributeValue value) throws ParseException {
return DateUtils.parseISO8601Date(value.getS());
}
};
}
示例13: getCalendarSSUnmarshaller
import com.amazonaws.util.DateUtils; //导入依赖的package包/类
public static SSUnmarshaller getCalendarSSUnmarshaller() {
return new SSUnmarshaller() {
@Override
public Object unmarshall(final AttributeValue value) throws ParseException {
final Set<Calendar> argument = new HashSet<Calendar>();
for (final String s : value.getSS()) {
final Calendar cal = GregorianCalendar.getInstance();
cal.setTime(DateUtils.parseISO8601Date(s));
argument.add(cal);
}
return argument;
}
};
}
示例14: getCalendarSUnmarshaller
import com.amazonaws.util.DateUtils; //导入依赖的package包/类
public static SUnmarshaller getCalendarSUnmarshaller() {
return new SUnmarshaller() {
@Override
public Object unmarshall(final AttributeValue value) throws ParseException {
final Calendar cal = GregorianCalendar.getInstance();
cal.setTime(DateUtils.parseISO8601Date(value.getS()));
return cal;
}
};
}
示例15: unmarshall
import com.amazonaws.util.DateUtils; //导入依赖的package包/类
public Date unmarshall(JsonUnmarshallerContext unmarshallerContext)
throws Exception {
return DateUtils.parseServiceSpecificDate(unmarshallerContext
.readText());
}