1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir package complex.loadAllDocuments; 28*cdf0e10cSrcweir 29*cdf0e10cSrcweir import com.sun.star.uno.UnoRuntime; 30*cdf0e10cSrcweir import com.sun.star.ucb.XSimpleFileAccess; 31*cdf0e10cSrcweir import com.sun.star.lang.XMultiServiceFactory; 32*cdf0e10cSrcweir 33*cdf0e10cSrcweir /** 34*cdf0e10cSrcweir * Simulates an input and output stream and 35*cdf0e10cSrcweir * implements the interfaces XInputStream, XOutputStream. 36*cdf0e10cSrcweir * So it can be used for testing loading/saving of documents 37*cdf0e10cSrcweir * using streams instead of URLs. 38*cdf0e10cSrcweir */ 39*cdf0e10cSrcweir public class StreamSimulator implements com.sun.star.io.XInputStream , 40*cdf0e10cSrcweir com.sun.star.io.XOutputStream , 41*cdf0e10cSrcweir com.sun.star.io.XSeekable 42*cdf0e10cSrcweir { 43*cdf0e10cSrcweir //_________________________________ 44*cdf0e10cSrcweir /** 45*cdf0e10cSrcweir * @member m_sFileName name of the corrsponding file on disk 46*cdf0e10cSrcweir * @member m_xInStream the internal input stream for reading 47*cdf0e10cSrcweir * @member m_xOutStream the internal input stream for writing 48*cdf0e10cSrcweir * @member m_xSeek points at runtime to m_xInStream or m_xOutStream and make it seekable 49*cdf0e10cSrcweir * 50*cdf0e10cSrcweir * @member m_bInWasUsed indicates, that the input stream interface was used 51*cdf0e10cSrcweir * @member m_bOutWasUsed indicates, that the output stream interface was used 52*cdf0e10cSrcweir */ 53*cdf0e10cSrcweir 54*cdf0e10cSrcweir private String m_sFileName ; 55*cdf0e10cSrcweir private com.sun.star.io.XInputStream m_xInStream ; 56*cdf0e10cSrcweir private com.sun.star.io.XOutputStream m_xOutStream ; 57*cdf0e10cSrcweir private com.sun.star.io.XSeekable m_xSeek ; 58*cdf0e10cSrcweir 59*cdf0e10cSrcweir public boolean m_bInWasUsed ; 60*cdf0e10cSrcweir public boolean m_bOutWasUsed ; 61*cdf0e10cSrcweir 62*cdf0e10cSrcweir /** 63*cdf0e10cSrcweir * construct a new instance of this class 64*cdf0e10cSrcweir * It set the name of the correspojnding file on disk, which 65*cdf0e10cSrcweir * should be source or target for the following operations on 66*cdf0e10cSrcweir * this object. And it regulate if it should function as 67*cdf0e10cSrcweir * input or output stream. 68*cdf0e10cSrcweir * 69*cdf0e10cSrcweir * @param sFileName 70*cdf0e10cSrcweir * name of the file on disk 71*cdf0e10cSrcweir * Will be used as source (if param bInput==true) 72*cdf0e10cSrcweir * or as target (if param bInput==false). 73*cdf0e10cSrcweir * 74*cdf0e10cSrcweir * @param bInput 75*cdf0e10cSrcweir * it specify, which interface should work at this object. 76*cdf0e10cSrcweir * <TRUE/> => we simulate an input stream 77*cdf0e10cSrcweir * <FALSE/> => we simulate an output stream 78*cdf0e10cSrcweir * 79*cdf0e10cSrcweir * @throw com.sun.star.io.NotConnectedException 80*cdf0e10cSrcweir * in case the internal streams to the file on disk couldn't 81*cdf0e10cSrcweir * be established. 82*cdf0e10cSrcweir * They are neccessary. Otherwhise this simulator can't 83*cdf0e10cSrcweir * really work. 84*cdf0e10cSrcweir */ 85*cdf0e10cSrcweir public StreamSimulator(XMultiServiceFactory xMSF, 86*cdf0e10cSrcweir String sFileName, boolean bInput) 87*cdf0e10cSrcweir throws com.sun.star.io.NotConnectedException 88*cdf0e10cSrcweir { 89*cdf0e10cSrcweir m_sFileName = sFileName ; 90*cdf0e10cSrcweir m_bInWasUsed = false ; 91*cdf0e10cSrcweir m_bOutWasUsed = false ; 92*cdf0e10cSrcweir 93*cdf0e10cSrcweir try 94*cdf0e10cSrcweir { 95*cdf0e10cSrcweir XSimpleFileAccess xHelper = (XSimpleFileAccess) 96*cdf0e10cSrcweir UnoRuntime.queryInterface(XSimpleFileAccess.class, 97*cdf0e10cSrcweir xMSF.createInstance("com.sun.star.ucb.SimpleFileAccess")); 98*cdf0e10cSrcweir 99*cdf0e10cSrcweir if (xHelper == null) 100*cdf0e10cSrcweir throw new com.sun.star.io.NotConnectedException( 101*cdf0e10cSrcweir "ucb helper not available. Can't create streams."); 102*cdf0e10cSrcweir 103*cdf0e10cSrcweir if (bInput) 104*cdf0e10cSrcweir { 105*cdf0e10cSrcweir m_xInStream = xHelper.openFileRead(m_sFileName); 106*cdf0e10cSrcweir m_xSeek = (com.sun.star.io.XSeekable)UnoRuntime.queryInterface( 107*cdf0e10cSrcweir com.sun.star.io.XSeekable.class, 108*cdf0e10cSrcweir m_xInStream); 109*cdf0e10cSrcweir } 110*cdf0e10cSrcweir else 111*cdf0e10cSrcweir { 112*cdf0e10cSrcweir m_xOutStream = xHelper.openFileWrite(m_sFileName); 113*cdf0e10cSrcweir m_xSeek = (com.sun.star.io.XSeekable)UnoRuntime.queryInterface( 114*cdf0e10cSrcweir com.sun.star.io.XSeekable.class, 115*cdf0e10cSrcweir m_xOutStream); 116*cdf0e10cSrcweir } 117*cdf0e10cSrcweir } 118*cdf0e10cSrcweir catch(com.sun.star.uno.Exception exUno) 119*cdf0e10cSrcweir { 120*cdf0e10cSrcweir throw new com.sun.star.io.NotConnectedException( 121*cdf0e10cSrcweir "Could not open the file."); 122*cdf0e10cSrcweir } 123*cdf0e10cSrcweir } 124*cdf0e10cSrcweir 125*cdf0e10cSrcweir /** 126*cdf0e10cSrcweir * following methods simulates the XInputStream. 127*cdf0e10cSrcweir * The notice all actions inside the internal protocol 128*cdf0e10cSrcweir * and try to map all neccessary functions to the internal 129*cdf0e10cSrcweir * open in-stream. 130*cdf0e10cSrcweir */ 131*cdf0e10cSrcweir public int readBytes(byte[][] lData, int nBytesToRead ) 132*cdf0e10cSrcweir throws com.sun.star.io.NotConnectedException, 133*cdf0e10cSrcweir com.sun.star.io.BufferSizeExceededException, 134*cdf0e10cSrcweir com.sun.star.io.IOException 135*cdf0e10cSrcweir { 136*cdf0e10cSrcweir m_bInWasUsed = true; 137*cdf0e10cSrcweir 138*cdf0e10cSrcweir if (m_xInStream == null) 139*cdf0e10cSrcweir { 140*cdf0e10cSrcweir throw new com.sun.star.io.NotConnectedException("stream not open"); 141*cdf0e10cSrcweir } 142*cdf0e10cSrcweir 143*cdf0e10cSrcweir int nRead = 0; 144*cdf0e10cSrcweir try 145*cdf0e10cSrcweir { 146*cdf0e10cSrcweir nRead = m_xInStream.readBytes(lData,nBytesToRead); 147*cdf0e10cSrcweir } 148*cdf0e10cSrcweir catch (com.sun.star.io.NotConnectedException exConnect) { 149*cdf0e10cSrcweir } 150*cdf0e10cSrcweir catch (com.sun.star.io.BufferSizeExceededException exBuffer ) { 151*cdf0e10cSrcweir } 152*cdf0e10cSrcweir catch (com.sun.star.io.IOException exIO ) { 153*cdf0e10cSrcweir } 154*cdf0e10cSrcweir catch (com.sun.star.uno.RuntimeException exRuntime) { 155*cdf0e10cSrcweir } 156*cdf0e10cSrcweir catch (com.sun.star.uno.Exception exUno ) { 157*cdf0e10cSrcweir } 158*cdf0e10cSrcweir 159*cdf0e10cSrcweir 160*cdf0e10cSrcweir return nRead; 161*cdf0e10cSrcweir } 162*cdf0e10cSrcweir 163*cdf0e10cSrcweir public int readSomeBytes(byte[][] lData, int nMaxBytesToRead) 164*cdf0e10cSrcweir throws com.sun.star.io.NotConnectedException, 165*cdf0e10cSrcweir com.sun.star.io.BufferSizeExceededException , 166*cdf0e10cSrcweir com.sun.star.io.IOException 167*cdf0e10cSrcweir { 168*cdf0e10cSrcweir m_bInWasUsed = true; 169*cdf0e10cSrcweir 170*cdf0e10cSrcweir if (m_xInStream == null) 171*cdf0e10cSrcweir { 172*cdf0e10cSrcweir throw new com.sun.star.io.NotConnectedException("stream not open"); 173*cdf0e10cSrcweir } 174*cdf0e10cSrcweir 175*cdf0e10cSrcweir int nRead = 0; 176*cdf0e10cSrcweir try 177*cdf0e10cSrcweir { 178*cdf0e10cSrcweir nRead = m_xInStream.readSomeBytes(lData,nMaxBytesToRead); 179*cdf0e10cSrcweir } 180*cdf0e10cSrcweir catch (com.sun.star.io.NotConnectedException exConnect) { 181*cdf0e10cSrcweir } 182*cdf0e10cSrcweir catch (com.sun.star.io.BufferSizeExceededException exBuffer ) { 183*cdf0e10cSrcweir } 184*cdf0e10cSrcweir catch (com.sun.star.io.IOException exIO ) { 185*cdf0e10cSrcweir } 186*cdf0e10cSrcweir catch (com.sun.star.uno.RuntimeException exRuntime) { 187*cdf0e10cSrcweir } 188*cdf0e10cSrcweir catch (com.sun.star.uno.Exception exUno ) { 189*cdf0e10cSrcweir } 190*cdf0e10cSrcweir 191*cdf0e10cSrcweir return nRead; 192*cdf0e10cSrcweir } 193*cdf0e10cSrcweir 194*cdf0e10cSrcweir //_________________________________ 195*cdf0e10cSrcweir 196*cdf0e10cSrcweir public void skipBytes(int nBytesToSkip) 197*cdf0e10cSrcweir throws com.sun.star.io.NotConnectedException, 198*cdf0e10cSrcweir com.sun.star.io.BufferSizeExceededException , 199*cdf0e10cSrcweir com.sun.star.io.IOException 200*cdf0e10cSrcweir { 201*cdf0e10cSrcweir m_bInWasUsed = true; 202*cdf0e10cSrcweir 203*cdf0e10cSrcweir if (m_xInStream == null) 204*cdf0e10cSrcweir { 205*cdf0e10cSrcweir throw new com.sun.star.io.NotConnectedException("stream not open"); 206*cdf0e10cSrcweir } 207*cdf0e10cSrcweir 208*cdf0e10cSrcweir try 209*cdf0e10cSrcweir { 210*cdf0e10cSrcweir m_xInStream.skipBytes(nBytesToSkip); 211*cdf0e10cSrcweir } 212*cdf0e10cSrcweir catch (com.sun.star.io.NotConnectedException exConnect) { 213*cdf0e10cSrcweir } 214*cdf0e10cSrcweir catch (com.sun.star.io.BufferSizeExceededException exBuffer ) { 215*cdf0e10cSrcweir } 216*cdf0e10cSrcweir catch (com.sun.star.io.IOException exIO ) { 217*cdf0e10cSrcweir } 218*cdf0e10cSrcweir catch (com.sun.star.uno.RuntimeException exRuntime) { 219*cdf0e10cSrcweir } 220*cdf0e10cSrcweir catch (com.sun.star.uno.Exception exUno ) { 221*cdf0e10cSrcweir } 222*cdf0e10cSrcweir 223*cdf0e10cSrcweir } 224*cdf0e10cSrcweir 225*cdf0e10cSrcweir public int available() throws com.sun.star.io.NotConnectedException, 226*cdf0e10cSrcweir com.sun.star.io.IOException 227*cdf0e10cSrcweir { 228*cdf0e10cSrcweir m_bInWasUsed = true; 229*cdf0e10cSrcweir 230*cdf0e10cSrcweir if (m_xInStream == null) 231*cdf0e10cSrcweir { 232*cdf0e10cSrcweir throw new com.sun.star.io.NotConnectedException("stream not open"); 233*cdf0e10cSrcweir } 234*cdf0e10cSrcweir 235*cdf0e10cSrcweir int nAvailable = 0; 236*cdf0e10cSrcweir try 237*cdf0e10cSrcweir { 238*cdf0e10cSrcweir nAvailable = m_xInStream.available(); 239*cdf0e10cSrcweir } 240*cdf0e10cSrcweir catch (com.sun.star.io.NotConnectedException exConnect) { 241*cdf0e10cSrcweir } 242*cdf0e10cSrcweir catch (com.sun.star.io.IOException exIO ) { 243*cdf0e10cSrcweir } 244*cdf0e10cSrcweir catch (com.sun.star.uno.RuntimeException exRuntime) { 245*cdf0e10cSrcweir } 246*cdf0e10cSrcweir catch (com.sun.star.uno.Exception exUno ) { 247*cdf0e10cSrcweir } 248*cdf0e10cSrcweir 249*cdf0e10cSrcweir return nAvailable; 250*cdf0e10cSrcweir } 251*cdf0e10cSrcweir 252*cdf0e10cSrcweir //_________________________________ 253*cdf0e10cSrcweir 254*cdf0e10cSrcweir public void closeInput() throws com.sun.star.io.NotConnectedException, 255*cdf0e10cSrcweir com.sun.star.io.IOException 256*cdf0e10cSrcweir { 257*cdf0e10cSrcweir m_bInWasUsed = true; 258*cdf0e10cSrcweir 259*cdf0e10cSrcweir if (m_xInStream == null) 260*cdf0e10cSrcweir { 261*cdf0e10cSrcweir throw new com.sun.star.io.NotConnectedException("stream not open"); 262*cdf0e10cSrcweir } 263*cdf0e10cSrcweir 264*cdf0e10cSrcweir try 265*cdf0e10cSrcweir { 266*cdf0e10cSrcweir m_xInStream.closeInput(); 267*cdf0e10cSrcweir } 268*cdf0e10cSrcweir catch (com.sun.star.io.NotConnectedException exConnect) { 269*cdf0e10cSrcweir } 270*cdf0e10cSrcweir catch (com.sun.star.io.IOException exIO ) { 271*cdf0e10cSrcweir } 272*cdf0e10cSrcweir catch (com.sun.star.uno.RuntimeException exRuntime) { 273*cdf0e10cSrcweir } 274*cdf0e10cSrcweir catch (com.sun.star.uno.Exception exUno ) { 275*cdf0e10cSrcweir } 276*cdf0e10cSrcweir 277*cdf0e10cSrcweir } 278*cdf0e10cSrcweir 279*cdf0e10cSrcweir /** 280*cdf0e10cSrcweir * following methods simulates the XOutputStream. 281*cdf0e10cSrcweir * The notice all actions inside the internal protocol 282*cdf0e10cSrcweir * and try to map all neccessary functions to the internal 283*cdf0e10cSrcweir * open out-stream. 284*cdf0e10cSrcweir */ 285*cdf0e10cSrcweir public void writeBytes(byte[] lData) 286*cdf0e10cSrcweir throws com.sun.star.io.NotConnectedException, 287*cdf0e10cSrcweir com.sun.star.io.BufferSizeExceededException , 288*cdf0e10cSrcweir com.sun.star.io.IOException 289*cdf0e10cSrcweir { 290*cdf0e10cSrcweir m_bOutWasUsed = true; 291*cdf0e10cSrcweir 292*cdf0e10cSrcweir if (m_xOutStream == null) 293*cdf0e10cSrcweir { 294*cdf0e10cSrcweir throw new com.sun.star.io.NotConnectedException("stream not open"); 295*cdf0e10cSrcweir } 296*cdf0e10cSrcweir 297*cdf0e10cSrcweir try 298*cdf0e10cSrcweir { 299*cdf0e10cSrcweir m_xOutStream.writeBytes(lData); 300*cdf0e10cSrcweir } 301*cdf0e10cSrcweir catch (com.sun.star.io.NotConnectedException exConnect) { 302*cdf0e10cSrcweir } 303*cdf0e10cSrcweir catch (com.sun.star.io.BufferSizeExceededException exBuffer ) { 304*cdf0e10cSrcweir } 305*cdf0e10cSrcweir catch (com.sun.star.io.IOException exIO ) { 306*cdf0e10cSrcweir } 307*cdf0e10cSrcweir catch (com.sun.star.uno.RuntimeException exRuntime) { 308*cdf0e10cSrcweir } 309*cdf0e10cSrcweir catch (com.sun.star.uno.Exception exUno ) { 310*cdf0e10cSrcweir } 311*cdf0e10cSrcweir 312*cdf0e10cSrcweir } 313*cdf0e10cSrcweir 314*cdf0e10cSrcweir //_________________________________ 315*cdf0e10cSrcweir 316*cdf0e10cSrcweir public void flush() throws com.sun.star.io.NotConnectedException , 317*cdf0e10cSrcweir com.sun.star.io.BufferSizeExceededException , 318*cdf0e10cSrcweir com.sun.star.io.IOException 319*cdf0e10cSrcweir { 320*cdf0e10cSrcweir m_bOutWasUsed = true; 321*cdf0e10cSrcweir 322*cdf0e10cSrcweir if (m_xOutStream == null) 323*cdf0e10cSrcweir { 324*cdf0e10cSrcweir throw new com.sun.star.io.NotConnectedException("stream not open"); 325*cdf0e10cSrcweir } 326*cdf0e10cSrcweir 327*cdf0e10cSrcweir try 328*cdf0e10cSrcweir { 329*cdf0e10cSrcweir m_xOutStream.flush(); 330*cdf0e10cSrcweir } 331*cdf0e10cSrcweir catch (com.sun.star.io.NotConnectedException exConnect) { 332*cdf0e10cSrcweir } 333*cdf0e10cSrcweir catch (com.sun.star.io.BufferSizeExceededException exBuffer ) { 334*cdf0e10cSrcweir } 335*cdf0e10cSrcweir catch (com.sun.star.io.IOException exIO ) { 336*cdf0e10cSrcweir } 337*cdf0e10cSrcweir catch (com.sun.star.uno.RuntimeException exRuntime) { 338*cdf0e10cSrcweir } 339*cdf0e10cSrcweir catch (com.sun.star.uno.Exception exUno ) { 340*cdf0e10cSrcweir } 341*cdf0e10cSrcweir } 342*cdf0e10cSrcweir 343*cdf0e10cSrcweir //_________________________________ 344*cdf0e10cSrcweir 345*cdf0e10cSrcweir public void closeOutput() throws com.sun.star.io.NotConnectedException , 346*cdf0e10cSrcweir com.sun.star.io.BufferSizeExceededException, 347*cdf0e10cSrcweir com.sun.star.io.IOException 348*cdf0e10cSrcweir { 349*cdf0e10cSrcweir m_bOutWasUsed = true; 350*cdf0e10cSrcweir 351*cdf0e10cSrcweir if (m_xOutStream == null) 352*cdf0e10cSrcweir { 353*cdf0e10cSrcweir throw new com.sun.star.io.NotConnectedException("stream not open"); 354*cdf0e10cSrcweir } 355*cdf0e10cSrcweir 356*cdf0e10cSrcweir try 357*cdf0e10cSrcweir { 358*cdf0e10cSrcweir m_xOutStream.closeOutput(); 359*cdf0e10cSrcweir } 360*cdf0e10cSrcweir catch (com.sun.star.io.NotConnectedException exConnect) { 361*cdf0e10cSrcweir } 362*cdf0e10cSrcweir catch (com.sun.star.io.BufferSizeExceededException exBuffer ) { 363*cdf0e10cSrcweir } 364*cdf0e10cSrcweir catch (com.sun.star.io.IOException exIO ) { 365*cdf0e10cSrcweir } 366*cdf0e10cSrcweir catch (com.sun.star.uno.RuntimeException exRuntime) { 367*cdf0e10cSrcweir } 368*cdf0e10cSrcweir catch (com.sun.star.uno.Exception exUno ) { 369*cdf0e10cSrcweir } 370*cdf0e10cSrcweir 371*cdf0e10cSrcweir } 372*cdf0e10cSrcweir 373*cdf0e10cSrcweir /** 374*cdf0e10cSrcweir * following methods simulates the XSeekable. 375*cdf0e10cSrcweir * The notice all actions inside the internal protocol 376*cdf0e10cSrcweir * and try to map all neccessary functions to the internal 377*cdf0e10cSrcweir * open stream. 378*cdf0e10cSrcweir */ 379*cdf0e10cSrcweir public void seek(long nLocation ) 380*cdf0e10cSrcweir throws com.sun.star.lang.IllegalArgumentException, 381*cdf0e10cSrcweir com.sun.star.io.IOException 382*cdf0e10cSrcweir { 383*cdf0e10cSrcweir if (m_xInStream != null) 384*cdf0e10cSrcweir m_bInWasUsed = true; 385*cdf0e10cSrcweir else 386*cdf0e10cSrcweir if (m_xOutStream != null) 387*cdf0e10cSrcweir m_bOutWasUsed = true; 388*cdf0e10cSrcweir // else 389*cdf0e10cSrcweir //m_aProtocol.log("\tno stream open!\n"); 390*cdf0e10cSrcweir 391*cdf0e10cSrcweir if (m_xSeek == null) 392*cdf0e10cSrcweir { 393*cdf0e10cSrcweir throw new com.sun.star.io.IOException("stream not seekable"); 394*cdf0e10cSrcweir } 395*cdf0e10cSrcweir 396*cdf0e10cSrcweir try 397*cdf0e10cSrcweir { 398*cdf0e10cSrcweir m_xSeek.seek(nLocation); 399*cdf0e10cSrcweir } 400*cdf0e10cSrcweir catch (com.sun.star.lang.IllegalArgumentException exArg ) { 401*cdf0e10cSrcweir } 402*cdf0e10cSrcweir catch (com.sun.star.io.IOException exIO ) { 403*cdf0e10cSrcweir } 404*cdf0e10cSrcweir catch (com.sun.star.uno.RuntimeException exRuntime) { 405*cdf0e10cSrcweir } 406*cdf0e10cSrcweir catch (com.sun.star.uno.Exception exUno ) { 407*cdf0e10cSrcweir } 408*cdf0e10cSrcweir 409*cdf0e10cSrcweir } 410*cdf0e10cSrcweir 411*cdf0e10cSrcweir public long getPosition() throws com.sun.star.io.IOException 412*cdf0e10cSrcweir { 413*cdf0e10cSrcweir 414*cdf0e10cSrcweir if (m_xInStream != null) 415*cdf0e10cSrcweir m_bInWasUsed = true; 416*cdf0e10cSrcweir else 417*cdf0e10cSrcweir if (m_xOutStream != null) 418*cdf0e10cSrcweir m_bOutWasUsed = true; 419*cdf0e10cSrcweir // else 420*cdf0e10cSrcweir //m_aProtocol.log("\tno stream open!\n"); 421*cdf0e10cSrcweir 422*cdf0e10cSrcweir if (m_xSeek == null) 423*cdf0e10cSrcweir { 424*cdf0e10cSrcweir throw new com.sun.star.io.IOException("stream not seekable"); 425*cdf0e10cSrcweir } 426*cdf0e10cSrcweir 427*cdf0e10cSrcweir long nPos = 0; 428*cdf0e10cSrcweir try 429*cdf0e10cSrcweir { 430*cdf0e10cSrcweir nPos = m_xSeek.getPosition(); 431*cdf0e10cSrcweir } 432*cdf0e10cSrcweir catch (com.sun.star.io.IOException exIO ) { 433*cdf0e10cSrcweir } 434*cdf0e10cSrcweir catch (com.sun.star.uno.RuntimeException exRuntime) { 435*cdf0e10cSrcweir } 436*cdf0e10cSrcweir catch (com.sun.star.uno.Exception exUno ) { 437*cdf0e10cSrcweir } 438*cdf0e10cSrcweir 439*cdf0e10cSrcweir return nPos; 440*cdf0e10cSrcweir } 441*cdf0e10cSrcweir 442*cdf0e10cSrcweir //_________________________________ 443*cdf0e10cSrcweir 444*cdf0e10cSrcweir public long getLength() throws com.sun.star.io.IOException 445*cdf0e10cSrcweir { 446*cdf0e10cSrcweir 447*cdf0e10cSrcweir if (m_xInStream != null) 448*cdf0e10cSrcweir m_bInWasUsed = true; 449*cdf0e10cSrcweir else 450*cdf0e10cSrcweir if (m_xOutStream != null) 451*cdf0e10cSrcweir m_bOutWasUsed = true; 452*cdf0e10cSrcweir // else 453*cdf0e10cSrcweir //m_aProtocol.log("\tno stream open!\n"); 454*cdf0e10cSrcweir 455*cdf0e10cSrcweir if (m_xSeek == null) 456*cdf0e10cSrcweir { 457*cdf0e10cSrcweir throw new com.sun.star.io.IOException("stream not seekable"); 458*cdf0e10cSrcweir } 459*cdf0e10cSrcweir 460*cdf0e10cSrcweir long nLen = 0; 461*cdf0e10cSrcweir try 462*cdf0e10cSrcweir { 463*cdf0e10cSrcweir nLen = m_xSeek.getLength(); 464*cdf0e10cSrcweir } 465*cdf0e10cSrcweir catch (com.sun.star.io.IOException exIO ) { 466*cdf0e10cSrcweir } 467*cdf0e10cSrcweir catch (com.sun.star.uno.RuntimeException exRuntime) { 468*cdf0e10cSrcweir } 469*cdf0e10cSrcweir catch (com.sun.star.uno.Exception exUno ) { 470*cdf0e10cSrcweir } 471*cdf0e10cSrcweir 472*cdf0e10cSrcweir return nLen; 473*cdf0e10cSrcweir } 474*cdf0e10cSrcweir } 475