HS.Util.StreamUtils
abstract class HS.Util.StreamUtils
Method Inventory
- Base64Decode()
- Base64Encode()
- CheckIdentical()
- CopyFrom()
- CopyToFile()
- EnsureStream()
- EnsureString()
- GetTempDirectory()
- GetTempFilename()
- PurgeTempDirectory()
- ReadFromFile()
Parameters
parameter StringCharsToRead = 8192;
Size of substring when incrementally reading a string in chunks
Methods
classmethod Base64Decode(pInput="", ByRef pOutput As %Stream.GlobalBinary = "") as %Status
Base64 decode a string or a stream into a stream
By default a %Stream.GlobalBinary is returned. Caller may override by
sending in a different stream. For example:
Do ##class(HS.Util.StreamUtils).Base64Decode("SGVsbG8=",.tDecodedStream)
Set tInputFile=##class(%Stream.FileBinary).%New() Set tInputFile.Filename="c:\data.b64" Set tOutputFile=##class(%Stream.FileBinary).%New() Set tOutputFile.Filename="c:\data.dat" Do ##class(HS.Util.StreamUtils).Base64Decode(tInputFile,tOutputFile)
classmethod Base64Encode(pInput="", ByRef pOutput As %Stream.GlobalCharacter = "") as %Status
Base64 encode a string or a stream into a stream
By default a %Stream.GlobalCharacter is returned. Caller may override by
sending in any stream type that has a LineTerminator property. For example:
Do ##class(HS.Util.StreamUtils).Base64Encode("Hello",.tEncodedStream)
Set tInputFile=##class(%Stream.FileBinary).%New() Set tInputFile.Filename="c:\data.dat" Set tOutputFile=##class(%Stream.FileBinary).%New() Set tOutputFile.Filename="c:\data.b64" Do ##class(HS.Util.StreamUtils).Base64Encode(tInputFile,tOutputFile)
classmethod CheckIdentical(pStream1, pStream2) as %Boolean
Check if two streams have identical data
Returns 1 if the streams have the same content. Returns 0 otherwise.
classmethod CopyFrom(pDest As %Stream.Object, pSource) as %Status
Copy either a string or stream into a stream
classmethod CopyToFile(pFilePath As %String, pStream As %Stream.Object, pEncoding) as %Status
Write stream to a file
- pFilePath
- [required] location to save the stream
- pStream
- [required] stream to write
- pEncoding
- [optional] if given uses a character stream with this translate table
Set tSC = ##class(HS.Util.StreamUtils).CopyToFile("/path/to/doc.pdf", tPDFStream) Set tSC = ##class(HS.Util.StreamUtils).CopyToFile("/path/to/ccd.xml", tCCDStream, "UTF8")
classmethod EnsureStream(pStringOrStream) as %Stream
Convert the input (if necessary) to a %Stream
Inputs:
pStringOrStream : (required) A %String or a %Stream is accepted. If not a %Stream, it is converted into
a %Stream
Throws: Any exception from StringIO will be thrown from this method
Throws: Any exception from StringIO will be thrown from this method
classmethod EnsureString(pStringOrStream) as %String
Convert the input (if necessary) to a %String.
Inputs:
pStringOrStream : (required) A %String or a %Stream is accepted. If a Stream, it is converted into
a string.
Throws: Any exception from StringIO will be thrown from this method
Throws: Any exception from StringIO will be thrown from this method
classmethod GetTempDirectory(pSubDir="HSTMP") as %String
Get a temp directory, ensuring it exists
- pSubDir
- [optional] subdirectory under the system temp dir, defaults to 'HSTMP'
Returns:
- the requested subdirectory if it exists or was created successfully
- otherwise the system configured temp directory
classmethod GetTempFilename(pSubDir) as %String
Get a temp file path
- pSubDir
- [optional] subdirectory under the system temp dir, defaults to 'HSTMP'
Returns: the full temp file path
classmethod PurgeTempDirectory(pSubDir) as %Boolean
Delete all files in the temp directory
- pSubDir
- [optional] subdirectory under the system temp dir, defaults to 'HSTMP'
Returns true if all files deleted
classmethod ReadFromFile(pFilePath As %String, ByRef pStream As %Stream.Object, pEncoding) as %Status
Read stream from file, optionally copying it into a provided stream
- pFilePath
- [required] location to read the stream from
- pStream
- [output] if given the stream to copy into, otherwise the file stream
- pEncoding
- [optional] if given reads using a character stream with this translate table
Set tSC = ##class(HS.Util.StreamUtils).ReadFromFile("/path/to/doc.pdf", .tPDFStream) // a %Stream.FileBinary Set tSC = ##class(HS.Util.StreamUtils).ReadFromFile("/path/to/ccd.xml", .tCCDStream, "UTF8") // a %Stream.FileCharacter with TranslateTable="UTF8" Set tSDAStream = ##class(HS.SDA3.QuickStream).%New() Set tSC = ##class(HS.Util.StreamUtils).ReadFromFile("/path/to/sda.xml", .tSDAStream, "UTF8") // reads file as UTF8 and copies into provided QuickStream