blob: 888e71ab60eb5e6b66d12a0083bdbe6a5a756111 (
plain) (
blame)
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
|
---
title: ServerOutputStream
---
## Imports
- `java.io.FilterOutputStream`
- `java.io.IOException`
- `java.io.OutputStream`
## Extends
[FilterOutputStream](https://docs.oracle.com/javase/7/docs/api/java/io/FilterOutputStream.html)
## Fields
### `private int _version`
Purpose is to be determined.
## Constructors
```java
public ServerOutputStream(OutputStream o) {
super(o);
setVersion(24);
}
public ServerOutputStream(OutputStream o, int vers) {
super(o);
setVersion(vers);
}
```
## Methods
### `public void setVersion(int vers)`
Sets [`this._version`](#private-int-_version) to `vers`.
### `public int getVersion()`
Returns [`this._version`](#private-int-_version).
### `public final void write(int b) throws IOException`
Writes the singular byte; `b` to the output stream.
```java
this.out.write(b);
```
### `public final void write(byte[] b, int off, len) throws IOException`
Writes `len` bytes from the specified byte array starting at the offset; `off` to the output stream.
```java
this.out.write(b, off, len);
```
### `public final void writeByte(int v) throws IOException`
Clone of [`write(int b)`](#public-final-void-writeint-b-throws-ioexception).
### `public final void writeShort(int v) throws IOException`
```java
OutputStream out = this.out;
out.write(v >>> 8 & 0xFF);
out.write(v >>> 0 & 0xFF);
```
### `public final void writeInt(int v) throws IOException`
```java
OutputStream out = this.out;
out.write(v >>> 24 & 0xFF);
out.write(v >>> 16 & 0xFF);
out.write(v >>> 8 & 0xFF);
out.write(v >>> 0 & 0xFF);
```
### `public static int utfLength(String str)`
```java
int strlen = str.length();
int utflen = 0;
for (int i = 0; i < strlen; i++) {
int c = str.charAt(i);
if (c >= 1 && c <= 127) {
utflen++;
} else if (c > 2047) {
utflen += 3;
} else {
utflen += 2;
}
}
return utflen;
```
### `public final void writeUTF(String str) throws IOException`
```java
OutputStream out = this.out;
int strlen = str.length();
int utflen = utfLength(str);
assert utflen < 256;
out.write(utflen >>> 0 & 0xFF);
for (int i = 0; i < strlen; i++) {
int c = str.charAt(i);
if (c >= 1 && c <= 127) {
out.write(c);
} else if (c > 2047) {
out.write(0xE0 | c >> 12 & 0xF);
out.write(0x80 | c >> 6 & 0x3F);
out.write(0x80 | c >> 0 & 0x3F);
} else {
out.write(0xC0 | c >> 6 & 0x1F);
out.write(0x80 | c >> 0 & 0x3F);
}
}
```
### Resources
- [https://docs.oracle.com/javase/7/docs/api/java/io/FilterOutputStream.html](https://docs.oracle.com/javase/7/docs/api/java/io/FilterOutputStream.html)
|