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 28*cdf0e10cSrcweir package helper; 29*cdf0e10cSrcweir 30*cdf0e10cSrcweir import com.sun.star.uno.UnoRuntime; 31*cdf0e10cSrcweir 32*cdf0e10cSrcweir 33*cdf0e10cSrcweir import com.sun.star.lang.XMultiServiceFactory; 34*cdf0e10cSrcweir import com.sun.star.ucb.XSimpleFileAccess; 35*cdf0e10cSrcweir 36*cdf0e10cSrcweir /** 37*cdf0e10cSrcweir * It simulates an input and output stream and 38*cdf0e10cSrcweir * implements the interfaces XInputStream, XOutputStream. 39*cdf0e10cSrcweir * So it can be used for testing loading/saving of documents 40*cdf0e10cSrcweir * using streams instead of URLs. 41*cdf0e10cSrcweir * 42*cdf0e10cSrcweir */ 43*cdf0e10cSrcweir public class StreamSimulator implements com.sun.star.io.XInputStream , 44*cdf0e10cSrcweir com.sun.star.io.XOutputStream , 45*cdf0e10cSrcweir com.sun.star.io.XSeekable 46*cdf0e10cSrcweir { 47*cdf0e10cSrcweir //_________________________________ 48*cdf0e10cSrcweir /** 49*cdf0e10cSrcweir * @member m_sFileName name of the corrsponding file on disk 50*cdf0e10cSrcweir * @member m_xInStream the internal input stream for reading 51*cdf0e10cSrcweir * @member m_xOutStream the internal input stream for writing 52*cdf0e10cSrcweir * @member m_xSeek points at runtime to m_xInStream or m_xOutStream and make it seekable 53*cdf0e10cSrcweir * 54*cdf0e10cSrcweir * @member //m_aProtocol the external set protocol object for logging messages 55*cdf0e10cSrcweir * @member m_bInWasUsed indicates, that the input stream interface was used 56*cdf0e10cSrcweir * @member m_bOutWasUsed indicates, that the output stream interface was used 57*cdf0e10cSrcweir */ 58*cdf0e10cSrcweir 59*cdf0e10cSrcweir private String m_sFileName ; 60*cdf0e10cSrcweir private com.sun.star.io.XInputStream m_xInStream ; 61*cdf0e10cSrcweir private com.sun.star.io.XOutputStream m_xOutStream ; 62*cdf0e10cSrcweir private com.sun.star.io.XSeekable m_xSeek ; 63*cdf0e10cSrcweir 64*cdf0e10cSrcweir //public ComplexTestEnvironment //m_aProtocol ; 65*cdf0e10cSrcweir public boolean m_bInWasUsed ; 66*cdf0e10cSrcweir public boolean m_bOutWasUsed ; 67*cdf0e10cSrcweir 68*cdf0e10cSrcweir //_________________________________ 69*cdf0e10cSrcweir /** 70*cdf0e10cSrcweir * construct a new instance of this class 71*cdf0e10cSrcweir * It set the name of the correspojnding file on disk, which 72*cdf0e10cSrcweir * should be source or target for the following operations on 73*cdf0e10cSrcweir * this object. And it regulate if it should function as 74*cdf0e10cSrcweir * input or output stream. 75*cdf0e10cSrcweir * 76*cdf0e10cSrcweir * @param sFileName 77*cdf0e10cSrcweir * name of the file on disk 78*cdf0e10cSrcweir * Will be used as source (if param bInput==true) 79*cdf0e10cSrcweir * or as target (if param bInput==false). 80*cdf0e10cSrcweir * 81*cdf0e10cSrcweir * @param bInput 82*cdf0e10cSrcweir * it specify, which interface should work at this object. 83*cdf0e10cSrcweir * <TRUE/> => we simulate an input stream 84*cdf0e10cSrcweir * <FALSE/> => we simulate an output stream 85*cdf0e10cSrcweir * 86*cdf0e10cSrcweir * @throw com.sun.star.io.NotConnectedException 87*cdf0e10cSrcweir * in case the internal streams to the file on disk couldn't established. 88*cdf0e10cSrcweir * They are neccessary. Otherwhise this simulator can't realy work. 89*cdf0e10cSrcweir */ 90*cdf0e10cSrcweir public StreamSimulator( String sFileName , boolean bInput , 91*cdf0e10cSrcweir lib.TestParameters param ) throws com.sun.star.io.NotConnectedException 92*cdf0e10cSrcweir { 93*cdf0e10cSrcweir ////m_aProtocol = new ComplexTestEnvironment(); 94*cdf0e10cSrcweir m_sFileName = sFileName ; 95*cdf0e10cSrcweir m_bInWasUsed = false ; 96*cdf0e10cSrcweir m_bOutWasUsed = false ; 97*cdf0e10cSrcweir 98*cdf0e10cSrcweir try 99*cdf0e10cSrcweir { 100*cdf0e10cSrcweir XSimpleFileAccess xHelper = (XSimpleFileAccess) 101*cdf0e10cSrcweir UnoRuntime.queryInterface(XSimpleFileAccess.class, 102*cdf0e10cSrcweir ((XMultiServiceFactory)param.getMSF()).createInstance("com.sun.star.ucb.SimpleFileAccess")); 103*cdf0e10cSrcweir /* com.sun.star.ucb.XSimpleFileAccess xHelper = (com.sun.star.ucb.XSimpleFileAccess)OfficeConnect.createRemoteInstance( 104*cdf0e10cSrcweir com.sun.star.ucb.XSimpleFileAccess.class, 105*cdf0e10cSrcweir "com.sun.star.ucb.SimpleFileAccess");*/ 106*cdf0e10cSrcweir 107*cdf0e10cSrcweir if (xHelper == null) 108*cdf0e10cSrcweir throw new com.sun.star.io.NotConnectedException("ucb helper not available. Can't create streams."); 109*cdf0e10cSrcweir 110*cdf0e10cSrcweir if (bInput) 111*cdf0e10cSrcweir { 112*cdf0e10cSrcweir m_xInStream = xHelper.openFileRead(m_sFileName); 113*cdf0e10cSrcweir m_xSeek = (com.sun.star.io.XSeekable)UnoRuntime.queryInterface( 114*cdf0e10cSrcweir com.sun.star.io.XSeekable.class, 115*cdf0e10cSrcweir m_xInStream); 116*cdf0e10cSrcweir } 117*cdf0e10cSrcweir else 118*cdf0e10cSrcweir { 119*cdf0e10cSrcweir m_xOutStream = xHelper.openFileWrite(m_sFileName); 120*cdf0e10cSrcweir m_xSeek = (com.sun.star.io.XSeekable)UnoRuntime.queryInterface( 121*cdf0e10cSrcweir com.sun.star.io.XSeekable.class, 122*cdf0e10cSrcweir m_xOutStream); 123*cdf0e10cSrcweir } 124*cdf0e10cSrcweir } 125*cdf0e10cSrcweir catch(com.sun.star.uno.Exception exUno) 126*cdf0e10cSrcweir { 127*cdf0e10cSrcweir ////m_aProtocol.log("\tstream not open. throw NotConnectedException\n\n\tfailed\n}\n"); 128*cdf0e10cSrcweir throw new com.sun.star.io.NotConnectedException("Could not open the file."); 129*cdf0e10cSrcweir } 130*cdf0e10cSrcweir } 131*cdf0e10cSrcweir 132*cdf0e10cSrcweir /* public void finalize() 133*cdf0e10cSrcweir { 134*cdf0e10cSrcweir ////m_aProtocol.log("finalize was called. Please check if it was right or not.\n"); 135*cdf0e10cSrcweir } */ 136*cdf0e10cSrcweir 137*cdf0e10cSrcweir //_________________________________ 138*cdf0e10cSrcweir /** 139*cdf0e10cSrcweir * following methods simulates the XInputStream. 140*cdf0e10cSrcweir * The notice all actions inside the internal protocol 141*cdf0e10cSrcweir * and try to map all neccessary functions to the internal 142*cdf0e10cSrcweir * open in-stream. 143*cdf0e10cSrcweir */ 144*cdf0e10cSrcweir public int readBytes( /*OUT*/ byte[][] lData , 145*cdf0e10cSrcweir /*IN*/ int nBytesToRead ) throws com.sun.star.io.NotConnectedException , 146*cdf0e10cSrcweir com.sun.star.io.BufferSizeExceededException, 147*cdf0e10cSrcweir com.sun.star.io.IOException 148*cdf0e10cSrcweir { 149*cdf0e10cSrcweir //m_aProtocol.log("readBytes(lData["+lData.length+"]["+lData[0]+"],"+nBytesToRead+")\n{\n"); 150*cdf0e10cSrcweir m_bInWasUsed = true; 151*cdf0e10cSrcweir 152*cdf0e10cSrcweir if (m_xInStream == null) 153*cdf0e10cSrcweir { 154*cdf0e10cSrcweir //m_aProtocol.log("\tstream not open. throw NotConnectedException\n\n\tfailed\n}\n"); 155*cdf0e10cSrcweir throw new com.sun.star.io.NotConnectedException("stream not open"); 156*cdf0e10cSrcweir } 157*cdf0e10cSrcweir 158*cdf0e10cSrcweir int nRead = 0; 159*cdf0e10cSrcweir try 160*cdf0e10cSrcweir { 161*cdf0e10cSrcweir nRead = m_xInStream.readBytes(lData,nBytesToRead); 162*cdf0e10cSrcweir } 163*cdf0e10cSrcweir catch (com.sun.star.io.NotConnectedException exConnect) { //m_aProtocol.log("\tgot NotConnectedException\n\tfailed\n}\n" ); throw exConnect; 164*cdf0e10cSrcweir } 165*cdf0e10cSrcweir catch (com.sun.star.io.BufferSizeExceededException exBuffer ) { //m_aProtocol.log("\tgot BufferSizeExceededException\n\tfailed\n}\n"); throw exBuffer; 166*cdf0e10cSrcweir } 167*cdf0e10cSrcweir catch (com.sun.star.io.IOException exIO ) { //m_aProtocol.log("\tgot IOException\n\tfailed\n}\n" ); throw exIO; 168*cdf0e10cSrcweir } 169*cdf0e10cSrcweir catch (com.sun.star.uno.RuntimeException exRuntime) { //m_aProtocol.log("\tgot RuntimeException\n\tfailed\n}\n" ); throw exRuntime; 170*cdf0e10cSrcweir } 171*cdf0e10cSrcweir catch (com.sun.star.uno.Exception exUno ) { //m_aProtocol.log("\tgot Exception\n\tfailed\n}\n" ); 172*cdf0e10cSrcweir } 173*cdf0e10cSrcweir 174*cdf0e10cSrcweir //m_aProtocol.log("\treads "+nRead+" bytes\n\tOK\n}\n"); 175*cdf0e10cSrcweir 176*cdf0e10cSrcweir //if (nRead != nBytesToRead) 177*cdf0e10cSrcweir //m_aProtocol.log("there are some missing bytes for reading!\n"); 178*cdf0e10cSrcweir 179*cdf0e10cSrcweir return nRead; 180*cdf0e10cSrcweir } 181*cdf0e10cSrcweir 182*cdf0e10cSrcweir //_________________________________ 183*cdf0e10cSrcweir 184*cdf0e10cSrcweir public int readSomeBytes( /*OUT*/ byte[][] lData , 185*cdf0e10cSrcweir /*IN*/ int nMaxBytesToRead ) throws com.sun.star.io.NotConnectedException , 186*cdf0e10cSrcweir com.sun.star.io.BufferSizeExceededException , 187*cdf0e10cSrcweir com.sun.star.io.IOException 188*cdf0e10cSrcweir { 189*cdf0e10cSrcweir //m_aProtocol.log("readSomeBytes(lData["+lData.length+"]["+lData[0]+"],"+nMaxBytesToRead+")\n{\n"); 190*cdf0e10cSrcweir m_bInWasUsed = true; 191*cdf0e10cSrcweir 192*cdf0e10cSrcweir if (m_xInStream == null) 193*cdf0e10cSrcweir { 194*cdf0e10cSrcweir //m_aProtocol.log("\tstream not open. throw NotConnectedException\n\tfailed\n}\n"); 195*cdf0e10cSrcweir throw new com.sun.star.io.NotConnectedException("stream not open"); 196*cdf0e10cSrcweir } 197*cdf0e10cSrcweir 198*cdf0e10cSrcweir int nRead = 0; 199*cdf0e10cSrcweir try 200*cdf0e10cSrcweir { 201*cdf0e10cSrcweir nRead = m_xInStream.readSomeBytes(lData,nMaxBytesToRead); 202*cdf0e10cSrcweir } 203*cdf0e10cSrcweir catch (com.sun.star.io.NotConnectedException exConnect) { //m_aProtocol.log("\tgot NotConnectedException\n\tfailed\n}\n" ); throw exConnect; 204*cdf0e10cSrcweir } 205*cdf0e10cSrcweir catch (com.sun.star.io.BufferSizeExceededException exBuffer ) { //m_aProtocol.log("\tgot BufferSizeExceededException\n\tfailed\n}\n"); throw exBuffer; 206*cdf0e10cSrcweir } 207*cdf0e10cSrcweir catch (com.sun.star.io.IOException exIO ) { //m_aProtocol.log("\tgot IOException\n\tfailed\n}\n" ); throw exIO; 208*cdf0e10cSrcweir } 209*cdf0e10cSrcweir catch (com.sun.star.uno.RuntimeException exRuntime) { //m_aProtocol.log("\tgot RuntimeException\n\tfailed\n}\n" ); throw exRuntime; 210*cdf0e10cSrcweir } 211*cdf0e10cSrcweir catch (com.sun.star.uno.Exception exUno ) { //m_aProtocol.log("\tgot Exception\n\tfailed\n}\n" ); 212*cdf0e10cSrcweir } 213*cdf0e10cSrcweir 214*cdf0e10cSrcweir //m_aProtocol.log("\treads "+nRead+" bytes\n\tOK\n}\n"); 215*cdf0e10cSrcweir 216*cdf0e10cSrcweir //if (nRead != nMaxBytesToRead) 217*cdf0e10cSrcweir //m_aProtocol.log("there are some missing bytes for reading!"); 218*cdf0e10cSrcweir 219*cdf0e10cSrcweir return nRead; 220*cdf0e10cSrcweir } 221*cdf0e10cSrcweir 222*cdf0e10cSrcweir //_________________________________ 223*cdf0e10cSrcweir 224*cdf0e10cSrcweir public void skipBytes( /*IN*/ int nBytesToSkip ) throws com.sun.star.io.NotConnectedException , 225*cdf0e10cSrcweir com.sun.star.io.BufferSizeExceededException , 226*cdf0e10cSrcweir com.sun.star.io.IOException 227*cdf0e10cSrcweir { 228*cdf0e10cSrcweir //m_aProtocol.log("skipBytes("+nBytesToSkip+")\n{\n"); 229*cdf0e10cSrcweir m_bInWasUsed = true; 230*cdf0e10cSrcweir 231*cdf0e10cSrcweir if (m_xInStream == null) 232*cdf0e10cSrcweir { 233*cdf0e10cSrcweir //m_aProtocol.log("\tstream not open. throw NotConnectedException\n\tfailed\n}\n"); 234*cdf0e10cSrcweir throw new com.sun.star.io.NotConnectedException("stream not open"); 235*cdf0e10cSrcweir } 236*cdf0e10cSrcweir 237*cdf0e10cSrcweir try 238*cdf0e10cSrcweir { 239*cdf0e10cSrcweir m_xInStream.skipBytes(nBytesToSkip); 240*cdf0e10cSrcweir } 241*cdf0e10cSrcweir catch (com.sun.star.io.NotConnectedException exConnect) { //m_aProtocol.log("\tgot NotConnectedException\n\tfailed\n}\n" ); throw exConnect; 242*cdf0e10cSrcweir } 243*cdf0e10cSrcweir catch (com.sun.star.io.BufferSizeExceededException exBuffer ) { //m_aProtocol.log("\tgot BufferSizeExceededException\n\tfailed\n}\n"); throw exBuffer; 244*cdf0e10cSrcweir } 245*cdf0e10cSrcweir catch (com.sun.star.io.IOException exIO ) { //m_aProtocol.log("\tgot IOException\n\tfailed\n}\n" ); throw exIO; 246*cdf0e10cSrcweir } 247*cdf0e10cSrcweir catch (com.sun.star.uno.RuntimeException exRuntime) { //m_aProtocol.log("\tgot RuntimeException\n\tfailed\n}\n" ); throw exRuntime; 248*cdf0e10cSrcweir } 249*cdf0e10cSrcweir catch (com.sun.star.uno.Exception exUno ) { //m_aProtocol.log("\tgot Exception\n\tfailed\n}\n" ); 250*cdf0e10cSrcweir } 251*cdf0e10cSrcweir 252*cdf0e10cSrcweir //m_aProtocol.log("\tOK\n}\n"); 253*cdf0e10cSrcweir } 254*cdf0e10cSrcweir 255*cdf0e10cSrcweir //_________________________________ 256*cdf0e10cSrcweir 257*cdf0e10cSrcweir public int available() throws com.sun.star.io.NotConnectedException, 258*cdf0e10cSrcweir com.sun.star.io.IOException 259*cdf0e10cSrcweir { 260*cdf0e10cSrcweir //m_aProtocol.log("available()\n{\n"); 261*cdf0e10cSrcweir m_bInWasUsed = true; 262*cdf0e10cSrcweir 263*cdf0e10cSrcweir if (m_xInStream == null) 264*cdf0e10cSrcweir { 265*cdf0e10cSrcweir //m_aProtocol.log("\tstream not open. throw NotConnectedException\n\tfailed\n}\n"); 266*cdf0e10cSrcweir throw new com.sun.star.io.NotConnectedException("stream not open"); 267*cdf0e10cSrcweir } 268*cdf0e10cSrcweir 269*cdf0e10cSrcweir int nAvailable = 0; 270*cdf0e10cSrcweir try 271*cdf0e10cSrcweir { 272*cdf0e10cSrcweir nAvailable = m_xInStream.available(); 273*cdf0e10cSrcweir } 274*cdf0e10cSrcweir catch (com.sun.star.io.NotConnectedException exConnect) { //m_aProtocol.log("\tgot NotConnectedException\n\tfailed\n}\n"); throw exConnect; 275*cdf0e10cSrcweir } 276*cdf0e10cSrcweir catch (com.sun.star.io.IOException exIO ) { //m_aProtocol.log("\tgot IOException\n\tfailed\n}\n" ); throw exIO; 277*cdf0e10cSrcweir } 278*cdf0e10cSrcweir catch (com.sun.star.uno.RuntimeException exRuntime) { //m_aProtocol.log("\tgot RuntimeException\n\tfailed\n}\n" ); throw exRuntime; 279*cdf0e10cSrcweir } 280*cdf0e10cSrcweir catch (com.sun.star.uno.Exception exUno ) { //m_aProtocol.log("\tgot Exception\n\tfailed\n}\n" ); 281*cdf0e10cSrcweir } 282*cdf0e10cSrcweir 283*cdf0e10cSrcweir //m_aProtocol.log("\treturns "+nAvailable+" bytes\n\tOK\n}\n"); 284*cdf0e10cSrcweir return nAvailable; 285*cdf0e10cSrcweir } 286*cdf0e10cSrcweir 287*cdf0e10cSrcweir //_________________________________ 288*cdf0e10cSrcweir 289*cdf0e10cSrcweir public void closeInput() throws com.sun.star.io.NotConnectedException, 290*cdf0e10cSrcweir com.sun.star.io.IOException 291*cdf0e10cSrcweir { 292*cdf0e10cSrcweir //m_aProtocol.log("closeInput()\n{\n"); 293*cdf0e10cSrcweir m_bInWasUsed = true; 294*cdf0e10cSrcweir 295*cdf0e10cSrcweir if (m_xInStream == null) 296*cdf0e10cSrcweir { 297*cdf0e10cSrcweir //m_aProtocol.log("\tstream not open. throw NotConnectedException\n\tfailed\n}\n"); 298*cdf0e10cSrcweir throw new com.sun.star.io.NotConnectedException("stream not open"); 299*cdf0e10cSrcweir } 300*cdf0e10cSrcweir 301*cdf0e10cSrcweir try 302*cdf0e10cSrcweir { 303*cdf0e10cSrcweir m_xInStream.closeInput(); 304*cdf0e10cSrcweir } 305*cdf0e10cSrcweir catch (com.sun.star.io.NotConnectedException exConnect) { //m_aProtocol.log("\tgot NotConnectedException\n\tfailed\n}\n"); throw exConnect; 306*cdf0e10cSrcweir } 307*cdf0e10cSrcweir catch (com.sun.star.io.IOException exIO ) { //m_aProtocol.log("\tgot IOException\n\tfailed\n}\n" ); throw exIO; 308*cdf0e10cSrcweir } 309*cdf0e10cSrcweir catch (com.sun.star.uno.RuntimeException exRuntime) { //m_aProtocol.log("\tgot RuntimeException\n\tfailed\n}\n" ); throw exRuntime; 310*cdf0e10cSrcweir } 311*cdf0e10cSrcweir catch (com.sun.star.uno.Exception exUno ) { //m_aProtocol.log("\tgot Exception\n\tfailed\n}\n" ); 312*cdf0e10cSrcweir } 313*cdf0e10cSrcweir 314*cdf0e10cSrcweir //m_aProtocol.log("\tOK\n}\n"); 315*cdf0e10cSrcweir } 316*cdf0e10cSrcweir 317*cdf0e10cSrcweir //_________________________________ 318*cdf0e10cSrcweir /** 319*cdf0e10cSrcweir * following methods simulates the XOutputStream. 320*cdf0e10cSrcweir * The notice all actions inside the internal protocol 321*cdf0e10cSrcweir * and try to map all neccessary functions to the internal 322*cdf0e10cSrcweir * open out-stream. 323*cdf0e10cSrcweir */ 324*cdf0e10cSrcweir public void writeBytes( /*IN*/byte[] lData ) throws com.sun.star.io.NotConnectedException , 325*cdf0e10cSrcweir com.sun.star.io.BufferSizeExceededException , 326*cdf0e10cSrcweir com.sun.star.io.IOException 327*cdf0e10cSrcweir { 328*cdf0e10cSrcweir //m_aProtocol.log("writeBytes(lData["+lData.length+"])\n{\n"); 329*cdf0e10cSrcweir m_bOutWasUsed = true; 330*cdf0e10cSrcweir 331*cdf0e10cSrcweir if (m_xOutStream == null) 332*cdf0e10cSrcweir { 333*cdf0e10cSrcweir //m_aProtocol.log("\tstream not open. throw NotConnectedException\n\tfailed\n}\n"); 334*cdf0e10cSrcweir throw new com.sun.star.io.NotConnectedException("stream not open"); 335*cdf0e10cSrcweir } 336*cdf0e10cSrcweir 337*cdf0e10cSrcweir try 338*cdf0e10cSrcweir { 339*cdf0e10cSrcweir m_xOutStream.writeBytes(lData); 340*cdf0e10cSrcweir } 341*cdf0e10cSrcweir catch (com.sun.star.io.NotConnectedException exConnect) { //m_aProtocol.log("\tgot NotConnectedException\n\tfailed\n}\n" ); throw exConnect; 342*cdf0e10cSrcweir } 343*cdf0e10cSrcweir catch (com.sun.star.io.BufferSizeExceededException exBuffer ) { //m_aProtocol.log("\tgot BufferSizeExceededException\n\tfailed\n}\n"); throw exBuffer; 344*cdf0e10cSrcweir } 345*cdf0e10cSrcweir catch (com.sun.star.io.IOException exIO ) { //m_aProtocol.log("\tgot IOException\n\tfailed\n}\n" ); throw exIO; 346*cdf0e10cSrcweir } 347*cdf0e10cSrcweir catch (com.sun.star.uno.RuntimeException exRuntime) { //m_aProtocol.log("\tgot RuntimeException\n\tfailed\n}\n" ); throw exRuntime; 348*cdf0e10cSrcweir } 349*cdf0e10cSrcweir catch (com.sun.star.uno.Exception exUno ) { //m_aProtocol.log("\tgot Exception\n\tfailed\n}\n" ); 350*cdf0e10cSrcweir } 351*cdf0e10cSrcweir 352*cdf0e10cSrcweir //m_aProtocol.log("\tOK\n}\n"); 353*cdf0e10cSrcweir } 354*cdf0e10cSrcweir 355*cdf0e10cSrcweir //_________________________________ 356*cdf0e10cSrcweir 357*cdf0e10cSrcweir public void flush() throws com.sun.star.io.NotConnectedException , 358*cdf0e10cSrcweir com.sun.star.io.BufferSizeExceededException , 359*cdf0e10cSrcweir com.sun.star.io.IOException 360*cdf0e10cSrcweir { 361*cdf0e10cSrcweir //m_aProtocol.log("flush()\n{\n"); 362*cdf0e10cSrcweir m_bOutWasUsed = true; 363*cdf0e10cSrcweir 364*cdf0e10cSrcweir if (m_xOutStream == null) 365*cdf0e10cSrcweir { 366*cdf0e10cSrcweir //m_aProtocol.log("\tstream not open. throw NotConnectedException\n\tfailed\n}\n"); 367*cdf0e10cSrcweir throw new com.sun.star.io.NotConnectedException("stream not open"); 368*cdf0e10cSrcweir } 369*cdf0e10cSrcweir 370*cdf0e10cSrcweir try 371*cdf0e10cSrcweir { 372*cdf0e10cSrcweir m_xOutStream.flush(); 373*cdf0e10cSrcweir } 374*cdf0e10cSrcweir catch (com.sun.star.io.NotConnectedException exConnect) { //m_aProtocol.log("\tgot NotConnectedException\n\tfailed\n}\n" ); throw exConnect; 375*cdf0e10cSrcweir } 376*cdf0e10cSrcweir catch (com.sun.star.io.BufferSizeExceededException exBuffer ) { //m_aProtocol.log("\tgot BufferSizeExceededException\n\tfailed\n}\n"); throw exBuffer; 377*cdf0e10cSrcweir } 378*cdf0e10cSrcweir catch (com.sun.star.io.IOException exIO ) { //m_aProtocol.log("\tgot IOException\n\tfailed\n}\n" ); throw exIO; 379*cdf0e10cSrcweir } 380*cdf0e10cSrcweir catch (com.sun.star.uno.RuntimeException exRuntime) { //m_aProtocol.log("\tgot RuntimeException\n\tfailed\n}\n" ); throw exRuntime; 381*cdf0e10cSrcweir } 382*cdf0e10cSrcweir catch (com.sun.star.uno.Exception exUno ) { //m_aProtocol.log("\tgot Exception\n\tfailed\n}\n" ); 383*cdf0e10cSrcweir } 384*cdf0e10cSrcweir //m_aProtocol.log("\tOK\n}\n"); 385*cdf0e10cSrcweir } 386*cdf0e10cSrcweir 387*cdf0e10cSrcweir //_________________________________ 388*cdf0e10cSrcweir 389*cdf0e10cSrcweir public void closeOutput() throws com.sun.star.io.NotConnectedException , 390*cdf0e10cSrcweir com.sun.star.io.BufferSizeExceededException, 391*cdf0e10cSrcweir com.sun.star.io.IOException 392*cdf0e10cSrcweir { 393*cdf0e10cSrcweir //m_aProtocol.log("closeOutput()\n{\n"); 394*cdf0e10cSrcweir m_bOutWasUsed = true; 395*cdf0e10cSrcweir 396*cdf0e10cSrcweir if (m_xOutStream == null) 397*cdf0e10cSrcweir { 398*cdf0e10cSrcweir //m_aProtocol.log("\tstream not open. throw NotConnectedException\n\tfailed\n}\n"); 399*cdf0e10cSrcweir throw new com.sun.star.io.NotConnectedException("stream not open"); 400*cdf0e10cSrcweir } 401*cdf0e10cSrcweir 402*cdf0e10cSrcweir try 403*cdf0e10cSrcweir { 404*cdf0e10cSrcweir m_xOutStream.closeOutput(); 405*cdf0e10cSrcweir } 406*cdf0e10cSrcweir catch (com.sun.star.io.NotConnectedException exConnect) { //m_aProtocol.log("\tgot NotConnectedException\n\tfailed\n}\n" ); throw exConnect; 407*cdf0e10cSrcweir } 408*cdf0e10cSrcweir catch (com.sun.star.io.BufferSizeExceededException exBuffer ) { //m_aProtocol.log("\tgot BufferSizeExceededException\n\tfailed\n}\n"); throw exBuffer; 409*cdf0e10cSrcweir } 410*cdf0e10cSrcweir catch (com.sun.star.io.IOException exIO ) { //m_aProtocol.log("\tgot IOException\n\tfailed\n}\n" ); throw exIO; 411*cdf0e10cSrcweir } 412*cdf0e10cSrcweir catch (com.sun.star.uno.RuntimeException exRuntime) { //m_aProtocol.log("\tgot RuntimeException\n\tfailed\n}\n" ); throw exRuntime; 413*cdf0e10cSrcweir } 414*cdf0e10cSrcweir catch (com.sun.star.uno.Exception exUno ) { //m_aProtocol.log("\tgot Exception\n\tfailed\n}\n" ); 415*cdf0e10cSrcweir } 416*cdf0e10cSrcweir 417*cdf0e10cSrcweir //m_aProtocol.log("\tOK\n}\n"); 418*cdf0e10cSrcweir } 419*cdf0e10cSrcweir 420*cdf0e10cSrcweir //_________________________________ 421*cdf0e10cSrcweir /** 422*cdf0e10cSrcweir * following methods simulates the XSeekable. 423*cdf0e10cSrcweir * The notice all actions inside the internal protocol 424*cdf0e10cSrcweir * and try to map all neccessary functions to the internal 425*cdf0e10cSrcweir * open stream. 426*cdf0e10cSrcweir */ 427*cdf0e10cSrcweir public void seek( /*IN*/long nLocation ) throws com.sun.star.lang.IllegalArgumentException, 428*cdf0e10cSrcweir com.sun.star.io.IOException 429*cdf0e10cSrcweir { 430*cdf0e10cSrcweir //m_aProtocol.log("seek("+nLocation+")\n{\n"); 431*cdf0e10cSrcweir 432*cdf0e10cSrcweir if (m_xInStream != null) 433*cdf0e10cSrcweir m_bInWasUsed = true; 434*cdf0e10cSrcweir else 435*cdf0e10cSrcweir if (m_xOutStream != null) 436*cdf0e10cSrcweir m_bOutWasUsed = true; 437*cdf0e10cSrcweir else 438*cdf0e10cSrcweir //m_aProtocol.log("\tno stream open!\n"); 439*cdf0e10cSrcweir 440*cdf0e10cSrcweir if (m_xSeek == null) 441*cdf0e10cSrcweir { 442*cdf0e10cSrcweir //m_aProtocol.log("\tstream not seekable. throw IOException\n\tfailed\n}\n"); 443*cdf0e10cSrcweir throw new com.sun.star.io.IOException("stream not seekable"); 444*cdf0e10cSrcweir } 445*cdf0e10cSrcweir 446*cdf0e10cSrcweir try 447*cdf0e10cSrcweir { 448*cdf0e10cSrcweir m_xSeek.seek(nLocation); 449*cdf0e10cSrcweir } 450*cdf0e10cSrcweir catch (com.sun.star.lang.IllegalArgumentException exArg ) { //m_aProtocol.log("\tgot IllegalArgumentException\n\tfailed\n}\n" ); throw exArg; 451*cdf0e10cSrcweir } 452*cdf0e10cSrcweir catch (com.sun.star.io.IOException exIO ) { //m_aProtocol.log("\tgot IOException\n\tfailed\n}\n" ); throw exIO; 453*cdf0e10cSrcweir } 454*cdf0e10cSrcweir catch (com.sun.star.uno.RuntimeException exRuntime) { //m_aProtocol.log("\tgot RuntimeException\n\tfailed\n}\n" ); throw exRuntime; 455*cdf0e10cSrcweir } 456*cdf0e10cSrcweir catch (com.sun.star.uno.Exception exUno ) { //m_aProtocol.log("\tgot Exception\n\tfailed\n}\n" ); 457*cdf0e10cSrcweir } 458*cdf0e10cSrcweir 459*cdf0e10cSrcweir //m_aProtocol.log("\tOK\n}\n"); 460*cdf0e10cSrcweir } 461*cdf0e10cSrcweir 462*cdf0e10cSrcweir //_________________________________ 463*cdf0e10cSrcweir 464*cdf0e10cSrcweir public long getPosition() throws com.sun.star.io.IOException 465*cdf0e10cSrcweir { 466*cdf0e10cSrcweir //m_aProtocol.log("getPosition()\n{\n"); 467*cdf0e10cSrcweir 468*cdf0e10cSrcweir if (m_xInStream != null) 469*cdf0e10cSrcweir m_bInWasUsed = true; 470*cdf0e10cSrcweir else 471*cdf0e10cSrcweir if (m_xOutStream != null) 472*cdf0e10cSrcweir m_bOutWasUsed = true; 473*cdf0e10cSrcweir else 474*cdf0e10cSrcweir //m_aProtocol.log("\tno stream open!\n"); 475*cdf0e10cSrcweir 476*cdf0e10cSrcweir if (m_xSeek == null) 477*cdf0e10cSrcweir { 478*cdf0e10cSrcweir //m_aProtocol.log("\tstream not seekable. throw IOException\n\tfailed\n}\n"); 479*cdf0e10cSrcweir throw new com.sun.star.io.IOException("stream not seekable"); 480*cdf0e10cSrcweir } 481*cdf0e10cSrcweir 482*cdf0e10cSrcweir long nPos = 0; 483*cdf0e10cSrcweir try 484*cdf0e10cSrcweir { 485*cdf0e10cSrcweir nPos = m_xSeek.getPosition(); 486*cdf0e10cSrcweir } 487*cdf0e10cSrcweir catch (com.sun.star.io.IOException exIO ) { //m_aProtocol.log("\tgot IOException\n\tfailed\n}\n" ); throw exIO; 488*cdf0e10cSrcweir } 489*cdf0e10cSrcweir catch (com.sun.star.uno.RuntimeException exRuntime) { //m_aProtocol.log("\tgot RuntimeException\n\tfailed\n}\n"); throw exRuntime; 490*cdf0e10cSrcweir } 491*cdf0e10cSrcweir catch (com.sun.star.uno.Exception exUno ) { //m_aProtocol.log("\tgot Exception\n\tfailed\n}\n" ); 492*cdf0e10cSrcweir } 493*cdf0e10cSrcweir 494*cdf0e10cSrcweir //m_aProtocol.log("\treturns pos="+nPos+"\n\tOK\n}\n"); 495*cdf0e10cSrcweir return nPos; 496*cdf0e10cSrcweir } 497*cdf0e10cSrcweir 498*cdf0e10cSrcweir //_________________________________ 499*cdf0e10cSrcweir 500*cdf0e10cSrcweir public long getLength() throws com.sun.star.io.IOException 501*cdf0e10cSrcweir { 502*cdf0e10cSrcweir //m_aProtocol.log("getLength()\n{\n"); 503*cdf0e10cSrcweir 504*cdf0e10cSrcweir if (m_xInStream != null) 505*cdf0e10cSrcweir m_bInWasUsed = true; 506*cdf0e10cSrcweir else 507*cdf0e10cSrcweir if (m_xOutStream != null) 508*cdf0e10cSrcweir m_bOutWasUsed = true; 509*cdf0e10cSrcweir else 510*cdf0e10cSrcweir //m_aProtocol.log("\tno stream open!\n"); 511*cdf0e10cSrcweir 512*cdf0e10cSrcweir if (m_xSeek == null) 513*cdf0e10cSrcweir { 514*cdf0e10cSrcweir //m_aProtocol.log("\tstream not seekable. throw IOException\n\tfailed\n}\n"); 515*cdf0e10cSrcweir throw new com.sun.star.io.IOException("stream not seekable"); 516*cdf0e10cSrcweir } 517*cdf0e10cSrcweir 518*cdf0e10cSrcweir long nLen = 0; 519*cdf0e10cSrcweir try 520*cdf0e10cSrcweir { 521*cdf0e10cSrcweir nLen = m_xSeek.getLength(); 522*cdf0e10cSrcweir } 523*cdf0e10cSrcweir catch (com.sun.star.io.IOException exIO ) { //m_aProtocol.log("\tgot IOException\n\tfailed\n}\n" ); throw exIO; 524*cdf0e10cSrcweir } 525*cdf0e10cSrcweir catch (com.sun.star.uno.RuntimeException exRuntime) { //m_aProtocol.log("\tgot RuntimeException\n\tfailed\n}\n"); throw exRuntime; 526*cdf0e10cSrcweir } 527*cdf0e10cSrcweir catch (com.sun.star.uno.Exception exUno ) { //m_aProtocol.log("\tgot Exception\n\tfailed\n}\n" ); 528*cdf0e10cSrcweir } 529*cdf0e10cSrcweir 530*cdf0e10cSrcweir //m_aProtocol.log("\treturns len="+nLen+"\n\tOK\n}\n"); 531*cdf0e10cSrcweir return nLen; 532*cdf0e10cSrcweir } 533*cdf0e10cSrcweir } 534