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.Object
A 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>
attributes
private java.nio.file.attribute.FileTime
creationTime
private int
id
private java.nio.file.attribute.FileTime
lastAccessTime
private java.nio.file.attribute.FileTime
lastModifiedTime
private int
links
-
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) void
closed()
Called when a stream or channel to this file is closed.(package private) @Nullable java.util.concurrent.locks.ReadWriteLock
contentLock()
Returns the read-write lock for this file's content, ornull
if there is no content lock.(package private) void
copyAttributes(File target)
Copies the attributes from this file to the given file.(package private) void
copyBasicAttributes(File target)
Copies basic attributes (file times) from this file to the given file.(package private) void
copyContentTo(File file)
Copies the content of this file to the given file.(package private) 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.(package private) void
decrementLinkCount()
Decrements the link count for this file.void
deleteAttribute(java.lang.String view, java.lang.String attribute)
Deletes the given attribute from the given view.(package private) void
deleted()
Called when (a single link to) this file is deleted.@Nullable java.lang.Object
getAttribute(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.FileTime
getCreationTime()
Gets the creation time of the file.java.nio.file.attribute.FileTime
getLastAccessTime()
Gets the last access time of the file.java.nio.file.attribute.FileTime
getLastModifiedTime()
Gets the last modified time of the file.int
id()
Returns the ID of this file.(package private) void
incrementLinkCount()
Increments the link count for this file.boolean
isDirectory()
Returns whether or not this file is a directory.boolean
isRegularFile()
Returns whether or not this file is a regular file.(package private) boolean
isRootDirectory()
Returns whether or not this file is a root directory of the file system.boolean
isSymbolicLink()
Returns whether or not this file is a symbolic link.(package private) void
linked(DirectoryEntry entry)
Called when this file has been linked in a directory.int
links()
Returns the current count of links to this file.(package private) void
opened()
Called when a stream or channel to this file is opened.private void
putAll(@Nullable com.google.common.collect.Table<java.lang.String,java.lang.String,java.lang.Object> attributes)
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.(package private) void
setCreationTime(java.nio.file.attribute.FileTime creationTime)
Sets the creation time of the file.private void
setFileTimes(java.nio.file.attribute.FileTime creationTime, java.nio.file.attribute.FileTime lastModifiedTime, java.nio.file.attribute.FileTime lastAccessTime)
(package private) void
setLastAccessTime(java.nio.file.attribute.FileTime lastAccessTime)
Sets the last access time of the file.(package private) void
setLastModifiedTime(java.nio.file.attribute.FileTime lastModifiedTime)
Sets the last modified time of the file.long
size()
Returns the size, in bytes, of this file's content.java.lang.String
toString()
(package private) void
unlinked()
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, ornull
if 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:
toString
in classjava.lang.Object
-
-