Fixed: missing import of `glob`
[openoffice-python:openoffice-python.git] / openoffice / streams.py
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
3 #
4 # Copyright (c) 2008 by Hartmut Goebel <h.goebel@goebel-consult.de>
5 # Licenced under the GNU General Public License v3 (GPLv3)
6 # see file LICENSE-gpl-3.0.txt
7 #
8
9 __author__ = "Hartmut Goebel <h.goebel@goebel-consult.de>"
10 __copyright__ = "Copyright (c) 2008 by Hartmut Goebel <h.goebel@goebel-consult.de>"
11 __licence__ = "GPLv3 - GNU General Public License v3"
12
13 import uno
14 import unohelper
15 from com.sun.star.io import XInputStream, XOutputStream, XSeekable
16
17 class InputStream(unohelper.Base, XInputStream, XSeekable):
18     def __init__(self, stream):
19         self.f = stream
20
21     def skipBytes(self, count):
22         self.f.read(count)
23
24     def readBytes(self, retSeq, count):
25         s = self.f.read(count)
26         return len(s), uno.ByteSequence(s)
27
28     def readSomeBytes(self, retSeq , count):
29         return self.readBytes(retSeq, count)
30
31     def available(self):
32         return 0
33
34     def closeInput(self):
35         self.f.close()
36
37     def seek(self, pos):
38         self.f.seek(pos)
39
40     def getPosition(self):
41         return self.f.tell()
42     
43     def getLength(self):
44         f = self.f # shortcut
45         pos = f.tell()
46         f.seek(0, 2)
47         len = f.tell()
48         f.seek(pos)
49         return len
50     
51
52 class OutputStream(unohelper.Base, XOutputStream):
53     def __init__(self, stream):
54         self.f = stream
55
56     def writeBytes(self, seq):
57         self.f.write(seq.value)
58
59     def closeOutput(self):
60         self.f.flush()
61
62     def flush(self):
63         self.f.flush()