Class FileConfigSource
java.lang.Object
com.kamikazejam.kamicommon.yaml.source.FileConfigSource
- All Implemented Interfaces:
ConfigSource
A
Supports both read and write (save) operations.
ConfigSource implementation that reads from and writes to a file on the filesystem.Supports both read and write (save) operations.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription@Nullable FileReturns the underlying File if this source is file-backed; otherwise null.
Useful for compatibility with APIs that require a File.booleanEnsures the writable source has any required backing structures (e.g., parent directories/files).
No-op for read-only sources.@NotNull StringReturns the path to a resource stream for default configuration data, if available.
This is typically used to load default settings bundled with the application/plugin.
If no resource stream is associated, may return null.@NotNull Stringid()A human-readable identifier for this source (e.g., absolute file path, URL, logical name).
Uniqueness is not required and the value is intended primarily for logging/debugging.booleanIndicates whether this source supports persisting data via write(...).@NotNull Optional<InputStream>Opens a fresh InputStream for the current contents of this source.
The caller is responsible for closing the returned stream.booleanWrites serialized data to this source using the provided charset.
Implementations should overwrite the existing contents atomically when possible.
For read-only sources, this method must throw UnsupportedOperationException.
-
Constructor Details
-
FileConfigSource
-
-
Method Details
-
id
Description copied from interface:ConfigSourceA human-readable identifier for this source (e.g., absolute file path, URL, logical name).
Uniqueness is not required and the value is intended primarily for logging/debugging.- Specified by:
idin interfaceConfigSource- Returns:
- identifier string for this source (not necessarily unique)
-
openStream
Description copied from interface:ConfigSourceOpens a fresh InputStream for the current contents of this source.
The caller is responsible for closing the returned stream.- Specified by:
openStreamin interfaceConfigSource- Returns:
- an Optional containing a new InputStream if content is available; empty if absent
- Throws:
IOException- if the stream cannot be opened due to I/O errors
-
isWritable
public boolean isWritable()Description copied from interface:ConfigSourceIndicates whether this source supports persisting data via write(...).- Specified by:
isWritablein interfaceConfigSource- Returns:
- true if writable; false if read-only
-
ensureExistsIfWritable
Description copied from interface:ConfigSourceEnsures the writable source has any required backing structures (e.g., parent directories/files).
No-op for read-only sources.- Specified by:
ensureExistsIfWritablein interfaceConfigSource- Returns:
- true if the source exists or was created successfully; false otherwise
- Throws:
IOException- if creation fails due to I/O errors
-
write
Description copied from interface:ConfigSourceWrites serialized data to this source using the provided charset.
Implementations should overwrite the existing contents atomically when possible.
For read-only sources, this method must throw UnsupportedOperationException.- Specified by:
writein interfaceConfigSource- Parameters:
data- bytes to persistcharset- character set used to interpret textual data (if relevant)- Returns:
- true if the data was persisted successfully; false otherwise
- Throws:
IOException- if an I/O error occurs while writing
-
asFileIfPresent
Description copied from interface:ConfigSourceReturns the underlying File if this source is file-backed; otherwise null.
Useful for compatibility with APIs that require a File.- Specified by:
asFileIfPresentin interfaceConfigSource- Returns:
- File when applicable; null for non-file-backed sources
-
getResourceStreamPath
Description copied from interface:ConfigSourceReturns the path to a resource stream for default configuration data, if available.
This is typically used to load default settings bundled with the application/plugin.
If no resource stream is associated, may return null.- Specified by:
getResourceStreamPathin interfaceConfigSource
-