Class IO

  • Direct Known Subclasses:
    DocIO, ToolIO

    public abstract class IO
    extends java.lang.Object
    Author:
    Group 3
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected java.lang.Boolean allowSave  
      protected java.lang.String docName
      Document Name.
      protected static java.lang.String imagesDirString  
      protected static java.lang.String mediaDirString  
      protected java.util.Optional<nu.xom.Document> myDoc
      Open Document.
      protected java.io.File origZip  
      protected static java.lang.String scriptsDirString  
      protected static java.lang.String tempFilePrefix  
      protected java.util.HashMap<java.lang.String,​java.nio.file.Path> tempFiles
      Temporary files requiring cleanup.
      protected java.nio.file.Path tempPath  
      protected java.nio.file.FileSystem zipFs  
    • Constructor Summary

      Constructors 
      Constructor Description
      IO​(java.io.InputStream presStream)
      Build from a byte array.
      IO​(java.lang.String presFilePath)
      Create new IO and parse the project doc.
    • Method Summary

      All Methods Static Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      boolean canSave()
      Am I allowed to save the open doc?
      void close()
      Closes associated File Systems.
      protected static java.util.Optional<java.io.File> getArchive​(java.net.URI target)
      Retrieve a presentation archive.
      java.util.Optional<nu.xom.Document> getDoc()
      Get parsed document.
      static java.util.Optional<byte[]> getInternalResource​(java.lang.String file, java.lang.Class resClass)
      Get an internal class-path resource as bytes.
      java.util.Optional<byte[]> getResource​(java.lang.String path)
      Get a resource from the zip.
      java.util.Optional<java.lang.String> getResourceTempPath​(java.lang.String path)
      Extract a resource from the zip and return its path.
      static java.lang.Boolean isUriInternal​(java.lang.String path)
      Check if given Path should be in the ZIP archive.
      protected static java.util.Optional<java.nio.file.FileSystem> makeFs​(java.nio.file.Path path)
      Make a new Zip FS.
      java.util.Optional<java.net.URI> maybeURI​(java.lang.String UrString)
      Returns a maybe URI from an input string containing an URI.
      java.lang.String pathToUriString​(java.lang.String path)
      Turn a (possibly relative) path into a correct URI.
      protected abstract java.util.Optional<nu.xom.Document> retrieveDoc​(java.nio.file.FileSystem fs)
      Get doc from FileSystem.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • imagesDirString

        protected static final java.lang.String imagesDirString
        See Also:
        Constant Field Values
      • scriptsDirString

        protected static final java.lang.String scriptsDirString
        See Also:
        Constant Field Values
      • docName

        protected java.lang.String docName
        Document Name.
      • origZip

        protected java.io.File origZip
      • myDoc

        protected final java.util.Optional<nu.xom.Document> myDoc
        Open Document.
      • zipFs

        protected java.nio.file.FileSystem zipFs
      • tempPath

        protected java.nio.file.Path tempPath
      • allowSave

        protected java.lang.Boolean allowSave
      • tempFiles

        protected final java.util.HashMap<java.lang.String,​java.nio.file.Path> tempFiles
        Temporary files requiring cleanup.
    • Constructor Detail

      • IO

        public IO​(java.lang.String presFilePath)
        Create new IO and parse the project doc.
        Parameters:
        presFilePath - path to pres. Zip.
      • IO

        public IO​(java.io.InputStream presStream)
        Build from a byte array.
        Parameters:
        presStream - Stream containing archive.
    • Method Detail

      • retrieveDoc

        protected abstract java.util.Optional<nu.xom.Document> retrieveDoc​(java.nio.file.FileSystem fs)
        Get doc from FileSystem. Must be implemented by subclass!
        Parameters:
        fs - FileSystem
        Returns:
        Maybe Doc.
      • makeFs

        protected static final java.util.Optional<java.nio.file.FileSystem> makeFs​(java.nio.file.Path path)
        Make a new Zip FS.
        Parameters:
        path - Path to zip
        Returns:
        Maybe FS.
      • getArchive

        protected static final java.util.Optional<java.io.File> getArchive​(java.net.URI target)
        Retrieve a presentation archive.
        Parameters:
        target - URI of target zip.
        Returns:
        Maybe zip file.
      • getDoc

        public java.util.Optional<nu.xom.Document> getDoc()
        Get parsed document.
        Returns:
        Optional document.
      • getResource

        public java.util.Optional<byte[]> getResource​(java.lang.String path)
        Get a resource from the zip.
        Parameters:
        path - Resource path.
        Returns:
        Optional resource bytes.
      • getResourceTempPath

        public java.util.Optional<java.lang.String> getResourceTempPath​(java.lang.String path)
        Extract a resource from the zip and return its path.
        Parameters:
        path - Resource path.
        Returns:
        Optional resource bytes.
      • isUriInternal

        public static java.lang.Boolean isUriInternal​(java.lang.String path)
        Check if given Path should be in the ZIP archive.
        Parameters:
        path - Path to check.
        Returns:
        True or False.
      • getInternalResource

        public static java.util.Optional<byte[]> getInternalResource​(java.lang.String file,
                                                                     java.lang.Class resClass)
        Get an internal class-path resource as bytes.
        Parameters:
        file - File to return.
        resClass - Class to look in.
        Returns:
        Maybe file bytes.
      • canSave

        public boolean canSave()
        Am I allowed to save the open doc?
        Returns:
        Boolean.
      • pathToUriString

        public java.lang.String pathToUriString​(java.lang.String path)
        Turn a (possibly relative) path into a correct URI.
        Parameters:
        path - Path to convert.
        Returns:
        Converted path.
      • maybeURI

        public java.util.Optional<java.net.URI> maybeURI​(java.lang.String UrString)
        Returns a maybe URI from an input string containing an URI.
        Parameters:
        UrString - URI/Path String.
        Returns:
        Maybe URI.
      • close

        public void close()
        Closes associated File Systems. Must be run when object is finished with.