DataBufferInputStream.java
2.5 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
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.adobe.service.DataBuffer
*/
package com.adobe.aemfd.docmanager.internal.io;
import com.adobe.service.DataBuffer;
import java.io.IOException;
import java.io.InputStream;
public class DataBufferInputStream
extends InputStream {
private DataBuffer dataBuffer;
private long _pos = 0;
private long _len;
private boolean closed = false;
public DataBufferInputStream(DataBuffer dataBuffer) {
this.dataBuffer = dataBuffer;
this._len = dataBuffer.getBufLength();
}
private void checkClosed() throws IOException {
if (this.closed) {
throw new IOException("The stream is closed!");
}
}
public int available() throws IOException {
this.checkClosed();
if (this._len == -1) {
return super.available();
}
if (this._pos >= this._len) {
return 0;
}
long avb = this._len - this._pos;
return avb > Integer.MAX_VALUE ? Integer.MAX_VALUE : (int)avb;
}
public int read() throws IOException {
byte[] buf = new byte[1];
int rd = this.read(buf);
return rd == -1 ? -1 : buf[0];
}
public int read(byte[] b, int off, int len) throws IOException {
int toRead;
this.checkClosed();
if (b == null) {
throw new NullPointerException();
}
if (off < 0 || len < 0 || len > b.length - off) {
throw new IndexOutOfBoundsException();
}
if (len == 0) {
return 0;
}
int n = toRead = this._len == -1 ? len : Math.min(len, this.available());
if (toRead == 0) {
return -1;
}
byte[] rb = this.dataBuffer.getBytes(this._pos, (long)toRead);
int actualRead = rb.length;
if (actualRead == 0) {
return -1;
}
System.arraycopy(rb, 0, b, off, actualRead);
this._pos += (long)actualRead;
return actualRead;
}
public long skip(long n) throws IOException {
this.checkClosed();
if (n <= 0) {
return 0;
}
if (this._len == -1) {
return 0;
}
int avb = this.available();
if (avb == 0) {
return 0;
}
long toSkip = Math.min(n, (long)avb);
this._pos += toSkip;
return toSkip;
}
public void close() throws IOException {
this.dataBuffer = null;
this.closed = true;
}
}