-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathdata_output_stream.py
More file actions
44 lines (30 loc) · 1.1 KB
/
Copy pathdata_output_stream.py
File metadata and controls
44 lines (30 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
"""
Writing to Java DataInputStream format.
"""
import struct
class DataOutputStream:
def __init__(self, stream):
self.stream = stream
def write_boolean(self, bool):
self.stream.write(struct.pack('?', bool))
def write_byte(self, val):
self.stream.write(struct.pack('b', val))
def write_unsigned_byte(self, val):
self.stream.write(struct.pack('B', val))
def write_char(self, val):
self.stream.write(struct.pack('>H', ord(val)))
def write_double(self, val):
self.stream.write(struct.pack('>d', val))
def write_float(self, val):
self.stream.write(struct.pack('>f', val))
def write_short(self, val):
self.stream.write(struct.pack('>h', val))
def write_unsigned_short(self, val):
self.stream.write(struct.pack('>H', val))
def write_long(self, val):
self.stream.write(struct.pack('>q', val))
def write_utf(self, string):
self.stream.write(struct.pack('>H', len(string)))
self.stream.write(string)
def write_int(self, val):
self.stream.write(struct.pack('>i', val))