Class OOXMLStreamWriter

java.lang.Object
java.io.Writer
com.nomagic.magicreport.engine.ooxml.OOXMLStreamWriter
All Implemented Interfaces:
Closeable, Flushable, Appendable, AutoCloseable

@OpenApiAll public class OOXMLStreamWriter extends Writer
This class implements a writer that can be used for OOXML. The writer write data into content.xml by default. An OOXMLStreamWriter is also provide a bridge from character streams to byte streams: Characters written to it are encoded into bytes using a specified charset.
Since:
Oct 19, 2009
  • Field Details

    • zipOutputStream

      protected ZipOutputStream zipOutputStream
      An internal output stream for ZIP file.
  • Constructor Details

    • OOXMLStreamWriter

      public OOXMLStreamWriter(OutputStream out, String entryName) throws IOException
      Create an OOXMLStreamWriter.
      Parameters:
      out - An OutputStream
      entryName - target entry name
      Throws:
      ZipException - if a ZIP file error has occurred
      IOException - if an I/O error has occurred
    • OOXMLStreamWriter

      public OOXMLStreamWriter(OutputStream out, String entryName, String charsetName) throws IOException
      Create an OOXMLStreamWriter that uses the named charset.
      Parameters:
      out - An OutputStream
      entryName - target entry name
      charsetName - The name of a supported java.nio.charset.Charset charset
      Throws:
      ZipException - if a ZIP file error has occurred
      IOException - if an I/O error has occurred
    • OOXMLStreamWriter

      public OOXMLStreamWriter(OutputStream out, String entryName, String charsetName, File fileBuffer) throws IOException
      Create an OOXMLStreamWriter that uses the named charset and file buffer. File buffer will be tracked and delete when this object has been destroyed.
      Parameters:
      out - An OutputStream
      entryName - target entry name
      charsetName - The name of a supported java.nio.charset.Charset charset
      fileBuffer - use this file to buffer a OOXML content. If no fileBuffer is specified, content will be stored in memory.
      Throws:
      ZipException - if a ZIP file error has occurred
      IOException - if an I/O error has occurred
  • Method Details

    • ensureOpen

      protected void ensureOpen() throws IOException
      Check to make sure that the stream has not been closed.
      Throws:
      IOException - If stream has been closed
    • close

      public void close() throws IOException
      Close the stream.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Specified by:
      close in class Writer
      Throws:
      IOException - If an I/O error occurs
    • flush

      public void flush() throws IOException
      Flushes the stream.
      Specified by:
      flush in interface Flushable
      Specified by:
      flush in class Writer
      Throws:
      IOException - If an I/O error occurs
    • write

      public void write(char[] cbuf, int offset, int length) throws IOException
      Write characters into current entry.
      Specified by:
      write in class Writer
      Parameters:
      cbuf - Array of characters
      offset - Offset from which to start writing characters
      length - Number of characters to write
      Throws:
      IOException - If an I/O error occurs
    • write

      public void write(String text) throws IOException
      Write text into current entry.
      Overrides:
      write in class Writer
      Parameters:
      text - text
      Throws:
      IOException - If an I/O error occurs
    • getOutputStream

      public OutputStream getOutputStream() throws IOException
      Returns an output stream for this writer.
      Returns:
      an output stream for writing bytes to this writer.
      Throws:
      IOException - if an I/O error has occurred
    • putNextEntry

      public void putNextEntry(OOXMLEntry entry) throws IOException
      Begins writing a new OOXML entry and positions the stream to the start of the entry data.
      Parameters:
      entry - the OOXML entry to be written
      Throws:
      IOException - if an I/O error has occurred
    • closeEntry

      public void closeEntry() throws IOException
      Closes the current OOXML entry and positions the stream for writing the next entry.
      Throws:
      IOException - if an I/O error has occurred
    • write

      public void write(byte[] buf, int offset, int length) throws IOException
      Writes an array of bytes to the current OOXML entry data. This method will block until all the bytes are written.
      Parameters:
      buf - the data to be written
      offset - the start offset in the data
      length - the number of bytes that are written
      Throws:
      IOException - if an I/O error has occurred