如何获取由Java Client的最后修改邮票排序的文物文件夹的文件列表

发布于 2025-01-26 04:41:11 字数 1659 浏览 1 评论 0原文

我正在尝试在文物文件项上获得最后修改的时间戳,但它以null为单位。 我在此功能上做错了什么?

    public static List<File> listChildren(RepositoryHandle aRepo, String folder, FileFilter filter)
    {
        List<File> children = null;
        
        if (null == aRepo || null == folder || folder.length() <= 0)
            return null;
        try
        {
            folder = FilenameUtils.normalizeNoEndSeparator(folder, true);
            ItemHandle folderItem = aRepo.folder(folder);
            Folder folderInfo = folderItem.info();
            List<Item> itemChildren = folderInfo.getChildren();
            if (null == itemChildren)
                return null;
            children = new ArrayList<>(itemChildren.size());
            String name;
            File fileItem;
            for(Item curItem: itemChildren)
            {
                
                fileItem = new File(curItem.getUri());
                Date timeStamp = curItem.getLastModified(); // This is coming as null
                fileItem.setLastModified(curItem.getLastModified().getTime());
                name = fileItem.getName();
                if (null != name)
                {
                    if (null == filter ||
                        filter.accept(fileItem))
                        children.add(fileItem);
                }
            } 
            // Sort the list by last modified stamp so that the oldest is at the front
            Collections.sort(children, Comparator.comparingLong(File::lastModified));
        }
        catch (Throwable ex)
        {
            ex.printStackTrace();
        }
        return children;
    }

I am trying to get last modified time stamp on Artifactory file item, but it is coming as null.
What am I doing wrong with this function?

    public static List<File> listChildren(RepositoryHandle aRepo, String folder, FileFilter filter)
    {
        List<File> children = null;
        
        if (null == aRepo || null == folder || folder.length() <= 0)
            return null;
        try
        {
            folder = FilenameUtils.normalizeNoEndSeparator(folder, true);
            ItemHandle folderItem = aRepo.folder(folder);
            Folder folderInfo = folderItem.info();
            List<Item> itemChildren = folderInfo.getChildren();
            if (null == itemChildren)
                return null;
            children = new ArrayList<>(itemChildren.size());
            String name;
            File fileItem;
            for(Item curItem: itemChildren)
            {
                
                fileItem = new File(curItem.getUri());
                Date timeStamp = curItem.getLastModified(); // This is coming as null
                fileItem.setLastModified(curItem.getLastModified().getTime());
                name = fileItem.getName();
                if (null != name)
                {
                    if (null == filter ||
                        filter.accept(fileItem))
                        children.add(fileItem);
                }
            } 
            // Sort the list by last modified stamp so that the oldest is at the front
            Collections.sort(children, Comparator.comparingLong(File::lastModified));
        }
        catch (Throwable ex)
        {
            ex.printStackTrace();
        }
        return children;
    }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

拥抱影子 2025-02-02 04:41:11

以下是修改后的版本,为我提供了整理列表。

public static List<String> listChildren(RepositoryHandle aRepo, String folder, FileFilter filter)
    {
        List<String> children = null;
        
        if (null == aRepo || null == folder || folder.length() <= 0)
            return null;
        try
        {
            folder = FilenameUtils.normalizeNoEndSeparator(folder, true);
            ItemHandle folderItem = aRepo.folder(folder);
            Folder folderInfo = folderItem.info();
            List<Item> itemChildren = folderInfo.getChildren();
            if (null == itemChildren)
                return null;
            List<org.jfrog.artifactory.client.model.File> itemExtChildren = new ArrayList<>();
            for(Item curItem: itemChildren)
            {
                ItemHandle hItem = aRepo.file(folder+curItem.getUri());
                if (null == hItem)
                    continue;
                org.jfrog.artifactory.client.model.File aFile = hItem.info();
                itemExtChildren.add(aFile);
            }
            Collections.sort(itemExtChildren, (org.jfrog.artifactory.client.model.File f1, org.jfrog.artifactory.client.model.File f2) -> 
                                              f1.getLastModified().compareTo(f2.getLastModified()));
            children = new ArrayList<>(itemChildren.size());
            String name;
            for(Item curItem: itemExtChildren)
            {
                name = curItem.getName();
                if (null != name)
                {
                    if (null == filter ||
                        filter.accept(new File(name)))
                        children.add(name);
                }
            } 
        }
        catch (Throwable ex)
        {
        }
        return children;
    }

Below is modified version that gave me sorted list.

public static List<String> listChildren(RepositoryHandle aRepo, String folder, FileFilter filter)
    {
        List<String> children = null;
        
        if (null == aRepo || null == folder || folder.length() <= 0)
            return null;
        try
        {
            folder = FilenameUtils.normalizeNoEndSeparator(folder, true);
            ItemHandle folderItem = aRepo.folder(folder);
            Folder folderInfo = folderItem.info();
            List<Item> itemChildren = folderInfo.getChildren();
            if (null == itemChildren)
                return null;
            List<org.jfrog.artifactory.client.model.File> itemExtChildren = new ArrayList<>();
            for(Item curItem: itemChildren)
            {
                ItemHandle hItem = aRepo.file(folder+curItem.getUri());
                if (null == hItem)
                    continue;
                org.jfrog.artifactory.client.model.File aFile = hItem.info();
                itemExtChildren.add(aFile);
            }
            Collections.sort(itemExtChildren, (org.jfrog.artifactory.client.model.File f1, org.jfrog.artifactory.client.model.File f2) -> 
                                              f1.getLastModified().compareTo(f2.getLastModified()));
            children = new ArrayList<>(itemChildren.size());
            String name;
            for(Item curItem: itemExtChildren)
            {
                name = curItem.getName();
                if (null != name)
                {
                    if (null == filter ||
                        filter.accept(new File(name)))
                        children.add(name);
                }
            } 
        }
        catch (Throwable ex)
        {
        }
        return children;
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文