1<?xml version="1.0" encoding="UTF-8"?> 2<!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd"> 3<script:module xmlns:script="http://openoffice.org/2000/script" script:name="stm_DataInputStream" script:language="StarBasic"> 4 5 6'************************************************************************* 7' 8' DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 9' 10' Copyright 2000, 2010 Oracle and/or its affiliates. 11' 12' OpenOffice.org - a multi-platform office productivity suite 13' 14' This file is part of OpenOffice.org. 15' 16' OpenOffice.org is free software: you can redistribute it and/or modify 17' it under the terms of the GNU Lesser General Public License version 3 18' only, as published by the Free Software Foundation. 19' 20' OpenOffice.org is distributed in the hope that it will be useful, 21' but WITHOUT ANY WARRANTY; without even the implied warranty of 22' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 23' GNU Lesser General Public License version 3 for more details 24' (a copy is included in the LICENSE file that accompanied this code). 25' 26' You should have received a copy of the GNU Lesser General Public License 27' version 3 along with OpenOffice.org. If not, see 28' <http://www.openoffice.org/license.html> 29' for a copy of the LGPLv3 License. 30' 31'************************************************************************* 32'************************************************************************* 33 34 35 36' Be sure that all variables are dimensioned: 37option explicit 38 39 40' REQUIRED VARIABLES for interface/service tests: 41Global cFileName As String 42Global oFileAcc As Object 43Global oInputStream As Object 44Global oOutputStream As Object 45Global bInputStream As Boolean 46Global bOutputStream As Boolean 47 48 49Sub CreateObj() 50 51'************************************************************************* 52' COMPONENT: 53' stm.DataInputStream 54'************************************************************************* 55On Error Goto ErrHndl 56 Dim oOS As Object 57 58 bInputStream = false 59 bOutputStream = false 60 cFileName = utils.getTempFileURL("BasicDataInputStream.dat") 61 oFileAcc = createUnoService("com.sun.star.ucb.SimpleFileAccess") 62 63 oObj = createUnoService("com.sun.star.io.DataInputStream") 64 65 'Creating a file... 66 oOS = oFileAcc.openFileWrite(cFileName) 67 oOS.closeOutput() 68 69 ResetStreams() 70Exit Sub 71ErrHndl: 72 Test.Exception() 73End Sub 74 75Function getOutStream() As Object 76On Error goto ErrHndl 77 Dim oFO As Object 78 ResetStreams() 79 oInputStream.closeInput() 80 oOutputStream = createUnoService("com.sun.star.io.DataOutputStream") 81 oFileAcc.kill(cFileName) 82 oFO = oFileAcc.openFileWrite(cFileName) 83 oOutputStream.setOutputStream(oFO) 84 bOutputStream = true 85 getOutStream() = oOutputStream 86Exit Function 87ErrHndl: 88 Test.Exception() 89 getOutStream() = NULL_OBJECT 90End Function 91 92Function getInStream() As Object 93On Error goto ErrHndl 94 ResetStreams() 95 getInStream() = oInputStream 96Exit Function 97ErrHndl: 98 Test.Exception() 99 getInStream() = NULL_OBJECT 100End Function 101 102Sub ResetStreams() 103On Error goto ErrHndl 104 if bInputStream then 105 oInputStream.closeInput() 106 bInputStream = false 107 end if 108 if bOutputStream then 109 oOutputStream.closeOutput() 110 bOutputStream = false 111 end if 112 113 if NOT oFileAcc.exists(cFileName) then 114 Dim oFO As Object 115 oFO = oFileAcc.openFileWrite(cFileName) 116 oFO.closeOutput() 117 end if 118 119 oInputStream = oFileAcc.openFileRead(cFileName) 120 bInputStream = true 121 oObj.setInputStream(oInputStream) 122Exit Sub 123ErrHndl: 124 Test.Exception() 125 resume next 126End Sub 127 128Sub DisposeObj() 129 if NOT isNULL(oObj) then oObj.closeInput() 130End Sub 131</script:module> 132