<commit_before>#include "WPXSvStream.h"

#include <tools/stream.hxx>
#include <unotools/streamwrap.hxx>
#include <unotools/ucbstreamhelper.hxx>

#ifndef _COM_SUN_STAR_IO_XINPUTSTREAM_H_
#include <com/sun/star/io/XSeekable.hpp>
#endif

using namespace ::com::sun::star::uno;
using namespace ::com::sun::star::io;

WPXSvInputStream::WPXSvInputStream( Reference< XInputStream > xStream ) :
        WPXInputStream(true),
        mxChildStorage(),
        mxChildStream(),
        mxStream(xStream),
        mnOffset(0)
{
    Reference < XSeekable> xSeekable = Reference < XSeekable > (xStream, UNO_QUERY);
    if (!xSeekable.is())
        mnLength = 0;
    else
        mnLength = xSeekable->getLength(); // exception
}

WPXSvInputStream::~WPXSvInputStream()
{
}

const uint8_t * WPXSvInputStream::read(size_t numBytes)
{
    // FIXME: assume no short reads (?)
    mnOffset += mxStream->readBytes (maData, numBytes);
    return (const uint8_t *)maData.getConstArray();
}

int WPXSvInputStream::seek(long offset, WPX_SEEK_TYPE seekType)
{
    if (seekType == WPX_SEEK_CUR && offset >= 0)
    {
            mxStream->skipBytes (offset); // exception ?
            mnOffset += offset;
            return FALSE;
    }
    Reference < XSeekable> xSeekable = Reference < XSeekable >(mxStream, UNO_QUERY);

    if (!xSeekable.is())
            return TRUE;

    if (seekType == WPX_SEEK_CUR)
            mnOffset += offset;
    else
            mnOffset = offset;

    xSeekable->seek(mnOffset); // FIXME: catch exception!

    return FALSE;
}

long WPXSvInputStream::tell()
{
    return mnOffset;
}

bool WPXSvInputStream::atEOS()
{
    return mnOffset >= mnLength;
}

bool WPXSvInputStream::isOLEStream()
{
    bool bAns;

    SvStream *pStream = utl::UcbStreamHelper::CreateStream( mxStream );
    bAns = pStream && SotStorage::IsOLEStorage( pStream );
    delete pStream;

    seek (0, WPX_SEEK_SET);

    return bAns;
}

WPXInputStream * WPXSvInputStream::getDocumentOLEStream()
{
    SvStream *pStream = utl::UcbStreamHelper::CreateStream( mxStream );

    mxChildStorage = new SotStorage( pStream, TRUE );

    mxChildStream = mxChildStorage->OpenSotStream(
            rtl::OUString::createFromAscii( "PerfectOffice_MAIN" ),
            STREAM_STD_READ );

    Reference < XInputStream > xContents = new utl::OInputStreamWrapper( mxChildStream );
    if (xContents.is())
        return new WPXSvInputStream( xContents );
    else
        return NULL;
}<commit_msg>INTEGRATION: CWS libwpdupgrade (1.3.2); FILE MERGED 2005/02/08 15:27:59 rene 1.3.2.2: fix OLE docs (thanks mmeeks@) 2005/02/02 20:44:46 rene 1.3.2.1: upgrade writerperfect to new libwpd API and implement --with-system-libwpd. Remove old libwpd/ stuff, tarball will come when the actual release happened :-)<commit_after>#include "WPXSvStream.h"

#include <tools/stream.hxx>
#include <unotools/streamwrap.hxx>
#include <unotools/ucbstreamhelper.hxx>

#ifndef _COM_SUN_STAR_IO_XINPUTSTREAM_H_
#include <com/sun/star/io/XSeekable.hpp>
#endif

using namespace ::com::sun::star::uno;
using namespace ::com::sun::star::io;

WPXSvInputStream::WPXSvInputStream( Reference< XInputStream > xStream ) :
        WPXInputStream(true),
        mxChildStorage(),
        mxChildStream(),
        mxStream(xStream),
        mnOffset(0)
{
    Reference < XSeekable> xSeekable = Reference < XSeekable > (xStream, UNO_QUERY);
    if (!xSeekable.is())
        mnLength = 0;
    else
        mnLength = xSeekable->getLength(); // exception
}

WPXSvInputStream::~WPXSvInputStream()
{
}

const uint8_t * WPXSvInputStream::read(size_t numBytes, size_t &numBytesRead)
{
    // FIXME: assume no short reads (?)
    sal_Int64 oldMnOffset = mnOffset;
    mnOffset += mxStream->readBytes (maData, numBytes);
    numBytesRead = mnOffset - oldMnOffset;
    return (const uint8_t *)maData.getConstArray();
}

int WPXSvInputStream::seek(long offset, WPX_SEEK_TYPE seekType)
{
    if (seekType == WPX_SEEK_CUR && offset >= 0)
    {
            mxStream->skipBytes (offset); // exception ?
            mnOffset += offset;
            return FALSE;
    }
    Reference < XSeekable> xSeekable = Reference < XSeekable >(mxStream, UNO_QUERY);

    if (!xSeekable.is())
            return TRUE;

    if (seekType == WPX_SEEK_CUR)
            mnOffset += offset;
    else
            mnOffset = offset;

    xSeekable->seek(mnOffset); // FIXME: catch exception!

    return FALSE;
}

long WPXSvInputStream::tell()
{
    return mnOffset;
}

bool WPXSvInputStream::atEOS()
{
    return mnOffset >= mnLength;
}

bool WPXSvInputStream::isOLEStream()
{
    bool bAns;

    SvStream *pStream = utl::UcbStreamHelper::CreateStream( mxStream );
    bAns = pStream && SotStorage::IsOLEStorage( pStream );
    delete pStream;

    seek (0, WPX_SEEK_SET);

    return bAns;
}

WPXInputStream * WPXSvInputStream::getDocumentOLEStream()
{
    SvStream *pStream = utl::UcbStreamHelper::CreateStream( mxStream );

    mxChildStorage = new SotStorage( pStream, TRUE );

    mxChildStream = mxChildStorage->OpenSotStream(
            rtl::OUString::createFromAscii( "PerfectOffice_MAIN" ),
            STREAM_STD_READ );

    Reference < XInputStream > xContents = new utl::OSeekableInputStreamWrapper( mxChildStream );
    if (xContents.is())
        return new WPXSvInputStream( xContents );
    else
        return NULL;
}
{'fraction_non_alphanumeric': 0.11899399399399399, 'fraction_numerical': 0.009947447447447447, 'mean_word_length': 3.448247078464107, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 37, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '923351', 'n_tokens_mistral': 1861, 'n_tokens_neox': 1794, 'n_words': 372}