LineOutputStream.java
2.84 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
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
/*
* Decompiled with CFR 0_118.
*/
package com.day.jcr.vault.util;
import java.io.IOException;
import java.io.OutputStream;
public class LineOutputStream
extends OutputStream {
public static final byte[] LS_BINARY = null;
public static final byte[] LS_UNIX = new byte[]{10};
public static final byte[] LS_WINDOWS = new byte[]{13, 10};
public static final byte[] LS_NATIVE = System.getProperty("line.separator").getBytes();
private byte[] buffer = new byte[8192];
private byte[] lineFeed = LS_NATIVE;
private int pos = 0;
private static final char STATE_INIT = ' ';
private static final char STATE_CR = 'c';
private static final char STATE_LF = 'l';
private static final char STATE_CRLF = 'f';
private char state = 32;
private final OutputStream out;
public LineOutputStream(OutputStream out, byte[] ls) {
this.out = out;
if (ls != null) {
this.lineFeed = ls;
}
}
public void write(int b) throws IOException {
if (b == 10) {
switch (this.state) {
case ' ': {
this.state = 108;
break;
}
case 'c': {
this.state = 102;
break;
}
case 'l': {
this.flush(true);
this.state = 108;
break;
}
case 'f': {
this.flush(true);
this.state = 108;
}
}
} else if (b == 13) {
switch (this.state) {
case ' ': {
this.state = 99;
break;
}
case 'l': {
this.state = 102;
break;
}
case 'c': {
this.flush(true);
this.state = 99;
break;
}
case 'f': {
this.flush(true);
this.state = 99;
}
}
} else {
if (this.state != ' ') {
this.flush(true);
this.state = 32;
}
if (this.pos == this.buffer.length) {
this.flush();
}
this.buffer[this.pos++] = (byte)(b & 255);
}
}
public void flush(boolean addLF) throws IOException {
this.flush();
if (addLF) {
this.out.write(this.lineFeed);
}
this.out.flush();
}
public void flush() throws IOException {
this.out.write(this.buffer, 0, this.pos);
this.pos = 0;
this.out.flush();
}
public void close() throws IOException {
this.flush(this.state != ' ');
this.out.close();
}
}