本文整理汇总了Java中com.amazonaws.util.DateUtils类的典型用法代码示例。如果您正苦于以下问题:Java DateUtils类的具体用法?Java DateUtils怎么用?Java DateUtils使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DateUtils类属于com.amazonaws.util包,在下文中一共展示了DateUtils类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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));
}
开发者ID:IBM,项目名称:ibm-cos-sdk-java,代码行数:9,代码来源:DateTimeJsonSerializer.java
示例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());
}
开发者ID:IBM,项目名称:ibm-cos-sdk-java,代码行数:22,代码来源:EC2CredentialsFetcherTest.java
示例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);
}
开发者ID:awslabs,项目名称:amazon-cognito-developer-authentication-sample,代码行数:22,代码来源:Utilities.java
示例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);
}
开发者ID:aws-samples,项目名称:reinvent2013-mobile-photo-share,代码行数:27,代码来源:Utilities.java
示例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;
}
}
开发者ID:IBM,项目名称:ibm-cos-sdk-java,代码行数:12,代码来源:SimpleTypeStaxUnmarshallers.java
示例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;
}
开发者ID:IBM,项目名称:ibm-cos-sdk-java,代码行数:10,代码来源:SdkJsonGenerator.java
示例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);
}
开发者ID:IBM,项目名称:ibm-cos-sdk-java,代码行数:34,代码来源:AmazonHttpClient.java
示例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;
}
开发者ID:IBM,项目名称:ibm-cos-sdk-java,代码行数:36,代码来源:AWS4Signer.java
示例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);
}
}
}
开发者ID:IBM,项目名称:ibm-cos-sdk-java,代码行数:29,代码来源:XmlResponsesSaxParser.java
示例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;
}
开发者ID:libreio,项目名称:libre,代码行数:13,代码来源:AwsAttributes.java
示例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;
}
};
}
开发者ID:travel-cloud,项目名称:Cheddar,代码行数:14,代码来源:DynamoDBUnmarshallerUtil.java
示例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());
}
};
}
开发者ID:travel-cloud,项目名称:Cheddar,代码行数:10,代码来源:DynamoDBUnmarshallerUtil.java
示例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;
}
};
}
开发者ID:travel-cloud,项目名称:Cheddar,代码行数:16,代码来源:DynamoDBUnmarshallerUtil.java
示例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;
}
};
}
开发者ID:travel-cloud,项目名称:Cheddar,代码行数:12,代码来源:DynamoDBUnmarshallerUtil.java
示例15: unmarshall
import com.amazonaws.util.DateUtils; //导入依赖的package包/类
public Date unmarshall(JsonUnmarshallerContext unmarshallerContext)
throws Exception {
return DateUtils.parseServiceSpecificDate(unmarshallerContext
.readText());
}
开发者ID:IBM,项目名称:ibm-cos-sdk-java,代码行数:6,代码来源:SimpleTypeJsonUnmarshallers.java
示例16: sign
import com.amazonaws.util.DateUtils; //导入依赖的package包/类
/**
* Signs the specified request with the AWS3 signing protocol by using the
* AWS account credentials specified when this object was constructed and
* adding the required AWS3 headers to the request.
*
* @param request
* The request to sign.
*/
@Override
public void sign(SignableRequest<?> request, AWSCredentials credentials) throws SdkClientException {
// annonymous credentials, don't sign
if ( credentials instanceof AnonymousAWSCredentials ) {
return;
}
AWSCredentials sanitizedCredentials = sanitizeCredentials(credentials);
SigningAlgorithm algorithm = SigningAlgorithm.HmacSHA256;
String nonce = UUID.randomUUID().toString();
int timeOffset = request.getTimeOffset();
Date dateValue = getSignatureDate(timeOffset);
String date = DateUtils.formatRFC822Date(dateValue);
boolean isHttps = false;
if (overriddenDate != null) date = overriddenDate;
request.addHeader("Date", date);
request.addHeader("X-Amz-Date", date);
// AWS3 HTTP requires that we sign the Host header
// so we have to have it in the request by the time we sign.
String hostHeader = request.getEndpoint().getHost();
if (SdkHttpUtils.isUsingNonDefaultPort(request.getEndpoint())) {
hostHeader += ":" + request.getEndpoint().getPort();
}
request.addHeader("Host", hostHeader);
if ( sanitizedCredentials instanceof AWSSessionCredentials ) {
addSessionCredentials(request, (AWSSessionCredentials) sanitizedCredentials);
}
byte[] bytesToSign;
String stringToSign;
if (isHttps) {
request.addHeader(NONCE_HEADER, nonce);
stringToSign = date + nonce;
bytesToSign = stringToSign.getBytes(UTF8);
} else {
String path = SdkHttpUtils.appendUri(request.getEndpoint().getPath(), request.getResourcePath());
/*
* AWS3 requires all query params to be listed on the third line of
* the string to sign, even if those query params will be sent in
* the request body and not as a query string. POST formatted query
* params should *NOT* be included in the request payload.
*/
stringToSign = request.getHttpMethod().toString() + "\n"
+ getCanonicalizedResourcePath(path) + "\n"
+ getCanonicalizedQueryString(request.getParameters()) + "\n"
+ getCanonicalizedHeadersForStringToSign(request) + "\n"
+ getRequestPayloadWithoutQueryParams(request);
bytesToSign = hash(stringToSign);
}
if (log.isDebugEnabled())
log.debug("Calculated StringToSign: " + stringToSign);
String signature = signAndBase64Encode(bytesToSign,
sanitizedCredentials.getAWSSecretKey(), algorithm);
StringBuilder builder = new StringBuilder();
builder.append(isHttps ? HTTPS_SCHEME : HTTP_SCHEME).append(" ");
builder.append("AWSAccessKeyId=" + sanitizedCredentials.getAWSAccessKeyId() + ",");
builder.append("Algorithm=" + algorithm.toString() + ",");
if (!isHttps) {
builder.append(getSignedHeadersComponent(request) + ",");
}
builder.append("Signature=" + signature);
request.addHeader(AUTHORIZATION_HEADER, builder.toString());
}
开发者ID:IBM,项目名称:ibm-cos-sdk-java,代码行数:81,代码来源:AWS3Signer.java
示例17: parseIso8601Date
import com.amazonaws.util.DateUtils; //导入依赖的package包/类
public static Date parseIso8601Date(String dateString) {
return DateUtils.parseISO8601Date(dateString);
}
开发者ID:IBM,项目名称:ibm-cos-sdk-java,代码行数:4,代码来源:ServiceUtils.java
示例18: formatIso8601Date
import com.amazonaws.util.DateUtils; //导入依赖的package包/类
public static String formatIso8601Date(Date date) {
return DateUtils.formatISO8601Date(date);
}
开发者ID:IBM,项目名称:ibm-cos-sdk-java,代码行数:4,代码来源:ServiceUtils.java
示例19: parseRfc822Date
import com.amazonaws.util.DateUtils; //导入依赖的package包/类
public static Date parseRfc822Date(String dateString) {
if (StringUtils.isNullOrEmpty(dateString)) {
return null;
}
return DateUtils.parseRFC822Date(dateString);
}
开发者ID:IBM,项目名称:ibm-cos-sdk-java,代码行数:7,代码来源:ServiceUtils.java
示例20: formatRfc822Date
import com.amazonaws.util.DateUtils; //导入依赖的package包/类
public static String formatRfc822Date(Date date) {
return DateUtils.formatRFC822Date(date);
}
开发者ID:IBM,项目名称:ibm-cos-sdk-java,代码行数:4,代码来源:ServiceUtils.java
注:本文中的com.amazonaws.util.DateUtils类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论