summaryrefslogtreecommitdiff
path: root/sax
diff options
context:
space:
mode:
authorMatúš Kukan <matus.kukan@collabora.com>2014-09-24 14:55:02 +0200
committerMatúš Kukan <matus.kukan@collabora.com>2014-10-23 11:53:14 +0200
commitb7266ddb2f580a2ed3c558d1996b5e2760023145 (patch)
treea2a130ee1dc29c1b07497c499dd3ac3afd6a371b /sax
parent5c8ea6d943ef37d73069288f9ef7dbd374721a71 (diff)
FastSerializer: Buffer output and write it only at the end
Use OSequenceOutputStream class to concatenate strings in a Sequence<sal_Int8> buffer. And write data to file only at the end. The design is a bit fragile, since all FSHelpers need to be destroyed before calling FilterBase::commitStorage(). Otherwise data is not written. Change-Id: I26b02335ef36011bfcda17484b560811d18c7657
Diffstat (limited to 'sax')
-rw-r--r--sax/source/tools/fastserializer.cxx11
-rw-r--r--sax/source/tools/fastserializer.hxx6
2 files changed, 14 insertions, 3 deletions
diff --git a/sax/source/tools/fastserializer.cxx b/sax/source/tools/fastserializer.cxx
index fbce18aa9ab0..a9520e4907ea 100644
--- a/sax/source/tools/fastserializer.cxx
+++ b/sax/source/tools/fastserializer.cxx
@@ -53,7 +53,9 @@ using ::com::sun::star::io::BufferSizeExceededException;
namespace sax_fastparser {
FastSaxSerializer::FastSaxSerializer( )
- : mxOutputStream()
+ : maOutputData()
+ , maOutputStream(maOutputData)
+ , mxOutputStream()
, mxFastTokenHandler()
, maMarkStack()
, maClosingBracket((const sal_Int8 *)">", 1)
@@ -112,6 +114,9 @@ namespace sax_fastparser {
{
if (!mxOutputStream.is())
return;
+
+ maOutputStream.flush();
+ mxOutputStream->writeBytes(maOutputData);
}
void SAL_CALL FastSaxSerializer::writeId( ::sal_Int32 nElement )
@@ -293,7 +298,7 @@ namespace sax_fastparser {
if ( maMarkStack.size() == 1 && eMergeType != MERGE_MARKS_IGNORE)
{
- mxOutputStream->writeBytes( maMarkStack.top()->getData() );
+ maOutputStream.writeBytes( maMarkStack.top()->getData() );
maMarkStack.pop();
return;
}
@@ -314,7 +319,7 @@ namespace sax_fastparser {
void FastSaxSerializer::writeBytes( const Sequence< ::sal_Int8 >& aData ) throw ( NotConnectedException, BufferSizeExceededException, IOException, RuntimeException )
{
if ( maMarkStack.empty() )
- mxOutputStream->writeBytes( aData );
+ maOutputStream.writeBytes( aData );
else
maMarkStack.top()->append( aData );
}
diff --git a/sax/source/tools/fastserializer.hxx b/sax/source/tools/fastserializer.hxx
index a88e3ca0e166..147d7671d160 100644
--- a/sax/source/tools/fastserializer.hxx
+++ b/sax/source/tools/fastserializer.hxx
@@ -29,6 +29,7 @@
#include <boost/shared_ptr.hpp>
+#include <comphelper/seqstream.hxx>
#include "sax/fshelper.hxx"
namespace sax_fastparser {
@@ -148,6 +149,11 @@ public:
void mergeTopMarks( sax_fastparser::MergeMarksEnum eMergeType = sax_fastparser::MERGE_MARKS_APPEND );
private:
+ /// Buffer written to mxOutputStream at the end, called from FSHelper destructor.
+ css::uno::Sequence< sal_Int8 > maOutputData;
+ /// Helper class to dynamically allocate memory when needed for maOutputData.
+ comphelper::OSequenceOutputStream maOutputStream;
+ /// Output stream, usually writing data into files.
::com::sun::star::uno::Reference< ::com::sun::star::io::XOutputStream > mxOutputStream;
::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XFastTokenHandler > mxFastTokenHandler;