Class StringHandle
- All Implemented Interfaces:
ResourceHandle, Rebindable
This handle allows arbitrary strings to be managed as V2 Resources. It is primarily used for chat code blocks and tool parameters, enabling them to use the same high-fidelity viewer pipeline as physical files.
- Author:
- anahata
-
Field Summary
FieldsModifier and TypeFieldDescriptionCustom attributes for host-aware context propagation (e.g. classpath hints).private StringThe actual text content held in memory.private StringOptional context path to hint IDEs about the project/location this snippet belongs to.private longThe last modification timestamp.private final StringThe display name of the snippet.private final URIThe memory URI of the snippet.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.booleanDetermines if the resource is textual and suitable for a TextView.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.voidsetAttribute(String key, Object value) Sets a custom attribute on this virtual handle.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, getName, getOwner, getUri, isModified, isStale, setOwner
-
Field Details
-
uri
The memory URI of the snippet. -
name
The display name of the snippet. -
contextPath
Optional context path to hint IDEs about the project/location this snippet belongs to. -
The actual text content held in memory.
-
lastModified
private long lastModifiedThe last modification timestamp. -
attributes
-
-
Constructor Details
-
StringHandle
-
-
Method Details
-
setAttribute
-
getLastModified
public long getLastModified()Returns the last modified timestamp in milliseconds.Returns the mutable modification timestamp.
- Returns:
- The timestamp, or 0 if unknown.
-
exists
public boolean exists()Checks if the resource physically or virtually exists.Memory snippets always exist while the handle is alive.
- Returns:
- true if the source is available.
-
openStream
Opens a fresh input stream to the resource content.Opens a stream over the internal UTF-8 byte array.
- 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.Virtual snippets are always writable in memory.
- 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.Updates the internal string and notifies the owner orchestrator. Implements an equality gate to prevent redundant interpretation cycles.
- 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
trueas this is a memory handle.- Returns:
- true if virtual (in-memory content).
-
isTextual
public boolean isTextual()Determines if the resource is textual and suitable for a TextView.This method provides a centralized capability check. It whitelists common structured data formats that may be classified under the 'application/' hierarchy but are inherently textual.
Memory handles are always considered textual in the current platform version.
- Returns:
- true if the resource should be handled by a TextView.
-
getMimeType
Returns the detected MIME type of the resource.Memory handles default to text/plain. The viewer is responsible for environment-specific language detection via the resource name.
- Returns:
- The MIME type string (e.g., "text/plain", "image/png").
-
length
public long length()Returns the total length of the resource content in characters/bytes.Returns the length of the in-memory string.
- Returns:
- The length, or -1 if the length is unknown or streaming.
-

