Class OOXMLStreamReader

java.lang.Object
java.io.Reader
com.nomagic.magicreport.engine.ooxml.OOXMLStreamReader
All Implemented Interfaces:
Closeable, AutoCloseable, Readable

@OpenApiAll public class OOXMLStreamReader extends Reader
This class implements a reader that can be used for OOXML. The reader reader data from content.xml by default. An OOXMLStreamReader is also provide a bridge from byte streams to characters streams: It reads bytes and decodes them into characters using a specified charset
Since:
Oct 19, 2009
  • Field Details

    • zipInputStream

      protected ZipInputStream zipInputStream
      An internal input stream for ZIP file.
    • contentReader

      protected InputStreamReader contentReader
      An internal reader for specified content entry.
    • contentEntry

      protected OOXMLEntry contentEntry
      Keep the entry for content reader.
  • Constructor Details

    • OOXMLStreamReader

      public OOXMLStreamReader(InputStream in, String entryName) throws IOException
      Create an OOXMLStreamReader that uses the named charset.
      Parameters:
      in - An InputStream
      entryName - target entry name
      Throws:
      UnsupportedEncodingException - If the named charset is not supported
      IOException - if an I/O error has occurred
    • OOXMLStreamReader

      public OOXMLStreamReader(InputStream in, String entryName, String charsetName) throws IOException
      Create an OOXMLStreamReader that uses the named charset and entry.
      Parameters:
      in - An InputStream
      entryName - target entry name
      charsetName - The name of a supported java.nio.charset.Charset charset
      Throws:
      UnsupportedEncodingException - If the named charset is not supported
      IOException - if an I/O error has occurred
  • Method Details

    • init

      public void init(String entryName) throws IOException
      Initialize ODF stream.
      Parameters:
      entryName - name of target reading entry.
      Throws:
      IOException - If an I/O error occurs
    • getContentEntry

      public OOXMLEntry getContentEntry()
      Returns the OOXML file entry for the reader, or null if not found.
      Returns:
      the OOXML file entry, or null if not found
    • 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 Reader
      Throws:
      IOException - If an I/O error occurs
    • read

      public int read(char[] cbuf, int offset, int length) throws IOException
      Read characters from content.xml into a portion of an array. This method will block until some input is available, an I/O error occurs, or the end of the stream is reached.
      Specified by:
      read in class Reader
      Parameters:
      cbuf - Destination buffer
      offset - Offset at which to start storing characters
      length - Maximum number of characters to read
      Returns:
      The number of characters read, or -1 if the end of the stream has been reached
      Throws:
      IOException - If an I/O error occurs
    • read

      public int read(byte[] b, int off, int len) throws IOException
      Reads from the current OOXML entry into an array of bytes. Blocks until some input is available.
      Parameters:
      b - the buffer into which the data is read
      off - the start offset of the data
      len - the maximum number of bytes read
      Returns:
      the actual number of bytes read, or -1 if the end of the entry is reached
      Throws:
      IOException - if an I/O error has occurred
    • getNextEntry

      public OOXMLEntry getNextEntry() throws IOException
      Reads the next OOXML file entry and positions the stream at the beginning of the entry data.
      Returns:
      the next OOXML file entry, or null if there are no more entries
      Throws:
      IOException - if an I/O error has occurred