|
Commons IO example source code file (FileEntry.java)
The Commons IO FileEntry.java source code
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.commons.io.monitor;
import java.io.File;
import java.io.Serializable;
/**
* {@link FileEntry} represents the state of a file or directory, capturing
* the following {@link File} attributes at a point in time.
* <ul>
* <li>File Name (see {@link File#getName()})
* <li>Exists - whether the file exists or not (see {@link File#exists()})
* <li>Directory - whether the file is a directory or not (see {@link File#isDirectory()})
* <li>Last Modified Date/Time (see {@link File#lastModified()})
* <li>Length (see {@link File#length()}) - directories treated as zero
* <li>Children - contents of a directory (see {@link File#listFiles(java.io.FileFilter)})
* </ul>
* <p>
* <h3>Custom Implementations
* If the state of additional {@link File} attributes is required then create a custom
* {@link FileEntry} with properties for those attributes. Override the
* {@link #newChildInstance(File)} to return a new instance of the appropriate type.
* You may also want to override the {@link #refresh(File)} method.
* @see FileAlterationObserver
* @since Commons IO 2.0
*/
public class FileEntry implements Serializable {
static final FileEntry[] EMPTY_ENTRIES = new FileEntry[0];
private final FileEntry parent;
private FileEntry[] children;
private final File file;
private String name;
private boolean exists;
private boolean directory;
private long lastModified;
private long length;
/**
* Construct a new monitor for a specified {@link File}.
*
* @param file The file being monitored
*/
public FileEntry(File file) {
this((FileEntry)null, file);
}
/**
* Construct a new monitor for a specified {@link File}.
*
* @param parent The parent
* @param file The file being monitored
*/
public FileEntry(FileEntry parent, File file) {
if (file == null) {
throw new IllegalArgumentException("File is missing");
}
this.file = file;
this.parent = parent;
this.name = file.getName();
}
/**
* Refresh the attributes from the {@link File}, indicating
* whether the file has changed.
* <p>
* This implementation refreshes the <code>name,
Other Commons IO examples (source code examples)Here is a short list of links related to this Commons IO FileEntry.java source code file: |
| ... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2024 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.