Class Reference
IRIS for UNIX 2019.2
InterSystems: The power behind what matters   
Documentation  Search
  [%SYS] >  [%Library] >  [FileStreamAdaptor]
Private  Storage   

abstract stream class %Library.FileStreamAdaptor extends %AbstractStream

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

Inventory

Parameters Properties Methods Queries Indices ForeignKeys Triggers
11 12 39


Summary

Properties
%Location AtEnd Attributes CanonicalFilename
Directory Filename Id LastModified
LineTerminator ReadSize RemoveOnClose Size

Methods
%AddToSaveSet %CheckUnique %ClassIsLatestVersion %ClassName
%ConstructClone %Delete %DeleteExtent %DeleteId
%DispatchClassMethod %DispatchGetModified %DispatchGetProperty %DispatchMethod
%DispatchSetModified %DispatchSetMultidimProperty %DispatchSetProperty %Exists
%ExistsId %Extends %GetParameter %GetSwizzleObject
%Id %IsA %IsModified %IsNull
%KillExtent %LOBPrefetch %LocationGet %LocationSet
%LockStream %New %NormalizeObject %ObjectIsNull
%ObjectModified %ObjectSize %Oid %Open
%OpenId %OriginalNamespace %PackageName %ReleaseLock
%Reload %RemoveFromSaveSet %RollBack %Save
%SerializeObject %SetModified %UnlockStream %ValidateObject
CanonicalFilenameGet Clear CopyFrom CopyFromAndSave
DeleteAttribute DeleteStream FileBinarySize FilenameGet
FilenameSet FindAt Flush GetAttribute
GetAttributeList GetStreamId GetStreamIdForFile InputFromDevice
IsCharacter IsDefinedAttribute IsNull LastModifiedGet
LineTerminatorSet LinkToFile MoveTo MoveToEnd
NewFileName NextAttribute OpenStream OutputToDevice
OutputToDeviceAt Read ReadLine ReadLineIntoStream
ReadSQL Rewind SaveStream SerializeToSyncSet
SetAttribute SetAttributeList SizeGet StreamOIDIsNull
SyncStreamIn Write WriteLine

Subclasses
%Library.FileBinaryStream %Library.FileCharacterStream

Parameters

• parameter FILEEXT = "stream";
• parameter OPENAPPEND = "AWUK\RAW\";
• parameter OPENREAD = "RUK\RAW\";
• parameter OPENREADTERM = "RSK\RAW\";
• parameter OPENWRITE = "WUNK\RAW\";
• final parameter READLINE = 1;
• final parameter READNORMAL = 0;
• parameter STORAGE = "OTHER";
• final parameter WRITEAPPEND = 1;
• final parameter WRITEJUSTSAVED = 4;
• final parameter WRITENORMAL = 0;

Properties

• 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.
• property Directory as %String(MAXLEN=5000);
Directory where stream files are located.
• property Filename as %String(MAXLEN=5000) [ Calculated ];
The filename that this stream is currently using
• 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.
• property ReadSize as %Integer;
While reading this holds the file size
• 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

Methods

• classmethod %Exists(soid As %ObjectIdentity) as %Boolean
Checks to see if the object identified by the OID oid exists in the extent.

Returns %Boolean TRUE is it exists, FALSE if it does not.

• method %LocationGet() as %String
This is a Get accessor method for the %Location property.
• method %LocationSet(value As %String) as %Status
This is a Set accessor method for the %Location property.
• method %NormalizeObject() as %Status
Normalizes all of an object's property values by invoking the data type Normalize methods. Many data types may allow many different representations of the same value. Normalization converts a value to its cannonical, or normalized, form.
• classmethod %ObjectIsNull(soid As %ObjectIdentity) as %Boolean
Return true if this stream oid is a null stream and false if the stream is not null
• method %ValidateObject(force As %Integer = 0) as %Status
This method validates an object. The %Save method of a persistent class calls it before filing any objects in the database. The %ValidateObject method of a referencing object can call it. You can also call it explicitly at any time.

