Skip to main content

%Library.FileStreamAdaptor

Class %Library.FileStreamAdaptor Extends %AbstractStream [ Abstract, Deprecated, System = 2 ]

Deprecated internal class. Stream adaptor for streams that store data in external files. Not to be used directly.

Parameters

WRITEJUSTSAVED

Parameter WRITEJUSTSAVED [ Final ] = 4;

STORAGE

Parameter STORAGE = "OTHER";

FILEEXT

Parameter FILEEXT = "stream";

OPENREAD

Parameter OPENREAD = "RUK\RAW\";

OPENWRITE

Parameter OPENWRITE = "WUNK\RAW\";

OPENAPPEND

Parameter OPENAPPEND = "AWUK\RAW\";

OPENREADTERM

Parameter OPENREADTERM = "RSK\RAW\";

READNORMAL

Parameter READNORMAL [ Final ] = 0;

READLINE

Parameter READLINE [ Final ] = 1;

WRITENORMAL

Parameter WRITENORMAL [ Final ] = 0;

WRITEAPPEND

Parameter WRITEAPPEND [ Final ] = 1;

Properties

Directory

Property Directory As %String(MAXLEN = 5000);

Directory where stream files are located.

Filename

Property Filename As %String(MAXLEN = 5000) [ Calculated ];

The filename that this stream is currently using

If you set this property to update the file we will write to/read from this operation can fail if for example the directory specified does not exist. To detect this failure either check the %Status return code of the FilenameSet or if using 'Set stream.Filename=newname' then check %objlasterror after the call to see if it reported an error.

CanonicalFilename

Property CanonicalFilename As %String(MAXLEN = 5000) [ Calculated ];

Read only property that returns the canonical filename if the file is open and "" if the file is not open.

NormalizedDirectory

Property NormalizedDirectory As %String(MAXLEN = 5000) [ Private ];

Normalized form of the directory. This is used for access to the file (as it adds the extra '/' if needed), but it stores the Directory in the Id as this may be a relative path. This is read only, you should not try and set its value.

StoreFile

Property StoreFile As %String(MAXLEN = 5000) [ Private ];

Name of file (without directory) containing stored stream.

TempFile

Property TempFile As %String(MAXLEN = 5000) [ Private ];

Name of file (without directory) containing temporary stream.

CurrFile

Property CurrFile As %String(MAXLEN = 5000) [ Private, Transient ];

Full path name of currently opened file. Equal to "" if no file is open.

RemoveOnClose

Property RemoveOnClose As %Boolean [ InitialExpression = 0, Transient ];

If true then remove the permanent file as well as any temp file when this object is closed

ReadMode

