ByteWriterOutputByteStream.java
3.69 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
105
106
107
108
109
110
111
112
113
114
115
/*
* Decompiled with CFR 0_118.
*/
package com.adobe.internal.io.stream;
import com.adobe.internal.io.ByteReader;
import com.adobe.internal.io.ByteWriter;
import com.adobe.internal.io.stream.ByteReaderInputByteStream;
import com.adobe.internal.io.stream.InputByteStream;
import com.adobe.internal.io.stream.OutputByteStream;
import com.adobe.internal.io.stream.OutputByteStreamImpl;
import com.adobe.internal.io.stream.OutputStreamImpl;
import com.adobe.internal.io.stream.SkippingOutputStream;
import com.adobe.internal.io.stream.StreamManager;
import java.io.IOException;
class ByteWriterOutputByteStream
extends OutputByteStreamImpl {
private ByteWriter byteWriter = null;
private StreamManager streamManager;
private boolean registered = false;
ByteWriterOutputByteStream(StreamManager streamManager, ByteWriter byteWriter, boolean register) throws IOException {
if (byteWriter == null) {
throw new IOException("Null ByteWriter parameter.");
}
this.streamManager = streamManager;
this.byteWriter = byteWriter;
this.registered = register;
if (register) {
this.streamManager.registerOutputByteStream(this, byteWriter);
}
}
ByteWriter getByteWriter() {
return this.byteWriter;
}
@Override
public void write(int b) throws IOException {
this.byteWriter.write(this.getPosition(), b);
this.seek(this.getPosition() + 1);
}
@Override
public void write(byte[] bytes, int offset, int length) throws IOException {
this.byteWriter.write(this.getPosition(), bytes, offset, length);
this.seek(this.getPosition() + (long)length);
}
@Override
public long length() throws IOException {
return this.byteWriter.length();
}
@Override
public boolean eof() throws IOException {
return this.getPosition() >= this.byteWriter.length();
}
@Override
public void close() throws IOException {
if (this.registered) {
this.streamManager.deregisterOutputByteStream(this, this.byteWriter);
} else {
this.byteWriter.close();
}
this.byteWriter = null;
}
@Override
public InputByteStream closeAndConvert() throws IOException {
ByteWriter br = this.byteWriter;
ByteReaderInputByteStream ibs = new ByteReaderInputByteStream(this.streamManager, br, this.registered);
if (this.registered) {
this.streamManager.deregisterOutputByteStream(this, this.byteWriter);
}
this.byteWriter = null;
return ibs;
}
@Override
public void flush() throws IOException {
this.byteWriter.flush();
}
@Override
public SkippingOutputStream toOutputStream() throws IOException {
return new OutputStreamImpl(this);
}
public String toString() {
StringBuilder message = null;
try {
byte[] buf = new byte[1000];
long position = Math.max(this.getPosition() - 1000, 0);
long bytesRead = this.byteWriter.read(position, buf, 0, buf.length);
message = new StringBuilder("OutputByteStream [ position = ").append(this.getPosition()).append(", limit = ").append(this.length()).append(" ] ").append(bytesRead == -1 ? "" : new String(buf, 0, (int)bytesRead, "US-ASCII"));
}
catch (Exception e) {
throw new RuntimeException(e);
}
return message.toString();
}
public void write(String s) throws IOException {
char[] chars = s.toCharArray();
byte[] bytes = new byte[chars.length];
for (int i = 0; i < chars.length; ++i) {
bytes[i] = (byte)chars[i];
}
this.write(bytes);
}
}