%ValidateObject does the following:

  1. It tests if any required property values are missing.
  2. If the PROPERTYVALIDATION class parameter is set to ValidateOnSave, it validates each non-null property value by calling the property method IsValid on each literal property and the object's %ValidateObject method for object-valued properties.
  3. If present, it will call a user-supplied %OnValidateObject method.

If any of these tests fail, %ValidateObject immediately returns an error value. It is up to the caller of %ValidateObject to process the error value.

Returns a %Status value indicating success or failure.

• method CanonicalFilenameGet() as %String
This is a Get accessor method for the CanonicalFilename property.
• method Clear(permanent As %Boolean = 1) as %Status
Clear the contents of this Stream from permanent storage. This will remove the permanent stream storage and any temporary stream and initialise the stream to its initial state that it starts in, including removing all the stream attributes.

Returns a %Status value indicating success or failure.

• method CopyFrom(source As %AbstractStream) as %Status
Copies the contents of source into this Stream.

For example, you can copy oldstream into a new stream:

	Set newstream=##class(%GlobalCharacterStream).%New()
	Do newstream.CopyFrom(oldstream)

Returns a %Status value indicating success or failure.

• method FileBinarySize() as %Integer
Return the current size of the file in bytes.
• method FilenameGet() as %String
This is a Get accessor method for the Filename property.
• method FilenameSet(file As %String) as Status
This is a Set accessor method for the Filename property.
• method Flush() as %Status
Flush any output in the stream not already saved.
• classmethod GetStreamIdForFile(file As %String, contenttype As %String = "", charset As %String = "") as %String
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()
• method LastModifiedGet() as %TimeStamp
This is a Get accessor method for the LastModified property.
• method LineTerminatorSet(terminator As %String) as %Status
This is a Set accessor method for the LineTerminator property.
• 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.

• method MoveToEnd() as %Status
Move to the end of the stream so the next Write will be appended to the end. This allows you to read from a stream, then MoveToEnd() and append new data, where just calling Write after a read will clear the stream before writing new data.

Returns a %Status value indicating success or failure.

• classmethod NewFileName(ext As %String = "", directory As %String = "") as %String
• method OpenStream(sid As %String) as %Status
Open a stream given a stream id
• method OutputToDevice(ByRef len As %Integer = -1) as %Status
Write out len characters of the stream to the current device starting from the current position. This method is optimised for performance by the various sub classes. If len is omitted or set to -1 then it will write out the entire stream starting at the beginning.
• method Read(ByRef len As %Integer = 32000, ByRef sc As %Status) as %RawString
Reads up to len characters from the current position in the stream. The current position is advanced by the number of characters read. Upon exit, len is set to the actual number of characters read. If a read occurs when the stream position is at the end of the stream, len will be set to -1 and Read will return a null string (""). If no len is passed in, ie. 'Read()' then it is up to the Read implementation as to how much data to return. Some stream classes use this to optimize the amount of data returned to align this with the underlying storage of the stream.

You must call Rewind if you want to read a stream from the beginning again. Calling Read after Write implicitly ends the Write operation and rewinds to the start of the stream.

Returns a string up to len characters long. The byref argument sc will return a %Status if any error occurred during the read.

• 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.
• method ReadLineIntoStream(ByRef sc As %Status) as %AbstractStream
This reads from the stream until it find the LineTerminator and returns this as a stream. If the stream does not contain the line terminator this can potentially be the entire stream.
• method Rewind() as %Status
Go back to the start of the stream.
• method SaveStream() as %Status
Deprecated method, use %Save instead. Saves the temporary copy of the stream data to a persistent location. Note that any locking or transaction handling must be done by the caller.

Returns a %Status value indicating success or failure.

• method SizeGet() as %Integer
Return the current size of the data stream.
• method Write(data As %RawString = "") as %Status
Appends the string data to the stream and advances the current stream position by the number of characters in data.

Note that a write operation immediately following a read or rewind will clear out the existing data in the stream.

Returns a %Status value indicating success or failure.



Copyright (c) 2019 by InterSystems Corporation. Cambridge, Massachusetts, U.S.A. All rights reserved. Confidential property of InterSystems Corporation.