1 #include "WPXSvStream.h"
2 #include "filter/FilterInternal.hxx"
3 #include <tools/stream.hxx>
4 #include <unotools/streamwrap.hxx>
5 #include <unotools/ucbstreamhelper.hxx>
8 using namespace ::com::sun::star::uno
;
9 using namespace ::com::sun::star::io
;
11 WPXSvInputStream::WPXSvInputStream( Reference
< XInputStream
> xStream
) :
16 mxSeekable(xStream
, UNO_QUERY
),
19 if (!xStream
.is() || !mxStream
.is())
29 mnLength
= mxSeekable
->getLength();
33 WRITER_DEBUG_MSG(("mnLength = mxSeekable->getLength() threw exception\n"));
40 WPXSvInputStream::~WPXSvInputStream()
44 const uint8_t * WPXSvInputStream::read(size_t numBytes
, size_t &numBytesRead
)
48 if (numBytes
== 0 || atEOS())
51 numBytesRead
= mxStream
->readSomeBytes (maData
, numBytes
);
52 if (numBytesRead
== 0)
55 return (const uint8_t *)maData
.getConstArray();
58 long WPXSvInputStream::tell()
60 if ((mnLength
== 0) || !mxStream
.is() || !mxSeekable
.is())
64 sal_Int64 tmpPosition
= mxSeekable
->getPosition();
65 if ((tmpPosition
< 0) || (tmpPosition
> (std::numeric_limits
<long>::max
)()))
67 return (long)tmpPosition
;
71 int WPXSvInputStream::seek(long offset
, WPX_SEEK_TYPE seekType
)
73 if ((mnLength
== 0) || !mxStream
.is() || !mxSeekable
.is())
76 sal_Int64 tmpPosition
= mxSeekable
->getPosition();
77 if ((tmpPosition
< 0) || (tmpPosition
> (std::numeric_limits
<long>::max
)()))
80 sal_Int64 tmpOffset
= offset
;
81 if (seekType
== WPX_SEEK_CUR
)
82 tmpOffset
+= tmpPosition
;
90 if (offset
> mnLength
)
98 mxSeekable
->seek(tmpOffset
);
103 WRITER_DEBUG_MSG(("mxSeekable->seek(offset) threw exception\n"));
108 bool WPXSvInputStream::atEOS()
110 if ((mnLength
== 0) || !mxStream
.is() || !mxSeekable
.is())
112 return (mxSeekable
->getPosition() >= mnLength
);
115 bool WPXSvInputStream::isOLEStream()
117 if ((mnLength
== 0) || !mxStream
.is() || !mxSeekable
.is())
120 sal_Int64 tmpPosition
= mxSeekable
->getPosition();
123 SvStream
*pStream
= utl::UcbStreamHelper::CreateStream( mxStream
);
124 bool bAns
= pStream
&& SotStorage::IsOLEStorage( pStream
);
128 mxSeekable
->seek(tmpPosition
);
133 WPXInputStream
* WPXSvInputStream::getDocumentOLEStream(const char * name
)
135 if ((mnLength
== 0) || !mxStream
.is() || !mxSeekable
.is())
138 sal_Int64 tmpPosition
= mxSeekable
->getPosition();
141 SvStream
*pStream
= utl::UcbStreamHelper::CreateStream( mxStream
);
143 if (!pStream
|| !SotStorage::IsOLEStorage( pStream
))
145 mxSeekable
->seek(tmpPosition
);
149 mxChildStorage
= new SotStorage( pStream
, TRUE
);
151 mxChildStream
= mxChildStorage
->OpenSotStream(
152 rtl::OUString::createFromAscii( name
),
155 mxSeekable
->seek(tmpPosition
);
157 if ( !mxChildStream
.Is() || mxChildStream
->GetError() )
159 mxSeekable
->seek(tmpPosition
);
163 Reference
< XInputStream
> xContents(new utl::OSeekableInputStreamWrapper( mxChildStream
));
164 mxSeekable
->seek(tmpPosition
);
166 return new WPXSvInputStream( xContents
);
171 WPXInputStream
* WPXSvInputStream::getDocumentOLEStream()
173 return getDocumentOLEStream( "PerfectOffice_MAIN" );