InDesign SDK  20.5
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StreamUtil Class Reference

#include <StreamUtil.h>

Static Public Member Functions

static IPMStreamCreateDBStreamRead (IDataBase *db, UID id)
 
static IPMStreamCreateDBStreamWrite (IDataBase *db, UID id)
 
static IPMStreamCreateCloudDBStreamRead (IDataBase *db, UID uid)
 
static IPMStreamCreateCloudDBStreamWrite (IDataBase *db, UID uid)
 
static IPMStreamCreateCopyStream (IDataBase *src, IDataBase *dest, IXferBytes *xfer=nil)
 
static IPMStreamCreateDBStreamCopy (IDataBase *src, IDataBase *dest, UID id, IPMUnknown *pmobject=nil)
 
static IPMStreamCreateFileStreamRead (const IDFile &sysFile, uint32 mode=kOpenIn, OSType fileType=0x3f3f3f3f, OSType creator=0x3f3f3f3f)
 
static IPMStreamCreateFileStreamWrite (const IDFile &sysFile, uint32 mode=kOpenOut, OSType fileType=0x3f3f3f3f, OSType creator=0x3f3f3f3f)
 
static IPMStreamCreateFileStreamReadLazy (const IDFile &sysFile, uint32 mode=kOpenIn, OSType fileType=0x3f3f3f3f, OSType creator=0x3f3f3f3f)
 
static IPMStreamCreateFileStreamWriteLazy (const IDFile &sysFile, uint32 mode=kOpenOut|kOpenTrunc, OSType fileType=0x3f3f3f3f, OSType creator=0x3f3f3f3f)
 
static IPMStreamCreateObjectTextFileStreamWrite (IDataBase *db, const IDFile &sysFile, uint32 mode=kOpenOut, OSType fileType=0x3f3f3f3f, OSType creator=0x3f3f3f3f)
 
static IPMStreamCreateResourceStreamRead (const RsrcSpec &spec, bool16 useLocaleIndexResource=kTrue)
 
static IPMStreamCreateObjectResourceStreamRead (const RsrcSpec &spec, IDataBase *db)
 
static void ResetStreamContentsChanged (IPMStream *)
 
static void SetStreamContentsChanged (IPMStream *)
 
static bool16 StreamContentsChanged (IPMStream *)
 
static IPMStreamCreateCustomDBStreamWrite (IDataBase *source, UID sourceUID, IDataBase *target, UID targetUID)
 
static IPMStreamCreateDCXCompositeStream (ClassID clsID, const AdobeDCX::CompositePtr compositePtr)
 
Bauhaus managed streams
static IPMStreamCreateManagedFileStreamRead (const IDFile &sysFile, uint32 mode=kOpenIn, OSType fileType=0x3f3f3f3f, OSType creator=0x3f3f3f3f)
 
static IPMStreamCreateManagedFileStreamReadLazy (const IDFile &sysFile, uint32 mode=kOpenIn, OSType fileType=0x3f3f3f3f, OSType creator=0x3f3f3f3f)
 
Memory-based streams
static IPMStreamCreatePointerStreamRead (char *buffer, size_t len)
 
static IPMStreamCreatePointerStreamWrite (char *buffer, size_t len)
 
static IPMStreamCreateMemoryStreamRead (IXferBytes *underlyingXferBytes, bool16 takeOwnership=kFalse, bool16 recycleBoss=kTrue)
 
static IPMStreamCreateMemoryStreamWrite (IXferBytes *underlyingXferBytes, bool16 takeOwnership=kFalse, bool16 recycleBoss=kTrue)
 

Detailed Description

StreamUtil is a class of static functions that create and manipulate InDesign streams.

It is provided for convenience and ease of use.



Note that any of the create stream methods will return nil if there is an error 

creating a stream (e.g., file cannot be opened, etc.). So client code should check

for nil on return.



