Interface Source
- All Superinterfaces:
CapabilityProvider, Container, HintProvider, InformationProvider
- All Known Implementing Classes:
DataBufferSource, DiskCopyImage, FileEntrySource, FileEntrySource, FileSource, UniversalDiskImage
Source and Factory for an archive or disk in AppleCommander.
Typical usage:
import com.webcodepro.applecommander.storage.Sources;
import java.util.Optional;
Optional<source> sourceOpt = Sources.create(Path.of(filename));
if (sourceOpt.isPresent()) {
// do something with the Source
Source source = sourceOpt.get();
System.out.println(source.getSize());
}
else {
// Only happens if the initiating object is not understood
throw new RuntimeException("Unable to create image source");
}
Optionally, you can use the Optional's more fluent API and write code like this:
import com.webcodepro.applecommander.storage.Sources;
Sources.create(Path.of(filename)).ifPresent(source -> {
// do something with the Source
System.out.println(source.getSize());
});
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic interfaceThis is the Source creation factory interface. -
Method Summary
Modifier and TypeMethodDescriptiondefault booleanextensionLike(String extension) Test if this name has a given file extension.getName()The name of the source.intgetSize()Indicates the physical size of this image on disk.booleanIndicates if this source has changed.voidhasChanged(boolean hasChanged) Sets the changed indicator.default booleanisApproxBetween(int value1, int value2) Indicates if the source image is "approximately" between these two values (less any image over-read).default booleanisApproxEQ(int value) Indicates if the source image is approximately equal to this size (less any image over-read).Read all bytes from this source.readBytes(int offset, int length) Read a range of bytes from this source.voidreplaceAllBytes(DataBuffer data) Replace ALL bytes in this Source.default voidsave()Save the image back to the origin.voidwriteBytes(int offset, DataBuffer data) Write bytes to this source.Methods inherited from interface CapabilityProvider
canMethods inherited from interface HintProvider
is, isAnyMethods inherited from interface InformationProvider
information
-
Method Details
-
getSize
int getSize()Indicates the physical size of this image on disk. -
getName
String getName()The name of the source. It likely will be used in user interfaces. It could represent a file from the computer or even a file from a file store. -
readAllBytes
DataBuffer readAllBytes()Read all bytes from this source. -
readBytes
Read a range of bytes from this source. -
writeBytes
Write bytes to this source. Updates the changed status. -
replaceAllBytes
Replace ALL bytes in this Source. -
hasChanged
boolean hasChanged()Indicates if this source has changed. -
hasChanged
void hasChanged(boolean hasChanged) Sets the changed indicator. -
save
Save the image back to the origin. Note that this could conceivably save back to the OS file system, or back to a file store. Use the
CapabilityProvider#canto see if a save is possible. The save operation should clear the change indicator.For example:
if (source.can(Capability.SAVE_SOURCE)) { source.save(); }Note that the capability can be used to enable appropriate options. If source cannot be saved, a "Save As" type operation can be applied and the source switched for the
FileStorein question.- Throws:
IOException- if an error occurs while saving the source.UnsupportedOperationException- if the source does not support the save operation.
-
isApproxEQ
default boolean isApproxEQ(int value) Indicates if the source image is approximately equal to this size (less any image over-read). Currently, hardcoded to allow up to 255 extra bytes at the end of a disk image. Must be at least the requested size! -
isApproxBetween
default boolean isApproxBetween(int value1, int value2) Indicates if the source image is "approximately" between these two values (less any image over-read). Currently, hardcoded to allow up to 255 extra bytes at the end of a disk image. Must be at least the requested size! -
extensionLike
Test if this name has a given file extension.
-