Property ReadMode As %Integer [ InitialExpression = {..#READNORMAL}, Private ];

Mode the device is opened in, either with terminators as delimitors or not.

MakePermLoc

Property MakePermLoc As %Boolean [ InitialExpression = 0, Private ];

If true then when saving this file we need to move it to the default permanent location

ReadSize

Property ReadSize As %Integer;

While reading this holds the file size

LineTerminator

Property LineTerminator As %String(MAXLEN = 10) [ InitialExpression = {$get(^%SYS("Stream","LineTerminator"),$select($$$isUNIX:$char(10),1:$char(13,10)))}, Transient ];

For file streams the line will terminate on any of the characters set in the LineTerminator, it does not support multi-character line terminators because it uses the ObjectScript file behavior which terminates on any of the characters.
Also for %FileCharacterStream even if you set this when you call WriteLine as the file was opened in 'S' mode it will normalize the line terminator as the data is being written, so for example if you set LineTerminator to $char(13,10) on Unix systems when you call WriteLine it will only write $char(10) to the file.

Methods

DirectorySet

Method DirectorySet(dir As %String) As %Status [ Private ]

%LocationSet

Method %LocationSet(value As %String) As %Status

%LocationGet

Method %LocationGet() As %String [ CodeMode = expression ]

FilenameSet

Method FilenameSet(file As %String) As Status [ CodeMode = call ]

FilenameGet

Method FilenameGet() As %String [ CodeMode = expression ]

CanonicalFilenameGet

Method CanonicalFilenameGet() As %String [ CodeMode = expression ]

LineTerminatorSet

Method LineTerminatorSet(terminator As %String) As %Status

%OnConstructClone

Method %OnConstructClone(object As %RegisteredObject, deep As %Boolean = 0, ByRef cloned As %String) As %Status [ Private, ProcedureBlock = 1 ]

%OnNew

Method %OnNew(initval As %String = "") As %Status [ Private ]

IOInit

Method IOInit() [ Private ]

%OnClose

Method %OnClose() As %Status [ Private ]

Rewind

Method Rewind() As %Status

Flush

Method Flush() As %Status

SizeGet

Method SizeGet() As %Integer [ CodeMode = call ]

Return the current size of the data stream.

FileBinarySize

Method FileBinarySize() As %Integer

Return the current size of the file in bytes.

IOGetStreamId

Method IOGetStreamId() As %String [ CodeMode = expression, Private ]

OpenStream

Method OpenStream(sid As %String) As %Status

Open a stream given a stream id

LinkToFile

Method LinkToFile(filename As %String) As %Status

This method lets you connect a file stream to a file called filename without making a copy of it. If the file does not already exist it will still allow you to link to this file, and %IsNull() will return true until you write to this file. Do object.Image.LinkToFile("\temp\image.jpg") Do object.%Save() The method as its name suggests creates a LINK to an EXISTING file. So this is a 'shared public' file, as it can be shared by several instances of a class, or even several classes. Using the CopyFrom method, on the contrary, creates a 'private' image, not sharable by other instances/classes, so these two methods are really different.

The problems with shared public images are that several instances are all allowed to update and even delete the image, causing problems for other instances.

For example, if dog #2 has image 'test.gif', I can also assign that image to dog #5 or even person #24 If I change the image for dog #5, then the image is changed in place to another image, thus upsetting dog#2 and person#24. If I delete dog#5, the image is also deleted and thus dog#2 and person#24 are changed.

Also note that if there is currently some temporary data in the old stream when the LinkToFile is called this temporary data will be removed before the stream is linked to this filename.

%SaveData

Method %SaveData(ByRef sid As %String) As %Status [ Private, ProcedureBlock = 1 ]

SaveStream

Method SaveStream() As %Status

IODeleteStream

ClassMethod IODeleteStream(sid As %String, concurrency As %Integer = 0) As %Status [ Private ]

NewFileName

ClassMethod NewFileName(ext As %String = "", directory As %String = "") As %String

Read

Method Read(ByRef len As %Integer = 32000, ByRef sc As %Status) As %RawString

SetupRead

Method SetupRead(newMode As %Integer) As %Status [ Private ]

Write

Method Write(data As %RawString = "") As %Status

MoveToEnd

Method MoveToEnd() As %Status

CopyFrom

Method CopyFrom(source As %AbstractStream) As %Status

OutputToDevice

Method OutputToDevice(ByRef len As %Integer = -1) As %Status

Clear

Method Clear(permanent As %Boolean = 1) As %Status

LastModifiedGet

Method LastModifiedGet() As %TimeStamp

GetStreamIdForFile

ClassMethod GetStreamIdForFile(file As %String, contenttype As %String = "", charset As %String = "") As %String [ CodeMode = generator ]

Generate a stream OId that links to this file. This can be used by the CSP server to generate an OID that can be embedded in a web page and later used to display this file. The contenttype is an optional parameter to specify the content type of this stream for display with a stream server. If I have a file called 'C:\Test.txt' then I can create a stream linked to this by: Set id=##class(%FileCharacterStream).GetStreamIdForFile("c:\Test.txt") Set stream=##class(%FileCharacterStream).%Open(id) Do stream.OutputToDevice()

GetReadOpenParameter

Method GetReadOpenParameter(filename As %String, mode As %Integer, ByRef pos As %Integer) As %String [ Private ]

GetWriteOpenParameter

Method GetWriteOpenParameter(filename As %String, mode As %Integer) As %String [ CodeMode = expression, Private ]

ReadLine

Method ReadLine(ByRef len As %Integer = 32000, ByRef sc As %Status, ByRef eol As %Boolean, ByRef term As %String) As %RawString

Read a line from the file. Note that besides the normal ReadLine arguments this can also be passed a term which will return the termintor that completed the line if we read in a whole line.

ReadLineIntoStream

Method ReadLineIntoStream(ByRef sc As %Status) As %AbstractStream

%NormalizeObject

Method %NormalizeObject() As %Status [ CodeMode = expression ]

%ValidateObject

Method %ValidateObject(force As %Integer = 0) As %Status [ CodeMode = expression ]

%Exists

ClassMethod %Exists(soid As %ObjectIdentity) As %Boolean

%ObjectIsNull

ClassMethod %ObjectIsNull(soid As %ObjectIdentity) As %Boolean