diff options
Diffstat (limited to 'package/source/zipapi/ByteGrabber.cxx')
-rw-r--r-- | package/source/zipapi/ByteGrabber.cxx | 49 |
1 files changed, 27 insertions, 22 deletions
diff --git a/package/source/zipapi/ByteGrabber.cxx b/package/source/zipapi/ByteGrabber.cxx index 50083b4dafc2..cd9e201dba0b 100644 --- a/package/source/zipapi/ByteGrabber.cxx +++ b/package/source/zipapi/ByteGrabber.cxx @@ -39,9 +39,9 @@ using namespace ::com::sun::star; ByteGrabber::ByteGrabber(uno::Reference < io::XInputStream > const & xIstream) : xStream(xIstream) , xSeek (xIstream, uno::UNO_QUERY ) -, aSequence ( 4 ) { - pSequence = aSequence.getArray(); + mpByteReader = dynamic_cast<comphelper::ByteReader*>(xStream.get()); + assert(mpByteReader); } ByteGrabber::~ByteGrabber() @@ -52,6 +52,8 @@ void ByteGrabber::setInputStream (const uno::Reference < io::XInputStream >& xNe { xStream = xNewStream; xSeek.set(xNewStream, uno::UNO_QUERY); + mpByteReader = dynamic_cast<comphelper::ByteReader*>(xStream.get()); + assert(mpByteReader); } // XInputStream chained @@ -61,6 +63,12 @@ sal_Int32 ByteGrabber::readBytes( uno::Sequence< sal_Int8 >& aData, return xStream->readBytes(aData, nBytesToRead ); } +sal_Int32 ByteGrabber::readBytes( sal_Int8* aData, + sal_Int32 nBytesToRead ) +{ + return mpByteReader->readSomeBytes(aData, nBytesToRead ); +} + // XSeekable chained... void ByteGrabber::seek( sal_Int64 location ) { @@ -88,42 +96,39 @@ sal_Int64 ByteGrabber::getLength( ) sal_uInt16 ByteGrabber::ReadUInt16() { - if (xStream->readBytes(aSequence, 2) != 2) + if (mpByteReader->readSomeBytes(maBuffer.data(), 2) != 2) return 0; - pSequence = aSequence.getConstArray(); return static_cast <sal_uInt16> - ( (pSequence[0] & 0xFF) - | (pSequence[1] & 0xFF) << 8); + ( (maBuffer[0] & 0xFF) + | (maBuffer[1] & 0xFF) << 8); } sal_uInt32 ByteGrabber::ReadUInt32() { - if (xStream->readBytes(aSequence, 4) != 4) + if (mpByteReader->readSomeBytes(maBuffer.data(), 4) != 4) return 0; - pSequence = aSequence.getConstArray(); return static_cast < sal_uInt32 > - ( (pSequence[0] & 0xFF) - | ( pSequence[1] & 0xFF ) << 8 - | ( pSequence[2] & 0xFF ) << 16 - | ( pSequence[3] & 0xFF ) << 24 ); + ( (maBuffer[0] & 0xFF) + | ( maBuffer[1] & 0xFF ) << 8 + | ( maBuffer[2] & 0xFF ) << 16 + | ( maBuffer[3] & 0xFF ) << 24 ); } sal_uInt64 ByteGrabber::ReadUInt64() { - if (xStream->readBytes(aSequence, 8) != 8) + if (mpByteReader->readSomeBytes(maBuffer.data(), 8) != 8) return 0; - pSequence = aSequence.getConstArray(); - return static_cast<sal_uInt64>(pSequence[0] & 0xFF) - | static_cast<sal_uInt64>(pSequence[1] & 0xFF) << 8 - | static_cast<sal_uInt64>(pSequence[2] & 0xFF) << 16 - | static_cast<sal_uInt64>(pSequence[3] & 0xFF) << 24 - | static_cast<sal_uInt64>(pSequence[4] & 0xFF) << 32 - | static_cast<sal_uInt64>(pSequence[5] & 0xFF) << 40 - | static_cast<sal_uInt64>(pSequence[6] & 0xFF) << 48 - | static_cast<sal_uInt64>(pSequence[7] & 0xFF) << 56; + return static_cast<sal_uInt64>(maBuffer[0] & 0xFF) + | static_cast<sal_uInt64>(maBuffer[1] & 0xFF) << 8 + | static_cast<sal_uInt64>(maBuffer[2] & 0xFF) << 16 + | static_cast<sal_uInt64>(maBuffer[3] & 0xFF) << 24 + | static_cast<sal_uInt64>(maBuffer[4] & 0xFF) << 32 + | static_cast<sal_uInt64>(maBuffer[5] & 0xFF) << 40 + | static_cast<sal_uInt64>(maBuffer[6] & 0xFF) << 48 + | static_cast<sal_uInt64>(maBuffer[7] & 0xFF) << 56; } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |