Class FileAction

java.lang.Object
svm.env.FileAction

public class FileAction extends Object

File Action.

Link to GitHub: Source File.

Author:
Simula Standard, S-Port: The Environment Interface, Øystein Myhre Andersen
  • Field Details

    • _CREATE

      public FileAction._CreateAction _CREATE
      CREATE: Action is performed as 'open'
    • _PURGE

      public boolean _PURGE

      PURGE: Action is performed at 'close'

      The value "purge" implies that the external file may be deleted by the environment when it is closed (in the sense that it becomes inaccessible to further program access). The value "nopurge" implies no such deletion.

    • _CANREAD

      public boolean _CANREAD

      If the value is true, input operations can be performed.

      This mode is relevant only for direct files.

    • _CANWRITE

      public boolean _CANWRITE

      If the value is true, output operations can be performed.

      This mode is relevant only for direct files.

    • _APPEND

      public boolean _APPEND

      The output to the file is added to the existing contents of the file.

      If the value is true, output to the file is added to the existing contents of the file. The value false implies for a sequential file that, after "close", the external file will contain only the output produced while the file was open.

      The mode is not relevant for in(byte)files.

    • _CHARSET

      protected Charset _CHARSET
      The current character set when encode/decode files.
    • _DEFAULT_BYTESIZE

      protected final int _DEFAULT_BYTESIZE
      The default BYTESIZE is 8 in this implementation.
      See Also:
    • _SYNCHRONOUS

      public boolean _SYNCHRONOUS

      The access mode SYNCHRONOUS.

      It is available for Out- files and Direct- files. For Outfile/OutBytefile, each write operation will be followed by a flush to ensure that the underlying storage device is updated. For Directfile/DirectBytefile the underlaying Java RandomAccessFile will be created open for reading and writing, and also require that every update to the file's content or metadata be written synchronously to the underlying storage device.

  • Constructor Details

    • FileAction

      public FileAction(String action)
      Construct and decode a new FileAction based upon the given 'action' string.
      Parameters:
      action - the action string
  • Method Details

    • decodeActions

      private void decodeActions(String action)

      Decode the given 'action' string.

      action encoding: (a digit gives the rank of the character, e.g. 0 is NUL)
           action == <0 ! 1 >          -- shared/noshared
                     <0 ! 1 >          -- append/noappend
                     <0 ! 1 ! 2 >      -- create/nocreate/anycreate
                     <0 ! 1 ! 2 >      -- readonly/writeonly/readwrite
                     <0 ! 1 >          -- purge/nopurge
                     <0 ! 1 ! 2 ! 3 ! 4 ! 5 >
                     -- rewind/norewind/next/previous/repeat/release
                     <>          -- bytesize: rank(char) (!0! default)
                     <>        -- move:
                     (  )*  -- unknown access modes
                     0                 -- terminating NUL character
      

      The action string will always be at least 10 chars long, encoded with the predefined modes in the above given sequence (e.g. char number 3 will always specify the CREATE mode). If no value is given for some mode, RTS will insert the appropriate default character at the relevant position. These defaults are:

           in(byte)file:     "!0!!1!!1!!0!!1!!2!!0!!0!!0!!0!!0!"
           out(byte)file:    "!1!!1!!2!!1!!1!!2!!0!!0!!0!!0!!0!"
           direct(byte)file: "!1!!1!!1!!2!!1!!5!!0!!0!!0!!0!!0!"
      

      If an unknown (i.e. non-Sport-defined) value are given as parameter to procedure "setaccess", the first character must be '%' (percent), otherwise "setaccess" returns FALSE (in all other cases it is TRUE). Accepted values will be concatenated with the standard string, with '%' replaced by a character (l) whose rank gives the length of the string, excluding the overwritten '%'. The action string is always terminated by the NUL character ('!0!').

                            Files of kind
       Mode:        In-        Out-        Direct-   Takes effect at
       SHARED       shared     noshared    noshared     open
       APPEND       NA         noappend    noappend     open
       CREATE       NA         anycreate   nocreate     open
       READWRITE    NA         NA          readwrite    open
       BYTESIZE:x   *          *           *            open
       REWIND       norewind   norewind    NA           open,close
       PURGE        nopurge    nopurge     nopurge      close
      
      Parameters:
      action - the action string
    • getActionChar

      private int getActionChar(String action, int idx)
      Utility: to pick up a character from the 'action' string
      Parameters:
      action - the action string
      idx - the index
      Returns:
      the requested character
    • doCreateAction

      public File doCreateAction(String fileName)
      Do the Create action.
      Parameters:
      fileName - the fileName
      Returns:
      the File
    • trySelectFile

      protected File trySelectFile(String fileName)

      Try to select a file named 'fileName'.

      If no file exists with that fileName it will try several possibilities:

      • First it will search the Option.internal.RUNTIME_USER_DIR
      • Second, system properties "user.dir" and "java.class.path".parent.
      • Finally, a JFileChooser dialog is opened to let the user select the file.
      Parameters:
      fileName - the given file name
      Returns:
      the resulting file or null
    • doPurgeAction

      public void doPurgeAction(String fileName)
      Do the Purge action
      Parameters:
      fileName - the fileName