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_MarkableOutputStream" 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.MarkableOutputStream 54'************************************************************************* 55On Error Goto ErrHndl 56 57 bInputStream = false 58 bOutputStream = false 59 cFileName = utils.getTempFileURL("BasicMarkableIOStream.dat") 60 oFileAcc = createUnoService("com.sun.star.ucb.SimpleFileAccess") 61 62 oObj = createUnoService("com.sun.star.io.MarkableOutputStream") 63 64 ResetStreams() 65Exit Sub 66ErrHndl: 67 Test.Exception() 68End Sub 69 70Function getOutStream() As Object 71On Error Goto ErrHndl 72 CloseStreams() 73 oOutputStream = oFileAcc.openFileWrite(cFileName) 74 bOutputStream = true 75 oObj.setOutputStream(oOutputStream) 76 getOutStream() = oOutputStream 77Exit Function 78ErrHndl: 79 Test.Exception() 80 getOutStream() = NULL_OBJECT 81End Function 82 83Function getInStream() As Object 84On Error Goto ErrHndl 85 Dim oFI As Object 86 87 CloseStreams() 88 oInputStream = createUnoService("com.sun.star.io.MarkableInputStream") 89 oFI = oFileAcc.openFileRead(cFileName) 90 oInputStream.setInputStream(oFI) 91 bInputStream = true 92 getInStream() = oInputStream 93 94Exit Function 95ErrHndl: 96 Test.Exception() 97 getInStream() = NULL_OBJECT 98End Function 99 100Sub ResetStreams() 101On Error goto ErrHndl 102 CloseStreams() 103 oFileAcc.Kill(cFileName) 104 oOutputStream = oFileAcc.openFileWrite(cFileName) 105 bOutputStream = true 106 oObj.setOutputStream(oOutputStream) 107Exit Sub 108ErrHndl: 109 Test.Exception() 110 resume next 111End Sub 112 113Sub CloseStreams() 114 if bOutputStream then 115 oObj.closeOutput() 116 bOutputStream = false 117 end if 118 if bInputStream then 119 oInputStream.closeInput() 120 bInputStream = false 121 end if 122End Sub 123 124Sub DisposeObj() 125 if NOT isNULL(oObj) then oObj.closeOutput() 126End Sub 127</script:module> 128