Example usage for java.nio.file.attribute BasicFileAttributes creationTime

List of usage examples for java.nio.file.attribute BasicFileAttributes creationTime

Introduction

In this page you can find the example usage for java.nio.file.attribute BasicFileAttributes creationTime.

Prototype

FileTime creationTime();

Source Link

Document

Returns the creation time.

Usage

From source file:com.github.thorqin.toolkit.web.utility.UploadManager.java

private static long getCreationTime(File f) throws IOException {
    BasicFileAttributes attributes = Files.readAttributes(f.toPath(), BasicFileAttributes.class);
    return attributes.creationTime().toMillis();
}

From source file:fr.pilato.elasticsearch.crawler.fs.framework.FsCrawlerUtil.java

public static LocalDateTime getCreationTime(File file) {
    LocalDateTime time;//  w  w w  . j  av  a 2  s  .  c  om
    try {
        Path path = Paths.get(file.getAbsolutePath());
        BasicFileAttributes fileattr = Files.getFileAttributeView(path, BasicFileAttributeView.class)
                .readAttributes();
        time = LocalDateTime.ofInstant(fileattr.creationTime().toInstant(), ZoneId.systemDefault());
    } catch (Exception e) {
        time = null;
    }
    return time;
}

From source file:org.fim.tooling.RepositoryTool.java

private FileTime getCreationTime(Path file) throws IOException {
    BasicFileAttributes attributes = Files.readAttributes(file, BasicFileAttributes.class);
    return attributes.creationTime();
}

From source file:org.fim.command.ResetFileAttributesCommand.java

private boolean resetCreationTime(Path file, FileState fileState, BasicFileAttributes attributes)
        throws IOException {
    long creationTime = attributes.creationTime().toMillis();
    long previousCreationTime = fileState.getFileTime().getCreationTime();
    if (creationTime != previousCreationTime) {
        setCreationTime(file, FileTime.fromMillis(previousCreationTime));
        System.out.printf("Set creation Time: %s \t%s -> %s%n", fileState.getFileName(),
                formatDate(creationTime), formatDate(previousCreationTime));
        return true;
    }//from  w  ww.  j  a v a 2 s  . c om
    return false;
}

From source file:sorcer.file.ScratchDirManager.java

private boolean isCutoffTime(Path path, long cutOffTime) throws IOException {
    ZonedDateTime now = ZonedDateTime.now();
    BasicFileAttributes attrs = Files.readAttributes(path, BasicFileAttributes.class);
    ZonedDateTime created = ZonedDateTime.ofInstant(attrs.creationTime().toInstant(), now.getZone());

    created = created.withYear(now.getYear()).withMonth(now.getMonthValue());

    ZonedDateTime cutoff = created.plus(cutOffTime, MILLIS);

    log.info("Created {}", created);
    log.info("now     {}", now);
    log.info("cutoff  {}", cutoff);

    return now.isAfter(cutoff);
}

From source file:net.mozq.picto.core.ProcessCore.java

private static Date getBaseDate(ProcessCondition processCondition, Path file, BasicFileAttributes attrs,
        ImageMetadata imageMetadata) throws IOException {

    Date baseDate = null;/*  w  w  w.java2  s.c  o  m*/
    switch (processCondition.getBaseDateType()) {
    case CurrentDate:
        baseDate = new Date(System.currentTimeMillis());
        break;
    case FileCreationDate:
        baseDate = toDate(attrs.creationTime());
        break;
    case FileModifiedDate:
        baseDate = toDate(attrs.lastModifiedTime());
        break;
    case FileAccessDate:
        baseDate = toDate(attrs.lastAccessTime());
        break;
    case ExifDate:
        baseDate = getExifDate(imageMetadata);
        break;
    case CustomDate:
        baseDate = processCondition.getCustomBaseDate();
        break;
    default:
        throw new IllegalStateException(processCondition.getBaseDateType().toString());
    }

    if (baseDate != null) {
        if (processCondition.getBaseDateModType() != DateModType.None) {
            Calendar cal = Calendar.getInstance(processCondition.getTimeZone());
            cal.setTime(baseDate);
            int signum = 1;
            switch (processCondition.getBaseDateModType()) {
            case None:
                break;
            case Minus:
                signum = -1;
                // FALLTHRU
            case Plus:
                addField(cal, Calendar.YEAR, processCondition.getBaseDateModYears(), signum);
                addField(cal, Calendar.MONTH, processCondition.getBaseDateModMonths(), signum);
                addField(cal, Calendar.DAY_OF_MONTH, processCondition.getBaseDateModDays(), signum);
                addField(cal, Calendar.HOUR_OF_DAY, processCondition.getBaseDateModHours(), signum);
                addField(cal, Calendar.MINUTE, processCondition.getBaseDateModMinutes(), signum);
                addField(cal, Calendar.SECOND, processCondition.getBaseDateModSeconds(), signum);
                break;
            case Overwrite:
                setField(cal, Calendar.YEAR, processCondition.getBaseDateModYears());
                setField(cal, Calendar.MONTH, processCondition.getBaseDateModMonths());
                setField(cal, Calendar.DAY_OF_MONTH, processCondition.getBaseDateModDays());
                setField(cal, Calendar.HOUR_OF_DAY, processCondition.getBaseDateModHours());
                setField(cal, Calendar.MINUTE, processCondition.getBaseDateModMinutes());
                setField(cal, Calendar.SECOND, processCondition.getBaseDateModSeconds());
                break;
            default:
                throw new IllegalStateException(processCondition.getBaseDateModType().toString());
            }
            baseDate = cal.getTime();
        }
    }

    return baseDate;
}

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

