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