Class EntityOutputStream

    • Field Detail

      • lock

        protected final Object lock
    • Constructor Detail

      • EntityOutputStream

        public EntityOutputStream()
        Creates a new entity stream with the maximum in memory threshold of a default value.
      • EntityOutputStream

        public EntityOutputStream​(Threshold memoryThreshold)
        Creates a new entity stream with the maximum in memory threshold of the supplied value.
        Parameters:
        memoryThreshold - the maximum number of bytes to hold in memory
      • EntityOutputStream

        public EntityOutputStream​(Threshold memoryThreshold,
                                  Supplier<String> filePrefix)
        Creates a new entity stream with the maximum in memory threshold and a file prefix to be used if the stream needs to be written to a file due to the threshold.
        Parameters:
        memoryThreshold - the maximum number of bytes to hold in memory
        filePrefix - the file prefix if a file is created
      • EntityOutputStream

        public EntityOutputStream​(Threshold memoryThreshold,
                                  Path tmpDir,
                                  Supplier<String> filePrefix)
        Creates a new entity stream with the maximum in memory threshold and a file prefix to be used if the stream needs to be written to a file due to the threshold.
        Parameters:
        memoryThreshold - the maximum number of bytes to hold in memory
        tmpDir - the temporary directory used for files, can be null to use the default
        filePrefix - the file prefix if a file is created
      • EntityOutputStream

        public EntityOutputStream​(Threshold memoryThreshold,
                                  Path tmpDir,
                                  Threshold fileThreshold,
                                  Supplier<String> filePrefix)
        Creates a new entity stream with the maximum in memory threshold and a file prefix to be used if the stream needs to be written to a file due to the threshold.
        Parameters:
        memoryThreshold - the maximum number of bytes to hold in memory
        tmpDir - the temporary directory used for files, can be null to use the default
        filePrefix - the file prefix if a file is created
    • Method Detail

      • isClosed

        public boolean isClosed()
        Checks if the output stream has been closed.
        Returns:
        true if the output stream has been closed, otherwise false
      • toInputStream

        public InputStream toInputStream()
                                  throws IOException
        Creates an input stream from this output stream.

        Note that when invoking this method close() is invoked first.

        Returns:
        an input stream for reading the output
        Throws:
        IOException - if an error occurs creating the input stream
      • getFile

        protected Path getFile()
        Returns the file if one was written to. If this is in memory, this method will return null.

        Important: You must use the lock when accessing this method.

        Returns:
        the file, if it exists, or null
      • getAndClearMemory

        protected byte[] getAndClearMemory()
        Returns the data in memory if getFile() returns null.

        Important: You must use the lock when accessing this method.

        Returns:
        the data in memory or an empty array
      • getContentLength

        public long getContentLength()
                              throws IOException
        The length of the length of the content written.
        Returns:
        the length of the content written
        Throws:
        IOException - if there is an error determining the length of the content