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 Classes
    Modifier and Type
    Interface
    Description
    static interface 
    This is the Source creation factory interface.
  • Method Summary

    Modifier and Type
    Method
    Description
    default boolean
    extensionLike(String extension)
    Test if this name has a given file extension.
    The name of the source.
    int
    Indicates the physical size of this image on disk.
    boolean
    Indicates if this source has changed.
    void
    hasChanged(boolean hasChanged)
    Sets the changed indicator.
    default boolean
    isApproxBetween(int value1, int value2)
    Indicates if the source image is "approximately" between these two values (less any image over-read).
    default boolean
    isApproxEQ(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.
    void
    Replace ALL bytes in this Source.
    default void
    Save the image back to the origin.
    void
    writeBytes(int offset, DataBuffer data)
    Write bytes to this source.

    Methods inherited from interface CapabilityProvider

    can

    Methods inherited from interface Container

    get

    Methods inherited from interface HintProvider

    is, isAny

    Methods 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

      DataBuffer readBytes(int offset, int length)
      Read a range of bytes from this source.
    • writeBytes

      void writeBytes(int offset, DataBuffer data)
      Write bytes to this source. Updates the changed status.
    • replaceAllBytes

      void replaceAllBytes(DataBuffer data)
      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

      default void save() throws IOException

      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#can to 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 FileStore in 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

      default boolean extensionLike(String extension)
      Test if this name has a given file extension.