Class OOXMLStreamWriter
java.lang.Object
java.io.Writer
com.nomagic.magicreport.engine.ooxml.OOXMLStreamWriter
- All Implemented Interfaces:
Closeable,Flushable,Appendable,AutoCloseable
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 Summary
FieldsModifier and TypeFieldDescriptionprotected ZipOutputStreamAn internal output stream for ZIP file. -
Constructor Summary
ConstructorsConstructorDescriptionOOXMLStreamWriter(OutputStream out, String entryName) Create an OOXMLStreamWriter.OOXMLStreamWriter(OutputStream out, String entryName, String charsetName) Create an OOXMLStreamWriter that uses the named charset.OOXMLStreamWriter(OutputStream out, String entryName, String charsetName, File fileBuffer) Create an OOXMLStreamWriter that uses the named charset and file buffer. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Close the stream.voidCloses the current OOXML entry and positions the stream for writing the next entry.protected voidCheck to make sure that the stream has not been closed.voidflush()Flushes the stream.Returns an output stream for this writer.voidputNextEntry(OOXMLEntry entry) Begins writing a new OOXML entry and positions the stream to the start of the entry data.voidwrite(byte[] buf, int offset, int length) Writes an array of bytes to the current OOXML entry data.voidwrite(char[] cbuf, int offset, int length) Write characters into current entry.voidWrite text into current entry.
-
Field Details
-
zipOutputStream
An internal output stream for ZIP file.
-
-
Constructor Details
-
OOXMLStreamWriter
Create an OOXMLStreamWriter.- Parameters:
out- An OutputStreamentryName- target entry name- Throws:
ZipException- if a ZIP file error has occurredIOException- if an I/O error has occurred
-
OOXMLStreamWriter
Create an OOXMLStreamWriter that uses the named charset.- Parameters:
out- An OutputStreamentryName- target entry namecharsetName- The name of a supportedjava.nio.charset.Charsetcharset- Throws:
ZipException- if a ZIP file error has occurredIOException- 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 OutputStreamentryName- target entry namecharsetName- The name of a supportedjava.nio.charset.CharsetcharsetfileBuffer- 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 occurredIOException- if an I/O error has occurred
-
-
Method Details
-
ensureOpen
Check to make sure that the stream has not been closed.- Throws:
IOException- If stream has been closed
-
close
Close the stream.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Specified by:
closein classWriter- Throws:
IOException- If an I/O error occurs
-
flush
Flushes the stream.- Specified by:
flushin interfaceFlushable- Specified by:
flushin classWriter- Throws:
IOException- If an I/O error occurs
-
write
Write characters into current entry.- Specified by:
writein classWriter- Parameters:
cbuf- Array of charactersoffset- Offset from which to start writing characterslength- Number of characters to write- Throws:
IOException- If an I/O error occurs
-
write
Write text into current entry.- Overrides:
writein classWriter- Parameters:
text- text- Throws:
IOException- If an I/O error occurs
-
getOutputStream
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
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
Closes the current OOXML entry and positions the stream for writing the next entry.- Throws:
IOException- if an I/O error has occurred
-
write
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 writtenoffset- the start offset in the datalength- the number of bytes that are written- Throws:
IOException- if an I/O error has occurred
-