Search in sources :

Example 6 with UserDefinedFileAttributeView

use of java.nio.file.attribute.UserDefinedFileAttributeView in project Singularity by HubSpot.

the class SingularityUploader method getFileAttributes.

UploaderFileAttributes getFileAttributes(Path file) {
    Set<String> supportedViews = FileSystems.getDefault().supportedFileAttributeViews();
    LOG.trace("Supported attribute views are {}", supportedViews);
    if (supportedViews.contains("user")) {
        try {
            UserDefinedFileAttributeView view = Files.getFileAttributeView(file, UserDefinedFileAttributeView.class);
            List<String> attributes = view.list();
            LOG.debug("Found file attributes {} for file {}", attributes, file);
            Optional<Long> maybeStartTime = readFileAttributeAsLong(file, LOG_START_TIME_ATTR, view, attributes);
            Optional<Long> maybeEndTime = readFileAttributeAsLong(file, LOG_END_TIME_ATTR, view, attributes);
            return new UploaderFileAttributes(maybeStartTime, maybeEndTime);
        } catch (Exception e) {
            LOG.error("Could not get extra file metadata for {}", file, e);
        }
    }
    return new UploaderFileAttributes(Optional.empty(), Optional.empty());
}
Also used : UserDefinedFileAttributeView(java.nio.file.attribute.UserDefinedFileAttributeView) NoSuchFileException(java.nio.file.NoSuchFileException) RetryException(com.github.rholder.retry.RetryException) ProcessFailedException(com.hubspot.singularity.runner.base.shared.ProcessFailedException) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException)

Aggregations

UserDefinedFileAttributeView (java.nio.file.attribute.UserDefinedFileAttributeView)6 ByteBuffer (java.nio.ByteBuffer)4 NoSuchFileException (java.nio.file.NoSuchFileException)3 Test (org.junit.Test)3 Path (java.nio.file.Path)2 RetryException (com.github.rholder.retry.RetryException)1 ProcessFailedException (com.hubspot.singularity.runner.base.shared.ProcessFailedException)1 IOException (java.io.IOException)1 UncheckedIOException (java.io.UncheckedIOException)1