Class StreamManager

java.lang.Object
com.adobe.internal.io.stream.StreamManager

public final class StreamManager extends Object
Only for internal engineering use. This api can change without notice. The source for all InputByteStream and OutputByteStream instances.
  • Method Details

    • newInstance

      public static StreamManager newInstance(ByteWriterFactory byteWriterFactory, ByteReader masterByteReader)
      Creates a new instance of the StreamManager. The ByteWriterFactory is used as the source of all new data sinks that are created. The "master" ByteReader is the main ByteReader used in the document processing. It is the backing store for the document. This will be closed and so will all InputByteStream instances made from it when the StreamManager is closed or the master ByteReader is reset.
      Parameters:
      byteWriterFactory - factory to use for creating new OutputByteStream instances
      masterByteReader - the "master" byte reader, can be null if there is no master
      Returns:
      a newly created StreamManager
    • resetMasterByteReader

      public void resetMasterByteReader(ByteReader masterByteReader) throws IOException
      Reset the master ByteReader and close it and all InputByteStream instances made from it.
      Parameters:
      masterByteReader - the new master ByteReader, can be null
      Throws:
      IOException
    • getInputByteStream

      public InputByteStream getInputByteStream(ByteReader byteReader) throws IOException
      Only for internal engineering use. This api can change without notice. Create an InputByteStream from a ByteReader.
      Parameters:
      byteReader - A ByteReader to be used for creating the InputByteStream.
      Returns:
      An InputByteStream.
      Throws:
      IOException
    • getInputByteStream

      public InputByteStream getInputByteStream(ByteReader byteReader, long startOffset, long length) throws IOException
      Only for internal engineering use. This api can change without notice. Create an InputByteStream from a ByteReader.
      Parameters:
      byteReader - A ByteReader to be used for creating the InputByteStream.
      Returns:
      An InputByteStream.
      Throws:
      IOException
    • getInputByteStream

      public InputByteStream getInputByteStream(byte[] b) throws IOException
      Only for internal engineering use. This api can change without notice. Create an InputByteStream from a byte array.
      Parameters:
      b - An array of bytes to be used for creating the InputByteStream.
      Returns:
      An InputByteStream.
      Throws:
      IOException
    • getInputByteStream

      public InputByteStream getInputByteStream(InputByteStream[] byteStreams) throws IOException
      Only for internal engineering use. This api can change without notice. Create an OutputByteStream. This creates an OutputByteStream that wraps multiple OutputByteStream objects and makes them appear as one large OutputByteStream. The OutputByteStream objects that are passed must not be modified in any way until the wrapping OutputByteStream returned from this method is no longer in use.
      Parameters:
      byteStreams - An array of OutputByteStream objects.
      Returns:
      An OutputByteStream.
      Throws:
      IOException
    • getOutputByteStream

      public OutputByteStream getOutputByteStream(ByteWriter byteWriter) throws IOException
      Only for internal engineering use. This api can change without notice. Create an OutputByteStream from a ByteWriter.
      Parameters:
      byteWriter - A ByteWriter to be used for creating the OutputByteStream.
      Returns:
      An OutputByteStream.
      Throws:
      IOException
    • getUnregisteredOutputByteStream

      public OutputByteStream getUnregisteredOutputByteStream(ByteWriter byteWriter) throws IOException
      Only for internal engineering use. This api can change without notice. Create an OutputByteStream from a ByteWriter. The returned OutputByteStream is unregistered and so will not be managed by the stream manager. It is the responsibility of the caller to ensure that the ByteWriter and the OutputByteStream are properly closed.
      Parameters:
      byteWriter - A ByteWriter to be used for creating the OutputByteStream.
      Returns:
      An OutputByteStream.
      Throws:
      IOException
    • getOutputByteStreamClearTemp

      public OutputByteStream getOutputByteStreamClearTemp(ByteWriterFactory.Fixed fixed, long size) throws IOException
      A utility function that calls getOutputByteStream(Longevity, EncryptionStatus, Fixed, long, boolean) with the following parameters:
      Longevity - Longevity.TEMPORARY
      EncryptionStatus - EncryptionStatus.CLEAR This is intended to create an OutputByteStream whose duration is temporary (lasting the duration of a single method) and the data to be stored is not encrypted nor is it decrypted.
      Parameters:
      fixed - whether the memory size is fixed or growable
      size - the number of bytes for OutputByteStream
      Returns:
      the newly created OutputByteStream
      Throws:
      IOException
    • getOutputByteStreamEncryptedTemp

      public OutputByteStream getOutputByteStreamEncryptedTemp(ByteWriterFactory.Fixed fixed, long size) throws IOException
      A utility function that calls getOutputByteStream(Longevity, EncryptionStatus, Fixed, long, boolean) with the following parameters:
      Longevity - Longevity.TEMPORARY
      EncryptionStatus - EncryptionStatus.ENCRYPTED This is intended to create an OutputByteStream whose duration is temporary (lasting the duration of a single method) and the data to be stored is encrypted.
      Parameters:
      fixed - whether the memory size is fixed or growable
      size - the number of bytes for OutputByteStream
      Returns:
      the newly created OutputByteStream
      Throws:
      IOException
    • getOutputByteStreamDecryptedTemp

      public OutputByteStream getOutputByteStreamDecryptedTemp(ByteWriterFactory.Fixed fixed, long size) throws IOException
      A utility function that calls getOutputByteStream(Longevity, EncryptionStatus, Fixed, long, boolean) with the following parameters:
      Longevity - Longevity.TEMPORARY
      EncryptionStatus - EncryptionStatus.DECRYPTED This is intended to create an OutputByteStream whose duration is temporary (lasting the duration of a single method) and the data to be stored is decrypted.
      Parameters:
      fixed - whether the memory size is fixed or growable
      size - the number of bytes for OutputByteStream
      Returns:
      the newly created OutputByteStream
      Throws:
      IOException
    • getOutputByteStreamClearDocument

      public OutputByteStream getOutputByteStreamClearDocument(ByteWriterFactory.Fixed fixed, long size) throws IOException
      A utility function that calls getOutputByteStream(Longevity, EncryptionStatus, Fixed, long, boolean) with the following parameters:
      Longevity - Longevity.LONG
      EncryptionStatus - EncryptionStatus.CLEAR This is intended to create an OutputByteStream whose expected duration of existence is of similar length to that of the PDFDocument and the data to be stored is not encrypted nor is it decrypted.
      Parameters:
      fixed - whether the memory size is fixed or growable
      size - the number of bytes for OutputByteStream
      Returns:
      the newly created OutputByteStream
      Throws:
      IOException
    • getOutputByteStreamEncryptedDocument

      public OutputByteStream getOutputByteStreamEncryptedDocument(ByteWriterFactory.Fixed fixed, long size) throws IOException
      A utility function that calls getOutputByteStream(Longevity, EncryptionStatus, Fixed, long, boolean) with the following parameters:
      Longevity - Longevity.LONG
      EncryptionStatus - EncryptionStatus.ENCRYPTED This is intended to create an OutputByteStream whose expected duration of existence is of similar length to that of the PDFDocument and the data to be stored is encrypted.
      Parameters:
      fixed - whether the memory size is fixed or growable
      size - the number of bytes for OutputByteStream
      Returns:
      the newly created OutputByteStream
      Throws:
      IOException
    • getOutputByteStreamDecryptedDocument

      public OutputByteStream getOutputByteStreamDecryptedDocument(ByteWriterFactory.Fixed fixed, long size) throws IOException
      A utility function that calls getOutputByteStream(Longevity, EncryptionStatus, Fixed, long, boolean) with the following parameters:
      Longevity - Longevity.LONG
      EncryptionStatus - EncryptionStatus.DECRYPTED This is intended to create an OutputByteStream whose expected duration of existence is of similar length to that of the PDFDocument and the data to be stored is decrypted.
      Parameters:
      fixed - whether the memory size is fixed or growable
      size - the number of bytes for OutputByteStream
      Returns:
      the newly created OutputByteStream
      Throws:
      IOException
    • getUnregisteredOutputByteStream

      public OutputByteStream getUnregisteredOutputByteStream(ByteWriterFactory.Fixed fixed, int size) throws IOException
      Create an OutputByteStream for use within the COS layer of the PDF toolkit. This OutputByteStream will not be kept track of through an internal registry and if not used correctly and carefully can lead to problems. This is not to be used outside of the COS layer. If it is desired to turn the OutputByteStream into an InputByteStream this can be done by using the OutputByteStream.closeAndConvert() method.
      Parameters:
      fixed - is the OutputByteStream of a fixed size or not
      size - the actual size of a fixed OutputByteStream or an estimate of a growable one
      Returns:
      a stream for writing data to
      Throws:
      IOException
    • getOutputByteStream

      public OutputByteStream getOutputByteStream(ByteWriterFactory.Longevity longevity, ByteWriterFactory.EncryptionStatus encryption, ByteWriterFactory.Fixed fixed, long size, boolean fast) throws IOException
      Create an OutputByteStream for use within the PDF toolkit. This OutputByteStream will be kept track of through an internal registry and will need to be properly closed by the caller. If it is desired to turn the OutputByteStream into an InputByteStream this can be done by using the OutputByteStream.closeAndConvert() method.
      Parameters:
      longevity - an estimate of how long the OutputByteStream will remain in use
      encryption - the encryption status of the contents of the OutputByteStream
      fixed - is the OutputByteStream of a fixed size or not
      size - the actual size of a fixed OutputByteStream or an estimate of a growable one
      fast - a request for a faster OutputByteStream which is only a suggestion
      Returns:
      a stream for writing data to
      Throws:
      IOException
    • getByteWriter

      public ByteWriter getByteWriter(ByteWriterFactory.Fixed fixed, long size) throws IOException
      Create a ByteWriter. This ByteWriter is not kept track of and will need to be properly closed by the caller. This is a potentially large resource leak if used improperly. Be extremely careful. This method is only in place for one place within the code that will soon be rewritten. Do not use for new code.

      This method has similar parameters as getOutputByteStream(Longevity, EncryptionStatus, Fixed, long, boolean) but makes the following default choices:
      Longevity - Longevity.LONG
      EncryptionStatus - EncryptionStatus.CLEAR

      Parameters:
      fixed - is the OutputByteStream of a fixed size or not
      size - the actual size of a fixed OutputByteStream or an estimate of a growable one
      Returns:
      a stream for writing data to
      Throws:
      IOException
    • close

      public void close() throws IOException
      Close this StreamManager. This closes all open ByteReader instances and any InputByteStream instances made from. The ByteWriterFactory given during construction is also closed. In the future if there are open ByteReader instances this will be considered an error state and an exception will be thrown.
      Throws:
      IOException
    • close

      public void close(boolean ignoreMaster) throws IOException
      Close this StreamManager. This closes all open ByteReader instances and any InputByteStream instances made from. The ByteWriterFactory given during construction is also closed. In the future if there are open ByteReader instances this will be considered an error state and an exception will be thrown.
      Parameters:
      ignoreMaster - if true the master ByteReader is ignored for closing and it will be the responsibility of the caller to close it
      Throws:
      IOException