org.apache.xmlgraphics.ps.dsc

## Class ResourceTracker

- java.lang.Object
- - org.apache.xmlgraphics.ps.dsc.ResourceTracker

-     public class ResourceTracker
      extends java.lang.Object

  This class is used to track resources in a DSC-compliant PostScript file. The distinction is made between supplied and needed resources. For the details of this distinction, please see the DSC specification.

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `ResourceTracker()`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `declareInlined(PSResource res)` This method declares that the given resource will be inlined and can therefore be removed from resource tracking.
    `java.util.Set` | `getDocumentNeededResources()` Returns the set of needed resources.
    `java.util.Set` | `getDocumentSuppliedResources()` Returns the set of supplied resources.
    `long` | `getUsageCount(PSResource res)` Returns the number of times a resource has been used inside the current DSC document.
    `boolean` | `isResourceSupplied(PSResource res)` Indicates whether a particular resource is supplied, rather than needed.
    `void` | `notifyResourceUsageOnPage(java.util.Collection resources)` Notifies the resource tracker about the usage of resources on the current page.
    `void` | `notifyResourceUsageOnPage(PSResource res)` Notifies the resource tracker about the usage of a resource on the current page.
    `void` | `notifyStartNewPage()` Notifies the resource tracker that a new page has been started and that the page resource set can be cleared.
    `void` | `registerNeededResource(PSResource res)` Registers a needed resource.
    `void` | `registerSuppliedResource(PSResource res)` Registers a supplied resource.
    `void` | `writeDocumentResources(PSGenerator gen)` Writes a DSC comment for the needed and supplied resourced for the current DSC document.
    `void` | `writePageResources(PSGenerator gen)` Writes a DSC comment for the accumulated used resources on the current page.
    `void` | `writeResources(boolean pageLevel, PSGenerator gen)` Writes a DSC comment for the accumulated used resources, either at page level or at document level.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### ResourceTracker

          public ResourceTracker()

  - ### Method Detail

    - #### getDocumentSuppliedResources

          public java.util.Set getDocumentSuppliedResources()

      Returns the set of supplied resources.
      Returns:
        the set of supplied resources

    - #### getDocumentNeededResources

          public java.util.Set getDocumentNeededResources()

      Returns the set of needed resources.
      Returns:
        the set of needed resources

    - #### notifyStartNewPage

          public void notifyStartNewPage()

      Notifies the resource tracker that a new page has been started and that the page resource set can be cleared.

    - #### registerSuppliedResource

          public void registerSuppliedResource(PSResource res)

      Registers a supplied resource. If the same resources is already in the set of needed resources, it is removed there.
      Parameters:
        `res` - the resource

    - #### registerNeededResource

          public void registerNeededResource(PSResource res)

      Registers a needed resource. If the same resources is already in the set of supplied resources, it is ignored, i.e. it is assumed to be supplied.
      Parameters:
        `res` - the resource

    - #### notifyResourceUsageOnPage

          public void notifyResourceUsageOnPage(PSResource res)

      Notifies the resource tracker about the usage of a resource on the current page.
      Parameters:
        `res` - the resource being used

    - #### notifyResourceUsageOnPage

          public void notifyResourceUsageOnPage(java.util.Collection resources)

      Notifies the resource tracker about the usage of resources on the current page.
      Parameters:
        `resources` - the resources being used

    - #### isResourceSupplied

          public boolean isResourceSupplied(PSResource res)

      Indicates whether a particular resource is supplied, rather than needed.
      Parameters:
        `res` - the resource
      Returns:
        true if the resource is registered as being supplied.

    - #### writeResources

          public void writeResources(boolean pageLevel,
                                     PSGenerator gen)
                              throws java.io.IOException

      Writes a DSC comment for the accumulated used resources, either at page level or at document level.
      Parameters:
        `pageLevel` - true if the DSC comment for the page level should be generated, false for the document level (in the trailer)
        `gen` - the PSGenerator to write the DSC comments with
      Throws:
        `java.io.IOException` - In case of an I/O problem

    - #### writePageResources

          public void writePageResources(PSGenerator gen)
                                  throws java.io.IOException

      Writes a DSC comment for the accumulated used resources on the current page. Then it commits all those resources to the used resources on document level.
      Parameters:
        `gen` - the PSGenerator to write the DSC comments with
      Throws:
        `java.io.IOException` - In case of an I/O problem

    - #### writeDocumentResources

          public void writeDocumentResources(PSGenerator gen)
                                      throws java.io.IOException

      Writes a DSC comment for the needed and supplied resourced for the current DSC document.
      Parameters:
        `gen` - the PSGenerator to write the DSC comments with
      Throws:
        `java.io.IOException` - In case of an I/O problem

    - #### declareInlined

          public void declareInlined(PSResource res)

      This method declares that the given resource will be inlined and can therefore be removed from resource tracking. This is useful when you don't know beforehand if a resource will be used multiple times. If it's only used once it's better to inline the resource to lower the maximum memory needed inside the PostScript interpreter.
      Parameters:
        `res` - the resource

    - #### getUsageCount

          public long getUsageCount(PSResource res)

      Returns the number of times a resource has been used inside the current DSC document.
      Parameters:
        `res` - the resource
      Returns:
        the number of times the resource has been used

Copyright 1999-2025 The Apache Software Foundation. All Rights Reserved.