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