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' Licensed to the Apache Software Foundation (ASF) under one 9' or more contributor license agreements. See the NOTICE file 10' distributed with this work for additional information 11' regarding copyright ownership. The ASF licenses this file 12' to you under the Apache License, Version 2.0 (the 13' "License"); you may not use this file except in compliance 14' with the License. You may obtain a copy of the License at 15' 16' http://www.apache.org/licenses/LICENSE-2.0 17' 18' Unless required by applicable law or agreed to in writing, 19' software distributed under the License is distributed on an 20' "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 21' KIND, either express or implied. See the License for the 22' specific language governing permissions and limitations 23' under the License. 24' 25'************************************************************************* 26 27 28 29 30 31' Be sure that all variables are dimensioned: 32option explicit 33 34 35' REQUIRED VARIABLES for interface/service tests: 36Global cFileName As String 37Global oFileAcc As Object 38Global oInputStream As Object 39Global oOutputStream As Object 40Global bInputStream As Boolean 41Global bOutputStream As Boolean 42 43 44Sub CreateObj() 45 46'************************************************************************* 47' COMPONENT: 48' stm.DataInputStream 49'************************************************************************* 50On Error Goto ErrHndl 51 Dim oOS As Object 52 53 bInputStream = false 54 bOutputStream = false 55 cFileName = utils.getTempFileURL("BasicDataInputStream.dat") 56 oFileAcc = createUnoService("com.sun.star.ucb.SimpleFileAccess") 57 58 oObj = createUnoService("com.sun.star.io.DataInputStream") 59 60 'Creating a file... 61 oOS = oFileAcc.openFileWrite(cFileName) 62 oOS.closeOutput() 63 64 ResetStreams() 65Exit Sub 66ErrHndl: 67 Test.Exception() 68End Sub 69 70Function getOutStream() As Object 71On Error goto ErrHndl 72 Dim oFO As Object 73 ResetStreams() 74 oInputStream.closeInput() 75 oOutputStream = createUnoService("com.sun.star.io.DataOutputStream") 76 oFileAcc.kill(cFileName) 77 oFO = oFileAcc.openFileWrite(cFileName) 78 oOutputStream.setOutputStream(oFO) 79 bOutputStream = true 80 getOutStream() = oOutputStream 81Exit Function 82ErrHndl: 83 Test.Exception() 84 getOutStream() = NULL_OBJECT 85End Function 86 87Function getInStream() As Object 88On Error goto ErrHndl 89 ResetStreams() 90 getInStream() = oInputStream 91Exit Function 92ErrHndl: 93 Test.Exception() 94 getInStream() = NULL_OBJECT 95End Function 96 97Sub ResetStreams() 98On Error goto ErrHndl 99 if bInputStream then 100 oInputStream.closeInput() 101 bInputStream = false 102 end if 103 if bOutputStream then 104 oOutputStream.closeOutput() 105 bOutputStream = false 106 end if 107 108 if NOT oFileAcc.exists(cFileName) then 109 Dim oFO As Object 110 oFO = oFileAcc.openFileWrite(cFileName) 111 oFO.closeOutput() 112 end if 113 114 oInputStream = oFileAcc.openFileRead(cFileName) 115 bInputStream = true 116 oObj.setInputStream(oInputStream) 117Exit Sub 118ErrHndl: 119 Test.Exception() 120 resume next 121End Sub 122 123Sub DisposeObj() 124 if NOT isNULL(oObj) then oObj.closeInput() 125End Sub 126</script:module> 127