Class PathHandle
- All Implemented Interfaces:
ResourceHandle, Rebindable
This handle provides access to real files on the host filesystem and is categorized as a non-virtual (physical) source.
- Author:
- anahata
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final @NonNull StringThe absolute path to the local file.Fields inherited from class AbstractResourceHandle
owner -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanexists()Checks if the resource physically or virtually exists.longReturns the last modified timestamp in milliseconds.Returns the detected MIME type of the resource.getName()Returns a user-friendly name for the source.getUri()Gets the unique URI for this resource.booleanDetermines if this is a virtual, memory-backed handle.booleanDetermines if the resource is writable in the current environment.longlength()Returns the total length of the resource content in characters/bytes.Opens a fresh input stream to the resource content.voidAgnostically writes text content back to the resource.Methods inherited from class AbstractResourceHandle
rebindMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface ResourceHandle
asBytes, asText, dispose, getCharset, getHeader, getHtmlDisplayName, getOwner, isModified, isStale, isTextual, setOwner
-
Field Details
-
path
The absolute path to the local file.
-
-
Constructor Details
-
PathHandle
public PathHandle()
-
-
Method Details
-
getName
Returns a user-friendly name for the source.Extracts the file name from the path.
- Returns:
- The source name.
-
getUri
Gets the unique URI for this resource.Returns the file:// URI for the path.
- Returns:
- The identifier URI.
-
getMimeType
Returns the detected MIME type of the resource.Uses Apache Tika for robust MIME detection of disk files.
- Returns:
- The MIME type string (e.g., "text/plain", "image/png").
-
getLastModified
public long getLastModified()Returns the last modified timestamp in milliseconds.Retrieves the last modified time from the filesystem.
- Returns:
- The timestamp, or 0 if unknown.
-
exists
public boolean exists()Checks if the resource physically or virtually exists.Checks if the file exists on the filesystem.
- Returns:
- true if the source is available.
-
openStream
Opens a fresh input stream to the resource content.Opens a standard filesystem input stream.
- Returns:
- A new InputStream instance.
- Throws:
IOException- if the stream cannot be opened.
-
isWritable
public boolean isWritable()Determines if the resource is writable in the current environment.Determines writability based on OS permissions.
- Returns:
- true if the handle supports the
ResourceHandle.write(String)operation.
-
write
Agnostically writes text content back to the resource.Purity Note: Read-only handles should throw
UnsupportedOperationException.Writes content using atomic filesystem options (TRUNCATE_EXISTING).
- Parameters:
content- The text to write.- Throws:
IOException- if the write fails.
-
isVirtual
public boolean isVirtual()Determines if this is a virtual, memory-backed handle.High-Fidelity Strategy: Virtual handles (snippets) typically trigger the 'Preview-as-Editor' mode in viewers to ensure constant IDE fidelity without card-swapping.
Implementation details: returns
falseas this is a physical filesystem resource.- Returns:
- true if virtual (in-memory content).
-
length
public long length()Returns the total length of the resource content in characters/bytes.Returns the physical file size on disk.
- Returns:
- The length, or -1 if the length is unknown or streaming.
-

