Home > Class Reference > HSLIB namespace > HS.Util.StreamUtils

HS.Util.StreamUtils

abstract class HS.Util.StreamUtils

Method Inventory (Including Private)

Methods (Including Private)

classmethod Base64Decode(pInput="", ByRef pOutput As %Stream.GlobalBinary = "") as %Status [ Language = objectscript ]
Base64 decode a string or a stream into a stream
  Do ##class(HS.Util.StreamUtils).Base64Decode("SGVsbG8=",.tDecodedStream)
  
By default a %Stream.GlobalBinary is returned. Caller may override by sending in a different stream. For example:
  Set tInputFile=##class(%Stream.FileBinary).%New()
  Set tInputFile.Filename="c:\data.b64"
  Set tOutputFile=##class(%String.FileBinary).%New()
  Set tOutputFile.Filename="c:\data.dat"
  Do ##class(HS.Util.StreamUtils).Base64Encode(tInputFile,tOutputFile)
  
classmethod Base64Encode(pInput="", ByRef pOutput As %Stream.GlobalCharacter = "") as %Status [ Language = objectscript ]
Base64 encode a string or a stream into a stream
  Do ##class(HS.Util.StreamUtils).Base64Encode("Hello",.tEncodedStream)
  
By default a %Stream.GlobalCharacter is returned. Caller may override by sending in any stream type that has a LineTerminator property. For example:
  Set tInputFile=##class(%Stream.FileBinary).%New()
  Set tInputFile.Filename="c:\data.dat"
  Set tOutputFile=##class(%String.FileBinary).%New()
  Set tOutputFile.Filename="c:\data.b64"
  Do ##class(HS.Util.StreamUtils).Base64Encode(tInputFile,tOutputFile)
  
classmethod CopyFrom(pDest As %Stream.Object, pSource) as %Status [ Language = objectscript ]
Copy either a string or stream into a stream
classmethod CopyToFile(pFilePath As %String, pStream As %Stream.Object, pEncoding) as %Status [ Language = objectscript ]
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 [ Language = objectscript ]
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
  • classmethod EnsureString(pStringOrStream) as %String [ Language = objectscript ]
    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
  • classmethod GetTempDirectory(pSubDir="HSTMP") as %String [ Language = objectscript ]
    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 [ Language = objectscript ]
    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 [ Language = objectscript ]
    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 [ Language = objectscript ]
    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 
      
    FeedbackOpens in a new window