Class StorageOutputStream

    • Constructor Detail

      • StorageOutputStream

        protected StorageOutputStream()
        Sole constructor.
    • Method Detail

      • toStorage

        public final Storage toStorage()
                                throws IOException
        Closes this output stream if it has not already been closed and returns a Storage object which contains the bytes that have been written to this output stream.

        Note that this method may not be invoked a second time. This is because for some implementations it is not possible to create another Storage object that can be read from and deleted independently (e.g. if the implementation writes to a file).

        Returns:
        a Storage object as described above.
        Throws:
        IOException - if an I/O error occurs.
        IllegalStateException - if this method has already been called.
      • write0

        protected abstract void write0​(byte[] buffer,
                                       int offset,
                                       int length)
                                throws IOException
        Has to implemented by a concrete subclass to write bytes from the given byte array to this StorageOutputStream. This method gets called by write(int), write(byte[]) and write(byte[], int, int). All the required preconditions have already been checked by these methods, including the check if the output stream has already been closed.
        Parameters:
        buffer - buffer containing bytes to write.
        offset - start offset in the buffer.
        length - number of bytes to write.
        Throws:
        IOException - if an I/O error occurs.
      • toStorage0

        protected abstract Storage toStorage0()
                                       throws IOException
        Has to be implemented by a concrete subclass to create a Storage object from the bytes that have been written to this StorageOutputStream. This method gets called by toStorage() after the preconditions have been checked. The implementation can also be sure that this methods gets invoked only once.
        Returns:
        a Storage object as described above.
        Throws:
        IOException - if an I/O error occurs.