- All Implemented Interfaces:
Runnable
bytefile class Directbytefile; begin integer LOC, MAXLOC; Boolean LOCKED; Boolean procedure endfile; endfile:=OPEN and then LOC>lastloc; integer procedure location; location := LOC; integer procedure maxloc; maxloc := MAXLOC; Boolean procedure locked; locked := LOCKED; Boolean procedure open; Boolean procedure close; integer procedure lastloc; procedure locate(i); integer i; short integer procedure inbyte; procedure outbyte(x); short integer x; Boolean procedure checkpoint; integer procedure lock(t,i,j); real t; integer i,j; Boolean procedure unlock; procedure intext(t); text t; procedure outtext(t); text t; ... end Directbytefile;An object of the class "Directbytefile" is used to represent an external file in which the individual bytes are addressable by ordinal numbers.
The variable LOC is defined to represent such ordinal numbers. When the file is closed, the value of LOC is zero.
In this implementation LOC is maintained by the underlying file system.
Link to GitHub: Source File.
- Author:
- SIMULA Standards Group, Øystein Myhre Andersen
-
Nested Class Summary
Nested classes/interfaces inherited from class simula.runtime.RTS_File
RTS_File._CreateAction
Nested classes/interfaces inherited from class simula.runtime.RTS_RTObject
RTS_RTObject.ForElt, RTS_RTObject.ForList, RTS_RTObject.ForListIterator, RTS_RTObject.OperationalState, RTS_RTObject.RTS_BOOLEAN_ARRAY, RTS_RTObject.RTS_BOUNDS, RTS_RTObject.RTS_CHARACTER_ARRAY, RTS_RTObject.RTS_INTEGER_ARRAY, RTS_RTObject.RTS_LABEL, RTS_RTObject.RTS_LONG_REAL_ARRAY, RTS_RTObject.RTS_NAME<T>, RTS_RTObject.RTS_REAL_ARRAY, RTS_RTObject.RTS_REALTYPE_ARRAY, RTS_RTObject.RTS_REF_ARRAY<T>, RTS_RTObject.RTS_TEXT_ARRAY, RTS_RTObject.SingleElt<T>, RTS_RTObject.SingleTValElt, RTS_RTObject.StepUntil, RTS_RTObject.UncaughtExceptionHandler, RTS_RTObject.WhileElt<T>, RTS_RTObject.WhileTValElt
-
Field Summary
Modifier and TypeFieldDescription(package private) boolean
The variable "LOCKED" indicates whether the file is currently locked by the executing program.(package private) int
The variable MAXLOC indicates the maximum possible location on the external file.private FileLock
The FileLockprivate int
The initial value of LAST_LOCprivate RandomAccessFile
The RandomAccessFile used.Fields inherited from class simula.runtime.RTS_Bytefile
_BYTESIZE, _MAXBYTE
Fields inherited from class simula.runtime.RTS_File
_APPEND, _ASK_PAPER, _BOT_MARGIN, _CANREAD, _CANWRITE, _CHARSET, _CREATE, _DEFAULT_BYTESIZE, _FONT, _LEFT_MARGIN, _OPEN, _ORIENTATION, _PURGE, _RIGHT_MARGIN, _SYNCHRONOUS, _TOP_MARGIN, FILE_NAME
Fields inherited from class simula.runtime.RTS_ENVIRONMENT
_STARTTIME, CURRENTDECIMALMARK, CURRENTLOWTEN, EXCEPTION_HANDLER, maxint, maxlongreal, maxreal, minint, minlongreal, minreal, simulaReleaseID
Fields inherited from class simula.runtime.RTS_RTObject
_CORUT, _CTX, _CUR, _DL, _INPUT_LINELENGTH, _JTX, _OUTPUT_LINELENGTH, _SL, _STATE, _SYSIN, _SYSOUT, NOTEXT
-
Constructor Summary
ConstructorDescriptionRTS_Directbytefile
(RTS_RTObject SL, RTS_TXT FN) Create a new _Directbytefile. -
Method Summary
Modifier and TypeMethodDescription_STM()
Method representing the Statements in this Block
This method is virtual and must be redefined in blocks.boolean
The procedure checkpoint.boolean
close()
The procedure close.boolean
endfile()
The procedure endfile.int
inbyte()
The procedure inbyte.The procedure intext.int
lastloc()
The procedure lastloc.void
locate
(int p) The procedure locate.int
location()
The procedure location.int
lock
(float timelimit, int loc1, int loc2) The procedure lock.boolean
locked()
Returns the value _LOCKED.int
maxloc()
The procedure maxloc.boolean
open()
The procedure open.void
outbyte
(int b) The procedure outbyte.void
The procedure outtext.boolean
unlock()
The procedure unlock.Methods inherited from class simula.runtime.RTS_Bytefile
bytesize
Methods inherited from class simula.runtime.RTS_File
doCreateAction, doPurgeAction, filename, isopen, setaccess, setCharset, setFont, setMargins, TRACE_OPEN, trySelectFile
Methods inherited from class simula.runtime.RTS_BASICIO
toString
Methods inherited from class simula.runtime.RTS_ENVIRONMENT
_char, _IPOW, _IS, abs, abs, abs, addepsilon, addepsilon, arccos, arcsin, arctan, arctan2, Char, clocktime, cos, cosh, cotan, cputime, datetime, decimalmark, DEFEXCEPTION, digit, discrete, draw, edfix, edit, edit, edit, edit, edit, edtime, entier, Erlang, error, exp, getIntInfo, getTextInfo, giveIntInfo, giveTextInfo, hash, histd, histo, isochar, isorank, letter, linear, ln, loadChar, log10, lowcase, lowerbound, lowten, max, max, max, max, max, min, min, min, min, min, mod, negexp, normal, Poisson, printStaticChain, printThreadList, randint, rank, rem, rts_utility, sign, simulaid, sin, sinh, sqrt, storeChar, subepsilon, subepsilon, tan, tanh, uniform, upcase, upperbound, waitSomeTime
Methods inherited from class simula.runtime.RTS_RTObject
_ASGSTR, _ASGTXT, _GOTO, _JUMPTABLE, _JUMPTABLE, _LABEL, _PRE_LABEL, _PRE_TABLE, _SIM_LABEL, _TXTREL_EQ, _TXTREL_GE, _TXTREL_GT, _TXTREL_LE, _TXTREL_LT, _TXTREL_NE, _VALUE, arrayValue, BBLK, blanks, BPRG, call, call, CONC, copy, detach, detach, detach, doubleValue, EBLK, edObjectAttributes, edObjectIdent, floatValue, getErrorMessage, intValue, isDetachUsed, isQPSystemBlock, objectTraceIdentifier, objectTraceIdentifier, objectValue, procValue, resume, resume, resume, swapCoroutines, sysin, sysout, terminate_program, TRACE_GOTO, TRF_EQ, TRF_NE
-
Field Details
-
_MAXLOC
int _MAXLOCThe variable MAXLOC indicates the maximum possible location on the external file. If this is not meaningful MAXLOC has the value of "maxint"-1. The procedure "maxloc" gives access to the current MAXLOC value. -
_LOCKED
boolean _LOCKEDThe variable "LOCKED" indicates whether the file is currently locked by the executing program. The procedure "locked" returns the current value. -
randomAccessFile
The RandomAccessFile used. -
fileLock
The FileLock -
INITIAL_LAST_LOC
private int INITIAL_LAST_LOCThe initial value of LAST_LOC
-
-
Constructor Details
-
RTS_Directbytefile
Create a new _Directbytefile.- Parameters:
SL
- staticLinkFN
- file name
-
-
Method Details
-
_STM
Description copied from class:RTS_RTObject
Method representing the Statements in this Block
This method is virtual and must be redefined in blocks.- Overrides:
_STM
in classRTS_Bytefile
- Returns:
- a pointer to this _RTObject
-
endfile
public boolean endfile()The procedure endfile.It returns true whenever LOC indicates an address greater than "lastloc".
Boolean procedure endfile; endfile:=OPEN and then LOC>lastloc;
- Returns:
- the resulting boolean.
-
location
public int location()The procedure location.It returns the current value of LOC.
In this implementation file.getFilePointer() is used for this purpose.
- Returns:
- the current read/write position.
-
maxloc
public int maxloc()The procedure maxloc.integer procedure maxloc; if not OPEN then error("..." ! file closed; ) else maxloc := MAXLOC;
The value assigned to MAXLOC at "open" is either a maximum length determined from the external file, or it is "maxint"-1 if no such length exists.- Returns:
- the value _MAXLOC.
-
locked
public boolean locked()Returns the value _LOCKED.- Returns:
- the value _LOCKED.
-
open
public boolean open()The procedure open.Boolean procedure open; if ... then begin ... LOC := 1; MAXLOC := ...; ! fixed size, or maxint-1; BYTESIZE := ... ! value of access mode BYTESIZE; open := OPEN := true; end open;
- Returns:
- true:ok, false:error
-
close
public boolean close()The procedure close.Boolean procedure close; if OPEN then begin ... MAXLOC := 0; OPEN := false; close := true; end close;
- Returns:
- true:ok, false:error
-
locate
public void locate(int p) The procedure locate.It is used to assign a given value to the variable LOC. A parameter value to "locate" which is less than one or greater than MAXLOC constitutes a run-time error.
procedure locate(p); integer p; if p<1 or p>MAXLOC then error("..." ! Parameter out of range; ) else begin LOC:= p; ... ; end locate; *
In this implementation we use the method seek(p) which sets the file-pointer offset, measured from the beginning of this file, at which the next read or write occurs. The offset may be set beyond the end of the file. Setting the offset beyond the end of the file does not change the file length. The file length will change only by writing after the offset has been set beyond the end of the file.Parameters: pos - the offset position, measured in bytes from the beginning of the file, at which to set the file pointer.
Throws: IOException - if pos is less than 0 or if an I/O error occurs.
- Parameters:
p
- desired location.
-
lastloc
public int lastloc()The procedure lastloc.integer procedure lastloc; if not OPEN then error("..." ! file closed; ) else lastloc := ...;
The procedure "lastloc" indicates the largest location of any written image. For a new file the value returned is zero.- Returns:
- The current last written location.
-
inbyte
public int inbyte()The procedure inbyte.It reads one byte, returning its integer value. The result of "inbyte" from an unwritten LOC is zero.
In this implementation the file.read() read a byte starting at the file pointer and advance the file pointer past the bytes read. I.e. LOC is maintained by the underlying file system.
short integer procedure inbyte; if not OPEN then error("..." !file closed; ) else if LOC <= lastloc then begin inbyte := ... ! next byte of size BYTESIZE;...; LOC := LOC+1 end inbyte;
- Returns:
- the byte value read.
-
outbyte
public void outbyte(int b) The procedure outbyte.It outputs a byte according to the given parameter value.
In this implementation the file.write() writes a byte starting at the file pointer and advance the file pointer past the byte written. I.e. LOC is maintained by the underlying file system.
procedure outbyte(x); short integer x; if not OPEN then error("..." !file closed; ) else if x < 0 or else x >= 2**BYTESIZE then error("..." ! Outbyte, illegal byte value ;); else if LOC > MAXLOC then error("..." !file overflow; ) else begin ... ! output of x; LOC := LOC + 1 end outbyte;
- Parameters:
b
- the byte value to be written.
-
checkpoint
public boolean checkpoint()The procedure checkpoint.All files producing output (sequential output or direct files) contain a Boolean procedure "checkpoint". The procedure causes the environment to attempt to secure the output produced so far. Depending on the nature of the associated external device, this causes completion of output transfer (i.e. intermediate buffer contents are transferred).
If this is not possible or meaningful, "checkpoint" is a dummy operation in which case the value false is returned.
- Returns:
- true:ok, false:error
-
lock
public int lock(float timelimit, int loc1, int loc2) The procedure lock.Direct File Locking
Procedure "lock" enables the program to get exclusive access to all or part of the file. The effect of a "lock" call while the file is locked ("LOCKED" is true) is that the previous lock is immediately released (prior to the new locking attempt).
The parameter "timelimit" is the (clock) time in seconds that is the maximum waiting time for the resource. If "timelimit" is less than or equal to zero, the procedure returns immediately without performing any actions upon the file.
The parameters "loc1" and "loc2" identify the part of the file to be locked, by giving the ordinal numbers of two external images (bytes). The program is given exclusive access to a part of the file which includes the requested region. If the two parameters are both zero, this implies locking the whole file. Otherwise, the size of the part of the file that is actually locked, is implementation-dependent; it may even include the entire file.
A return value of zero indicates a successful "lock" operation. The value -1 indicates that "timelimit" was exceeded (or was zero or negative). A negative value less than -1 indicates "lock" failure and its interpretation is implementation-defined.
integer procedure lock(timelimit,loc1,loc2); real timelimit; integer loc1,loc2; begin lock := -1; if timelimit>0.0 then begin if LOCKED then unlock; ... ! try to lock indicated part of file, see below; if !success; then begin LOCKED := true; lock := 0 end end end lock;
The procedures "lock" and "unlock" (see 10.2.2) provide locking mechanisms. The last two parameters of "lock" indicate the minimum range of (byte) locations to be locked (inclusive).It is implemented using:
public abstract FileLock lock(long position,long size,boolean shared) throws IOException
With Parameters:- position - The position at which the locked region is to start; must be non-negative
- size - The size of the locked region; must be non-negative, and the sum position + size must be non-negative
- shared - true to request a shared lock, in which case this channel must be open for reading (and possibly writing); false to request an exclusive lock, in which case this channel must be open for writing (and possibly reading)
- Parameters:
timelimit
- argument timelimitloc1
- argument loc1loc2
- argument loc2- Returns:
- code, 0:OK otherwise error
-
unlock
public boolean unlock()The procedure unlock.Boolean procedure unlock; begin unlock := checkpoint; if LOCKED then begin !release file; LOCKED := false end end unlock;
- Returns:
- the resulting boolean value
-
intext
The procedure intext.It fills the frame of the parameter "t" with successive input bytes.
text procedure intext(t); text t; begin t.setpos(1); while t.more and not ENDFILE do t.putchar(char(inbyte)); if ENDFILE then t.setpos(t.pos-1); intext:- t.sub(1,t.pos-1) end intext;
- Parameters:
t
- the argument text- Returns:
- the resulting text
-
outtext
The procedure outtext. It outputs all characters in the parameter "t" as bytes.procedure outtext(t); text t; begin t.setpos(1); while t.more do outbyte(rank(t.getchar)) end outtext;
- Parameters:
t
- the argument text
-