Code example for Path

Methods: getFileNamegetParent

0
import org.springframework.integration.message.GenericMessage; 
 
import com.github.hakko.musiccabinet.domain.model.aggr.DirectoryContent; 
import com.github.hakko.musiccabinet.domain.model.library.File; 
import com.github.hakko.musiccabinet.log.Logger; 
 
public class LibraryScanner extends SimpleFileVisitor<Path> {
 
	private static final Logger LOG = Logger.getLogger(LibraryScanner.class); 
 
	private Map<Path, DirectoryContent> map = new HashMap<>();
	 
	private PollableChannel libraryPresenceChannel;
	 
    public LibraryScanner(PollableChannel libraryPresenceChannel) {
		this.libraryPresenceChannel = libraryPresenceChannel;
	} 
 
	@Override 
    public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) {
    	DirectoryContent parentContent = map.get(dir.getParent());
    	if (parentContent != null) {
    		parentContent.getSubDirectories().add(dir.toString());
    	} 
    	map.put(dir, new DirectoryContent(dir.toString()));
    	 
    	return CONTINUE;
    } 
	 
    @Override 
    public FileVisitResult visitFile(Path file, BasicFileAttributes attr) {
    	DirectoryContent directoryContent = map.get(file.getParent());
    	if (attr.size() > Integer.MAX_VALUE) {
    		LOG.warn(file.getFileName() + " has actual file size " + attr.size());
    	} 
    	directoryContent.getFiles().add(new File(file, attr));
    	 
    	return CONTINUE;
    }