private void copyInternal(DavNode destination, boolean shallow) throws DavException {
    assert exists();
    assert attr.isPresent();
    if (!Files.isDirectory(destination.path.getParent())) {
        throw new DavException(DavServletResponse.SC_CONFLICT, "Destination's parent doesn't exist.");
    }//  w w  w.  ja  v a2 s .co  m

    try {
        if (shallow && destination instanceof DavFolder) {
            // http://www.webdav.org/specs/rfc2518.html#copy.for.collections
            Files.createDirectory(destination.path);
            BasicFileAttributeView attrView = Files.getFileAttributeView(destination.path,
                    BasicFileAttributeView.class);
            if (attrView != null) {
                BasicFileAttributes a = attr.get();
                attrView.setTimes(a.lastModifiedTime(), a.lastAccessTime(), a.creationTime());
            }
        } else {
            Files.walkFileTree(path,
                    new CopyingFileVisitor(path, destination.path, StandardCopyOption.REPLACE_EXISTING));
        }
    } catch (IOException e) {
        throw new DavException(DavServletResponse.SC_INTERNAL_SERVER_ERROR, e);
    }
}

From source file:eu.novait.imagerenamer.model.ImageFile.java

public ImageFile(String filepath) {
    this.filepath = new File(filepath);
    this.filename = this.filepath.getName();
    this.proposedFilename = "";
    this.extension = FilenameUtils.getExtension(this.filepath.getName());
    try {//from  w w w  .  j a v  a 2s .  c o m
        BasicFileAttributes attr = Files.readAttributes(this.filepath.toPath(), BasicFileAttributes.class);
        this.fileCreationDate = new Date(attr.creationTime().toMillis());
    } catch (IOException ex) {
        Logger.getLogger(ImageFile.class.getName()).log(Level.SEVERE, null, ex);
    }
    createThumbnail();
}

From source file:media_organizer.MediaInspector.java

public String get_file_creation_time(File file) throws IOException {
    // Find file creation time , etc
    Path f = file.toPath();/*from w w w. j a v a2s  .c  o m*/
    BasicFileAttributes attr;
    String fileCreationTime = null;
    try {
        attr = Files.readAttributes(f, BasicFileAttributes.class);
        fileCreationTime = attr.creationTime().toString();
        //System.out.println("create time: " + attr.creationTime());
        return fileCreationTime.replaceAll("[-:T.]", "_").replaceAll("[Z]", "");

    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        throw e;
    }
}

From source file:org.cryptomator.webdav.jackrabbit.resources.EncryptedFile.java

@Override
protected void determineProperties() {
    final Path path = ResourcePathUtils.getPhysicalPath(this);
    if (Files.exists(path)) {
        SeekableByteChannel channel = null;
        try {/*from  w  w w.  j  av  a2  s .c o  m*/
            channel = Files.newByteChannel(path, StandardOpenOption.READ);
            final Long contentLength = cryptor.decryptedContentLength(channel);
            properties.add(new DefaultDavProperty<Long>(DavPropertyName.GETCONTENTLENGTH, contentLength));

            final BasicFileAttributes attrs = Files.readAttributes(path, BasicFileAttributes.class);
            properties.add(new DefaultDavProperty<String>(DavPropertyName.CREATIONDATE,
                    FileTimeUtils.toRfc1123String(attrs.creationTime())));
            properties.add(new DefaultDavProperty<String>(DavPropertyName.GETLASTMODIFIED,
                    FileTimeUtils.toRfc1123String(attrs.lastModifiedTime())));
            properties.add(new HttpHeaderProperty(HttpHeader.ACCEPT_RANGES.asString(),
                    HttpHeaderValue.BYTES.asString()));
        } catch (IOException e) {
            LOG.error("Error determining metadata " + path.toString(), e);
            throw new IORuntimeException(e);
        } finally {
            IOUtils.closeQuietly(channel);
        }
    }
}