Class DocumentFile

  • All Implemented Interfaces:
    java.io.Closeable, java.lang.AutoCloseable, Document

    public class DocumentFile
    extends java.lang.Object
    implements Document, java.io.Closeable
    Implementation that handles a Document as a file in the filesystem and receives operations in a sorted manner (i.e. the regions are sorted). This improves the efficiency of reading the file by only scanning it once while operations are applied, until an instance of this document is closed.
    • Constructor Summary

      Constructors 
      Constructor Description
      DocumentFile​(java.io.File file, java.nio.charset.Charset charset)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void close()  
      void delete​(RegionByLine regionByOffset)
      Delete a region in the document, removing all text which contains it.
      void insert​(int beginLine, int beginColumn, java.lang.String textToInsert)
      Insert a text at a line at the position/column specified.
      void replace​(RegionByLine regionByLine, java.lang.String textToReplace)
      Replace a specific region in the document which contains text by another text, which not necessarily is the same length as the region's one.
      • Methods inherited from class java.lang.Object

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

      • DocumentFile

        public DocumentFile​(java.io.File file,
                            java.nio.charset.Charset charset)
                     throws java.io.IOException
        Throws:
        java.io.IOException
    • Method Detail

      • insert

        public void insert​(int beginLine,
                           int beginColumn,
                           java.lang.String textToInsert)
        Description copied from interface: Document
        Insert a text at a line at the position/column specified. If there is any text to the right of the insertion, that text is shifted by the length of the text to insert, which means that it is not replaced.
        Specified by:
        insert in interface Document
        Parameters:
        beginLine - the line in which to insert the text
        beginColumn - the position in the line in which to insert the text
        textToInsert - the text to be added
      • replace

        public void replace​(RegionByLine regionByLine,
                            java.lang.String textToReplace)
        Description copied from interface: Document
        Replace a specific region in the document which contains text by another text, which not necessarily is the same length as the region's one.
        Specified by:
        replace in interface Document
        Parameters:
        regionByLine - the region in which a text will be inserted to replace the current document's contents
        textToReplace - the text to insert
      • delete

        public void delete​(RegionByLine regionByOffset)
        Description copied from interface: Document
        Delete a region in the document, removing all text which contains it. If there is any text to the right of this region, it will be shifted to the left by the length of the region to delete.
        Specified by:
        delete in interface Document
        Parameters:
        regionByOffset - the region in which to erase all the text
      • close

        public void close()
                   throws java.io.IOException
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.io.Closeable
        Throws:
        java.io.IOException