Package com.google.common.jimfs
Class File
- java.lang.Object
-
- com.google.common.jimfs.File
-
- Direct Known Subclasses:
Directory,RegularFile,SymbolicLink
public abstract class File extends java.lang.ObjectA file object, containing both the file's metadata and content.
-
-
Field Summary
Fields Modifier and Type Field Description private @Nullable com.google.common.collect.Table<java.lang.String,java.lang.String,java.lang.Object>attributesprivate java.nio.file.attribute.FileTimecreationTimeprivate intidprivate java.nio.file.attribute.FileTimelastAccessTimeprivate java.nio.file.attribute.FileTimelastModifiedTimeprivate intlinks
-
Constructor Summary
Constructors Constructor Description File(int id, java.nio.file.attribute.FileTime creationTime)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description (package private) voidclosed()Called when a stream or channel to this file is closed.(package private) @Nullable java.util.concurrent.locks.ReadWriteLockcontentLock()Returns the read-write lock for this file's content, ornullif there is no content lock.(package private) voidcopyAttributes(File target)Copies the attributes from this file to the given file.(package private) voidcopyBasicAttributes(File target)Copies basic attributes (file times) from this file to the given file.(package private) voidcopyContentTo(File file)Copies the content of this file to the given file.(package private) abstract FilecopyWithoutContent(int id, java.nio.file.attribute.FileTime creationTime)Creates a new file of the same type as this file with the given ID and creation time.(package private) voiddecrementLinkCount()Decrements the link count for this file.voiddeleteAttribute(java.lang.String view, java.lang.String attribute)Deletes the given attribute from the given view.(package private) voiddeleted()Called when (a single link to) this file is deleted.@Nullable java.lang.ObjectgetAttribute(java.lang.String view, java.lang.String attribute)Gets the value of the given attribute in the given view.(package private) com.google.common.collect.ImmutableSet<java.lang.String>getAttributeKeys()Returns the attribute keys contained in the attributes map for the file.com.google.common.collect.ImmutableSet<java.lang.String>getAttributeNames(java.lang.String view)Returns the names of the attributes contained in the given attribute view in the file's attributes table.java.nio.file.attribute.FileTimegetCreationTime()Gets the creation time of the file.java.nio.file.attribute.FileTimegetLastAccessTime()Gets the last access time of the file.java.nio.file.attribute.FileTimegetLastModifiedTime()Gets the last modified time of the file.intid()Returns the ID of this file.(package private) voidincrementLinkCount()Increments the link count for this file.booleanisDirectory()Returns whether or not this file is a directory.booleanisRegularFile()Returns whether or not this file is a regular file.(package private) booleanisRootDirectory()Returns whether or not this file is a root directory of the file system.booleanisSymbolicLink()Returns whether or not this file is a symbolic link.(package private) voidlinked(DirectoryEntry entry)Called when this file has been linked in a directory.intlinks()Returns the current count of links to this file.(package private) voidopened()Called when a stream or channel to this file is opened.private voidputAll(@Nullable com.google.common.collect.Table<java.lang.String,java.lang.String,java.lang.Object> attributes)voidsetAttribute(java.lang.String view, java.lang.String attribute, java.lang.Object value)Sets the given attribute in the given view to the given value.(package private) voidsetCreationTime(java.nio.file.attribute.FileTime creationTime)Sets the creation time of the file.private voidsetFileTimes(java.nio.file.attribute.FileTime creationTime, java.nio.file.attribute.FileTime lastModifiedTime, java.nio.file.attribute.FileTime lastAccessTime)(package private) voidsetLastAccessTime(java.nio.file.attribute.FileTime lastAccessTime)Sets the last access time of the file.(package private) voidsetLastModifiedTime(java.nio.file.attribute.FileTime lastModifiedTime)Sets the last modified time of the file.longsize()Returns the size, in bytes, of this file's content.java.lang.StringtoString()(package private) voidunlinked()Called when this file has been unlinked from a directory, either for a move or delete.
-
-
-
Field Detail
-
id
private final int id
-
links
private int links
-
creationTime
private java.nio.file.attribute.FileTime creationTime
-
lastAccessTime
private java.nio.file.attribute.FileTime lastAccessTime
-
lastModifiedTime
private java.nio.file.attribute.FileTime lastModifiedTime
-
attributes
private @Nullable com.google.common.collect.Table<java.lang.String,java.lang.String,java.lang.Object> attributes
-
-
Method Detail
-
id
public int id()
Returns the ID of this file.
-
size
public long size()
Returns the size, in bytes, of this file's content. Directories and symbolic links have a size of 0.
-
isDirectory
public final boolean isDirectory()
Returns whether or not this file is a directory.
-
isRegularFile
public final boolean isRegularFile()
Returns whether or not this file is a regular file.
-
isSymbolicLink
public final boolean isSymbolicLink()
Returns whether or not this file is a symbolic link.
-
copyWithoutContent
abstract File copyWithoutContent(int id, java.nio.file.attribute.FileTime creationTime)
Creates a new file of the same type as this file with the given ID and creation time. Does not copy the content of this file unless the cost of copying the content is minimal. This is because this method is called with a hold on the file system's lock.
-
copyContentTo
void copyContentTo(File file) throws java.io.IOException
Copies the content of this file to the given file. The given file must be the same type of file as this file and should have no content.This method is used for copying the content of a file after copying the file itself. Does nothing by default.
- Throws:
java.io.IOException
-
contentLock
@Nullable java.util.concurrent.locks.ReadWriteLock contentLock()
Returns the read-write lock for this file's content, ornullif there is no content lock.
-
opened
void opened()
Called when a stream or channel to this file is opened.
-
closed
void closed()
Called when a stream or channel to this file is closed. If there are no more streams or channels open to the file and it has been deleted, its contents may be deleted.
-
deleted
void deleted()
Called when (a single link to) this file is deleted. There may be links remaining. Does nothing by default.
-
isRootDirectory
final boolean isRootDirectory()
Returns whether or not this file is a root directory of the file system.
-
links
public final int links()
Returns the current count of links to this file.
-
linked
void linked(DirectoryEntry entry)
Called when this file has been linked in a directory. The given entry is the new directory entry that links to this file.
-
unlinked
void unlinked()
Called when this file has been unlinked from a directory, either for a move or delete.
-
incrementLinkCount
final void incrementLinkCount()
Increments the link count for this file.
-
decrementLinkCount
final void decrementLinkCount()
Decrements the link count for this file.
-
getCreationTime
public final java.nio.file.attribute.FileTime getCreationTime()
Gets the creation time of the file.
-
getLastAccessTime
public final java.nio.file.attribute.FileTime getLastAccessTime()
Gets the last access time of the file.
-
getLastModifiedTime
public final java.nio.file.attribute.FileTime getLastModifiedTime()
Gets the last modified time of the file.
-
setCreationTime
final void setCreationTime(java.nio.file.attribute.FileTime creationTime)
Sets the creation time of the file.
-
setLastAccessTime
final void setLastAccessTime(java.nio.file.attribute.FileTime lastAccessTime)
Sets the last access time of the file.
-
setLastModifiedTime
final void setLastModifiedTime(java.nio.file.attribute.FileTime lastModifiedTime)
Sets the last modified time of the file.
-
getAttributeNames
public final com.google.common.collect.ImmutableSet<java.lang.String> getAttributeNames(java.lang.String view)
Returns the names of the attributes contained in the given attribute view in the file's attributes table.
-
getAttributeKeys
final com.google.common.collect.ImmutableSet<java.lang.String> getAttributeKeys()
Returns the attribute keys contained in the attributes map for the file.
-
getAttribute
public final @Nullable java.lang.Object getAttribute(java.lang.String view, java.lang.String attribute)Gets the value of the given attribute in the given view.
-
setAttribute
public final void setAttribute(java.lang.String view, java.lang.String attribute, java.lang.Object value)Sets the given attribute in the given view to the given value.
-
deleteAttribute
public final void deleteAttribute(java.lang.String view, java.lang.String attribute)Deletes the given attribute from the given view.
-
copyBasicAttributes
final void copyBasicAttributes(File target)
Copies basic attributes (file times) from this file to the given file.
-
setFileTimes
private void setFileTimes(java.nio.file.attribute.FileTime creationTime, java.nio.file.attribute.FileTime lastModifiedTime, java.nio.file.attribute.FileTime lastAccessTime)
-
copyAttributes
final void copyAttributes(File target)
Copies the attributes from this file to the given file.
-
putAll
private void putAll(@Nullable com.google.common.collect.Table<java.lang.String,java.lang.String,java.lang.Object> attributes)
-
toString
public final java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-