001package org.unix4j.unix.find; 002 003import java.io.File; 004 005import org.unix4j.util.Java7Util; 006 007/** 008 * Helper to access file attributes if compiled and run with Java 6 or older. 009 * Supports only last modified time and some basic attributes. 010 * <p> 011 * Use the singleton {@link #INSTANCE} which loads the Java7 version if possible 012 * with support for more file attributes. 013 */ 014class FileAttributes { 015 016 /** 017 * Singleton instance loading the Java7 version if possible with support for 018 * more file attributes. 019 */ 020 public static final FileAttributes INSTANCE = Java7Util.newInstance(FileAttributes.class, new FileAttributes()); 021 022 /** 023 * For subclass only, use {@link #INSTANCE} instead. 024 */ 025 protected FileAttributes() { 026 super(); 027 } 028 029 public long getLastModifiedTime(File file) { 030 return file.lastModified(); 031 } 032 public long getLastAccessedTime(File file) { 033 return file.lastModified();//fallback if no Java7 034 } 035 public long getCreationTime(File file) { 036 return file.lastModified();//fallback if no Java7 037 } 038 039 public boolean isDirectory(File file) { 040 return file.isDirectory(); 041 } 042 public boolean isRegularFile(File file) { 043 return file.isFile(); 044 } 045 public boolean isSymbolicLink(File file) { 046 return false; 047 } 048 public boolean isOther(File file) { 049 return !isDirectory(file) && !isRegularFile(file) && !isSymbolicLink(file); 050 } 051}