eXept Software AG Logo

Smalltalk/X Webserver

Documentation of class 'VirtualReadOnlyTextFileContents':

Home

Documentation
www.exept.de
Everywhere
for:
[back]

Class: VirtualReadOnlyTextFileContents


Inheritance:

   Object
   |
   +--Collection
      |
      +--SequenceableCollection
         |
         +--VirtualArray
            |
            +--VirtualArrayWithCache
               |
               +--VirtualReadOnlyTextFileContents

Package:
stx:libbasic2
Category:
Collections-Arrayed
Version:
rev: 1.2 date: 2022/05/05 15:20:21
user: cg
file: VirtualReadOnlyTextFileContents.st directory: libbasic2
module: stx stc-classLibrary: libbasic2
Author:
Claus Gittinger

Description:


I can be used to represent a huge file's contents as an array of lines.
(eg. for viewing in a text view).
When initialized, I will start a background reader to collect line start positions
of chunks; I will keep the numberOfLines/chunkSize number of start positions.
I will change my (virtual) size, as the reader processes the file.

When asked for a line, I will position to that chunk in the file and read
the line(s) as needed.

I will buffer one chunk (chunkSize) of lines, to speed up the presentation
of a few pages worth of text.


[instance variables:]
    lineChunkPositions  file position of chunks;
                        each chunk consists of chunkSize lines

    fileStream 
    lastReadPosition 
    lastLineRead 
    readProcess 
    chunkSize
    chunkReadSemaphore 
    accessLock 
    lastChunk
    lastChunkLineNr

[class variables:]


Related information:



Class protocol:

instance creation
o  on: fileStream


Instance protocol:

accessing
o  size
(comment from inherited method)
the virtual size

initialization
o  fileStream: aStream
lines per chunk

o  fileStream: aStream chunkSize: chunkSizeArg
lines per chunk

private
o  getLine: lineNr
I will temporarily reposition the file, read a chunk and then position back.

o  readerProcess
ensure that noone repositions the file between the positioning and the read

o  startReadProcess


Examples:


<<END
    |top textView fileContents|

    top := StandardSystemView new.
    textView := HVScrollableView for:TextView in:top.
    textView origin:0@0 corner:1.0@1.0.
    fileContents := VirtualReadOnlyTextFileContents on:('err' asFilename readStream).

    textView list:fileContents expandTabs:false
             scanForNonStrings:false includesNonStrings:false.
    textView checkedLinesForWidthOfContentsComputation:0.
    textView setWidthOfContents:1000.
    top open.
Test: create a file with 1 mio lines:
    |file fileContents|

    "create a big file"
    file := 'bigFile' asFilename writeStream.
    1 to:1000000 do:[:lNr |
        lNr printOn:file. file cr.
    ].
    file close.

    fileContents := VirtualReadOnlyTextFileContents on:('bigFile' asFilename readStream).
    self assert:(fileContents at:10) = '10'.
    self assert:(fileContents at:511) = '511'.
    self assert:(fileContents at:512) = '512'.
    self assert:(fileContents at:513) = '513'.
    self assert:(fileContents at:10000) = '10000'.
    self assert:(fileContents at:1) = '1'.
    self assert:(fileContents at:2) = '2'.
    self assert:(fileContents at:50000) = '50000'.
    self assert:(fileContents at:999999) = '999999'.
    self assert:(fileContents size = 1000000 ).
    self assert:(fileContents at:1000000) = '1000000'.
Test: create a file with 1 mio lines and open a textView on it (notice that the view will come up immediately, blocking if you scroll to a line which has not yet been scanned, or which is not in the chunk buffer)
    |file fileContents top textView |

    "create a big file"
    file := 'bigFile' asFilename writeStream.
    1 to:1000000 do:[:lNr |
        lNr printOn:file. file cr.
    ].
    file close.

    fileContents := VirtualReadOnlyTextFileContents on:('bigFile' asFilename readStream).

    top := StandardSystemView new label:'a big file'.
    textView := HVScrollableView for:TextView in:top.
    textView origin:0@0 corner:1.0@1.0.

    textView list:fileContents expandTabs:false
             scanForNonStrings:false includesNonStrings:false.
    textView checkedLinesForWidthOfContentsComputation:0.
    textView setWidthOfContents:1000.
    top open.
END"

ST/X 7.7.0.0; WebServer 1.702 at 20f6060372b9.unknown:8081; Sun, 08 Sep 2024 01:31:15 GMT