Example Code:


        InterfacePtr<IPMStream> s(StreamUtil::CreateFileStreamRead(myFile));

        if (s)  {

            // read from file

        }

        else {

            // handle error

Also, in all cases, the stream returned is a referenced object, and the caller is

responsible for releasing it. Typically this is handled via InterfacePtr, as in 

the example above.

Member Function Documentation

static IPMStream* StreamUtil::CreateCloudDBStreamRead (IDataBasedb,
UID uid 
)
static

Create a Read stream from the cloud document to read the content from database.

Parameters
dbwhat database the object is in
UIDthe object in the database to access
Returns
IPMStream* the new stream, or nil if the stream cannot be opened. For Internal USE only right now.
static IPMStream* StreamUtil::CreateCloudDBStreamWrite (IDataBasedb,
UID uid 
)
static

Create a Read stream from the cloud document to read the content from database.

Parameters
dbwhat database the object is in
UIDthe object in the database to access
Returns
IPMStream* the new stream, or nil if the stream cannot be opened. For Internal Use ONLY right now.
static IPMStream* StreamUtil::CreateCopyStream (IDataBasesrc,
IDataBasedest,
IXferBytesxfer = nil 
)
static

For internal use only. Open a stream for copying a database record.

Parameters
srcdatabase to copy from
destdatabase to copy to
IXerBytes*the handler to use for the copy
Returns
IPMStream* the new stream, or nil if the stream cannot be opened.
static IPMStream* StreamUtil::CreateDBStreamCopy (IDataBasesrc,
IDataBasedest,
UID id,
IPMUnknownpmobject = nil 
)
static

For internal use only. Copy a uid from the src database into a new object in the destination database.

Parameters
srcdatabase to copy from
destdatabase to copy to
destobject to copy to
pmobjectused in translating UIDs during the copy (for internal use only)
Returns
IPMStream* the new stream, or nil if the stream cannot be opened.
static IPMStream* StreamUtil::CreateDBStreamRead (IDataBasedb,
UID id 
)
static

Open a stream for reading a database object

Parameters
dbwhat database the object is in
UIDthe object in the database to access
Returns
IPMStream* the new stream, or nil if the stream cannot be opened.
static IPMStream* StreamUtil::CreateDBStreamWrite (IDataBasedb,
UID id 
)
static

Open a stream for writing a database record.

Parameters
dbwhat database the object is in
UIDthe object in the database to access
Returns
IPMStream* the new stream, or nil if the stream cannot be opened.
static IPMStream* StreamUtil::CreateFileStreamRead (const IDFilesysFile,
uint32 mode = kOpenIn,
OSType fileType = 0x3f3f3f3f,
OSType creator = 0x3f3f3f3f 
)
static

Open a stream for reading from a file.

Parameters
sysFilethe file to read from
modemode for opening the file (open for read, read/write, etc.)
fileTypeon Macintosh, this is the Finder file type
creatoron Macintosh, this the Finder creator type
Returns
IPMStream* the new stream, or nil if the file couldn't be opened.
static IPMStream* StreamUtil::CreateFileStreamReadLazy (const IDFilesysFile,
uint32 mode = kOpenIn,
OSType fileType = 0x3f3f3f3f,
OSType creator = 0x3f3f3f3f 
)
static

Open a stream for reading from a file. The file is opened on demand, the first time a read is requested. Note that in this case, you may get back a valid stream from the CreateFileStreamReadLazy method, but the file hasn't yet been opened. It will be opened as the result of a subsequent read request. If the open fails, the stream will go into an error state

See Also
GetStreamState. Client code should check for this.
Parameters
sysFilethe file to read from
modemode for opening the file (open for read, read/write, etc.)
fileTypeon Macintosh, this is the Finder file type
creatoron Macintosh, this the Finder creator type
Returns
IPMStream* the new stream, or nil if the file couldn't be opened.
static IPMStream* StreamUtil::CreateFileStreamWrite (const IDFilesysFile,
uint32 mode = kOpenOut,
OSType fileType = 0x3f3f3f3f,
OSType creator = 0x3f3f3f3f 
)
static

Open a stream for writing to a file.

Parameters
sysFilethe file to read from
modemode for opening the file (open for read, read/write, etc.)
fileTypeon Macintosh, this is the Finder file type
creatoron Macintosh, this the Finder creator type
Returns
IPMStream* the new stream, or nil if the file couldn't be opened.
static IPMStream* StreamUtil::CreateFileStreamWriteLazy (const IDFilesysFile,
uint32 mode = kOpenOut|kOpenTrunc,
OSType fileType = 0x3f3f3f3f,
OSType creator = 0x3f3f3f3f 
)
static

Open a stream for writing to a file. The file is opened on demand, the first time a write is requested. Note that in this case, you may get back a valid stream from the CreateFileStreamWriteLazy method, but the file hasn't yet been opened. It will be opened as the result of a subsequent write request. If the open fails, the stream will go into an error state

See Also
GetStreamState. Client code should check for this.
Parameters
sysFilethe file to read from
modemode for opening the file (open for read, read/write, etc.)
fileTypeon Macintosh, this is the Finder file type
creatoron Macintosh, this the Finder creator type
Returns
IPMStream* the new stream, or nil if the file couldn't be opened.
static IPMStream* StreamUtil::CreateManagedFileStreamRead (const IDFilesysFile,
uint32 mode = kOpenIn,
OSType fileType = 0x3f3f3f3f,
OSType creator = 0x3f3f3f3f 
)
static

Open a stream for reading from a file, downloads the file if it's not already in local repository. Returns nil if file cannot be opened.

Parameters
sysFilethe file to read from
modemode for opening the file (open for read, read/write, etc.)
fileTypeon Macintosh, this is the Finder file type
creatoron Macintosh, this the Finder creator type
Returns
IPMStream* the new stream, or nil if the file couldn't be opened.
static IPMStream* StreamUtil::CreateManagedFileStreamReadLazy (const IDFilesysFile,
uint32 mode = kOpenIn,
OSType fileType = 0x3f3f3f3f,
OSType creator = 0x3f3f3f3f 
)
static

Open a stream for reading from a file. File is actually opened on demand, the first time a read is requested. Downloads the file if it's not already in local repository. Returns nil if file cannot be opened.

Parameters
sysFilethe file to read from
modemode for opening the file (open for read, read/write, etc.)
fileTypeon Macintosh, this is the Finder file type
creatoron Macintosh, this the Finder creator type
Returns
IPMStream* the new stream, or nil if the file couldn't be opened.
static IPMStream* StreamUtil::CreateMemoryStreamRead (IXferBytesunderlyingXferBytes,
bool16 takeOwnership = kFalse,
bool16 recycleBoss = kTrue 
)
static

Open a stream for reading from memory.

Parameters
underlyingXferBytesIXferBytes instance the memory stream will read from.
takeOwnershipDenotes whether the stream is to be the sole owner of the given IXferBytes.
recycleBossDenotes whether to utilize a recycle boss for the stream.\ If the underlying IXferBytes must be released to free up resources, a file for instance, it is recommended to not use a recycle boss since the IXferBytes might not be released until the stream boss is reused.
Returns
IPMStream* the new read stream
static IPMStream* StreamUtil::CreateMemoryStreamWrite (IXferBytesunderlyingXferBytes,
bool16 takeOwnership = kFalse,
bool16 recycleBoss = kTrue 
)
static

Open a stream for writing to memory.

Parameters
underlyingXferBytesIXferBytes instance the memory stream will write to.
takeOwnershipDenotes whether the stream is to be the sole owner of the given IXferBytes.
recycleBossDenotes whether to utilize a recycle boss for the stream.\ If the underlying IXferBytes must be released to free up resources, a file for instance, it is recommended to not use a recycle boss since the IXferBytes might not be released until the stream boss is reused.
Returns
IPMStream* the new write stream
static IPMStream* StreamUtil::CreatePointerStreamRead (char * buffer,
size_t len 
)
static

Open a stream for reading from memory.

Parameters
buffermemory address to start reading from
lennumber of bytes to read
Returns
IPMStream* the new stream.
static IPMStream* StreamUtil::CreatePointerStreamWrite (char * buffer,
size_t len 
)
static

Open a stream for writing to memory.

Parameters
buffermemory address to start writing to
lennumber of bytes that can be written before end of stream
Returns
IPMStream* the new stream
static IPMStream* StreamUtil::CreateResourceStreamRead (const RsrcSpecspec,
bool16 useLocaleIndexResource = kTrue 
)
static

Open a stream for reading from a resource.

Parameters
speca descriptor of the resource to read
useLocaleIndexResourcekTrue to use a localized resource
Returns
IPMStream* the new stream
static void StreamUtil::ResetStreamContentsChanged (IPMStream)
inlinestatic

The following functions are used for verifying stream contents. They is debugging only because they are used to control assertions. There's an assert that comes up if an object has been modified, but Dirty() was never called on it ("object changed but not marked dirty"). The assert is for early detection of cases which could cause document corruption, but it does come up in some situations that are actually OK. For example, if your code does dynamic conversion of data, so that it gets converted when its read in, it would get this assert but be OK. Or if it writes out the current time. In any case, you can set a flag on the stream that causes the assert not to fire. From your ReadWrite, in the case where you're writing out, call SetStreamContentsChanged, and the assert will not come up.Set the stream back to normal after a call to SetStreamContentsChanged. Does nothing in Release target.

Parameters
sthe stream to set
static void StreamUtil::SetStreamContentsChanged (IPMStream)
inlinestatic

Set the stream to "changes expected" to prevent the assert from firing. Does nothing in Release target.

Parameters
sthe stream to set
static bool16 StreamUtil::StreamContentsChanged (IPMStream)
inlinestatic

Get the stream to "changes expected" to see if the assert should fire. Does nothing in Release target. Internal Use Only.

Parameters
sthe stream to set
Returns
bool16 return true if the stream has changes expected