PaddedInputByteStream.java
3.37 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
/*
* Decompiled with CFR 0_118.
*/
package com.adobe.internal.io.stream;
import com.adobe.internal.io.stream.InputByteStream;
import com.adobe.internal.io.stream.InputByteStreamImpl;
import java.io.IOException;
public class PaddedInputByteStream
extends InputByteStreamImpl {
private InputByteStream baseIBS;
private int paddedChar = 32;
private long padLength = 0;
private long padMark = 0;
public PaddedInputByteStream(InputByteStream ibs, int paddedChar, long padLength) {
this.baseIBS = ibs;
this.paddedChar = paddedChar;
this.padLength = padLength;
}
@Override
public void close() throws IOException {
this.baseIBS.close();
}
@Override
public long getPosition() throws IOException {
if (this.baseIBS.eof()) {
return this.baseIBS.length() + this.padMark;
}
return this.baseIBS.getPosition();
}
@Override
public long length() throws IOException {
return this.baseIBS.length() + this.padLength;
}
@Override
public int read() throws IOException {
if (this.eof()) {
return -1;
}
if (this.baseIBS.eof()) {
++this.padMark;
return this.paddedChar;
}
return this.baseIBS.read();
}
@Override
public int read(byte[] bytes, int position, int length) throws IOException {
int bytesToBeCopied;
if (this.eof()) {
return -1;
}
if (this.getPosition() + (long)length <= this.baseIBS.length()) {
return this.baseIBS.read(bytes, position, length);
}
if (this.getPosition() + (long)length > this.length()) {
length = (int)(this.length() - this.getPosition());
}
bytesToBeCopied = (bytesToBeCopied = (int)(this.baseIBS.length() - this.getPosition())) > 0 ? bytesToBeCopied : 0;
this.baseIBS.read(bytes, position, bytesToBeCopied);
for (int i = position += bytesToBeCopied; i < position + length - bytesToBeCopied; ++i) {
bytes[i] = (byte)this.paddedChar;
}
this.padMark += (long)(length - bytesToBeCopied);
return length;
}
@Override
public InputByteStream seek(long position) throws IOException {
if (position > this.length()) {
this.padMark = this.padLength;
this.baseIBS.seek(this.baseIBS.length());
} else if (position < this.baseIBS.length()) {
this.padMark = 0;
this.baseIBS.seek(position);
} else {
this.baseIBS.seek(this.baseIBS.length());
this.padMark = position - this.baseIBS.length();
}
return this;
}
@Override
public InputByteStream slice(long begin, long length) throws IOException {
long padding = 0;
if (begin < 0 || length < 0 || begin + length > this.length()) {
throw new IOException("Invalid slice of PaddedBytestream");
}
if (begin + length > this.baseIBS.length()) {
if (begin > this.baseIBS.length()) {
padding = length;
begin = 0;
length = 0;
} else {
padding = (int)(begin + length - this.baseIBS.length());
length -= padding;
}
}
return new PaddedInputByteStream(this.baseIBS.slice(begin, length), this.paddedChar, padding);
}
}