Example usage for java.time.format DateTimeFormatter RFC_1123_DATE_TIME

List of usage examples for java.time.format DateTimeFormatter RFC_1123_DATE_TIME

Introduction

In this page you can find the example usage for java.time.format DateTimeFormatter RFC_1123_DATE_TIME.

Prototype

DateTimeFormatter RFC_1123_DATE_TIME

To view the source code for java.time.format DateTimeFormatter RFC_1123_DATE_TIME.

Click Source Link

Document

The RFC-1123 date-time formatter, such as 'Tue, 3 Jun 2008 11:05:30 GMT'.

Usage

From source file:org.cryptomator.frontend.webdav.servlet.DavNode.java

private Optional<DavProperty<?>> creationDateProperty(DavPropertyName name) {
    return attr.map(BasicFileAttributes::creationTime) //
            .map(FileTime::toInstant) //
            .map(creationTime -> OffsetDateTime.ofInstant(creationTime, ZoneOffset.UTC)) //
            .map(creationDate -> new DefaultDavProperty<>(name,
                    DateTimeFormatter.RFC_1123_DATE_TIME.format(creationDate)));
}

From source file:com.netflix.spinnaker.front50.model.SwiftStorageService.java

@Override
public long getLastModified(ObjectType objectType) {
    List<? extends SwiftObject> objects = getSwift().objects().list(containerName,
            ObjectListOptions.create().path(objectType.group));
    ZonedDateTime lastModified = Instant.now().atZone(ZoneOffset.UTC);
    for (SwiftObject o : objects) {
        ZonedDateTime timestamp = ZonedDateTime.parse(
                getSwift().objects().getMetadata(containerName, o.getName()).get("Last-Modified"),
                DateTimeFormatter.RFC_1123_DATE_TIME);
        if (timestamp.isBefore(lastModified)) {
            lastModified = timestamp;//from  ww  w. j av a 2 s. c  o  m
        }
    }
    return lastModified.toEpochSecond();
}

From source file:org.cryptomator.frontend.webdav.servlet.DavNode.java

@Override
public void setProperty(DavProperty<?> property) throws DavException {
    final String namespacelessPropertyName = property.getName().getName();
    if (Arrays.asList(DAV_CREATIONDATE_PROPNAMES).contains(namespacelessPropertyName)
            && property.getValue() instanceof String) {
        String createDateStr = (String) property.getValue();
        OffsetDateTime creationDate = OffsetDateTime
                .from(DateTimeFormatter.RFC_1123_DATE_TIME.parse(createDateStr));
        this.setCreationTime(creationDate.toInstant());
    } else if (Arrays.asList(DAV_MODIFIEDDATE_PROPNAMES).contains(namespacelessPropertyName)
            && property.getValue() instanceof String) {
        String lastModifiedDateStr = (String) property.getValue();
        OffsetDateTime lastModifiedDate = OffsetDateTime
                .from(DateTimeFormatter.RFC_1123_DATE_TIME.parse(lastModifiedDateStr));
        this.setModificationTime(lastModifiedDate.toInstant());
    }//ww w.ja  v a2  s .co m
    properties.add(property);
}

From source file:org.ops4j.pax.web.resources.jsf.OsgiResource.java

/**
 * <p>/* w  w w.ja  va  2s .c om*/
 * RFC 2616 allows three different date-formats:
 * <ul>
 * <li>RFC 1123</li>
 * <li>RFC 1036</li>
 * <li>ASCI-Time</li>
 * </ul>
 * </p>
 *
 * @param headerValue value transmitted from client
 * @return the parsed DateTime
 * @see <a href=
 * "http://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.3">RFC
 * 2616</a>
 */
private LocalDateTime convertIfModifiedSinceToDate(String headerValue) {

    LocalDateTime time = null;
    try {
        time = LocalDateTime.parse(headerValue, DateTimeFormatter.RFC_1123_DATE_TIME);
    } catch (DateTimeParseException e) {
        logger.trace("could not parse date with RFC-1123. Will try RFC-1036 format...");
    }

    if (time == null) {
        try {
            time = LocalDateTime.parse(headerValue, DateTimeFormatter.ofPattern(PATTERN_RFC_1036));
        } catch (DateTimeParseException e) {
            logger.trace("could not parse date with RFC-1036. Will try ASCITIME format...");
        }
    }

    if (time == null) {
        try {
            time = LocalDateTime.parse(headerValue, DateTimeFormatter.ofPattern(PATTERN_ASCITIME));
        } catch (DateTimeParseException e) {
            logger.trace("could not parse date with ASCITIME.");
        }
    }

    if (time == null) {
        logger.error("Could not parse given if-modified-since header with value '{}'", headerValue);
    }
    return time;
}

From source file:com.baasbox.controllers.actions.filters.WrapResponse.java

private void setServerTime(Http.Response response) {
    ZonedDateTime date = ZonedDateTime.now(ZoneId.of("GMT"));
    String httpDate = DateTimeFormatter.RFC_1123_DATE_TIME.format(date);
    response.setHeader("Date", httpDate);
}

From source file:org.cryptomator.frontend.webdav.servlet.DavResourceFactoryImpl.java

/**
 * @return <code>true</code> if a partial response should be generated according to an If-Range precondition.
 *//*from   w  w  w  . ja  v a 2  s . c  o  m*/
private boolean isIfRangeHeaderSatisfied(BasicFileAttributes attr, String ifRangeHeader) throws DavException {
    if (ifRangeHeader == null) {
        // no header set -> satisfied implicitly
        return true;
    } else {
        try {
            Instant expectedTime = Instant.from(DateTimeFormatter.RFC_1123_DATE_TIME.parse(ifRangeHeader));
            Instant actualTime = attr.lastModifiedTime().toInstant();
            return expectedTime.compareTo(actualTime) == 0;
        } catch (DateTimeParseException e) {
            throw new DavException(DavServletResponse.SC_BAD_REQUEST,
                    "Unsupported If-Range header: " + ifRangeHeader);
        }
    }
}

From source file:com.muk.services.security.DefaultUaaLoginService.java

private String httpCookieToString(HttpCookie cookie) {
    final OffsetDateTime now = OffsetDateTime.now(ZoneOffset.UTC).plusSeconds(cookie.getMaxAge());
    final String cookieExpires = DateTimeFormatter.RFC_1123_DATE_TIME.format(now);
    final StringBuilder cookieBuilder = new StringBuilder();
    cookieBuilder.append(cookie.getName()).append("=").append(cookie.getValue()).append(";path=")
            .append(cookie.getPath()).append(";max-age=").append(cookie.getMaxAge()).append(";expires=")
            .append(cookieExpires);/*from ww w .j  a v a  2 s  . c om*/

    if (cookie.isHttpOnly()) {
        cookieBuilder.append(";HttpOnly");
    }

    return cookieBuilder.toString();
}

From source file:arxiv.xml.XMLParser.java

/**
 * Parse the date of an article version.
 * @throws ParseException if there is a parsing error
 *//* w  ww. j a va  2s  . co m*/
private ZonedDateTime parseSubmissionTime(String value) {
    ZonedDateTime submissionTime;
    try {
        submissionTime = ZonedDateTime.parse(value, DateTimeFormatter.RFC_1123_DATE_TIME);
    } catch (DateTimeParseException e) {
        throw new ParseException("Could not parse version date '" + value + "' in RFC_1123_DATE_TIME format",
                e);
    }

    return submissionTime;
}