Added readonly and preview options to openURL(). Some code cleanup.
[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 unohelper
14 from com.sun.star.io import XInputStream, XOutputStream, XSeekable
15
16 class InputStream(unohelper.Base, XInputStream, XSeekable):
17     def __init__(self, stream):
18         self.f = stream
19
20     def skipBytes(self, count):
21         self.f.read(count)
22
23     def readBytes(self, retSeq, count):
24         s = self.f.read(count)
25         return len(s), s
26
27     def readSomeBytes(self, retSeq , count):
28         return self.readBytes(retSeq, count)
29
30     def available(self):
31         return 0
32
33     def closeInput(self):
34         self.f.close()
35
36     def seek(self, pos):
37         self.f.seek(pos)
38
39     def getPosition(self):
40         return self.f.tell()
41     
42     def getLength(self):
43         f = self.f # shortcut
44         pos = f.tell()
45         f.seek(0, 2)
46         len = f.tell()
47         f.seek(pos)
48         return len
49     
50
51 class OutputStream(unohelper.Base, XOutputStream):
52     def __init__(self, stream):
53         self.f = stream
54
55     def writeBytes(self, seq):
56         self.f.write(seq.value)
57
58     def closeOutput(self):
59         self.f.flush()
60
61     def flush(self):
62         self.f.flush()