InputStreamByteWriter.java
2.2 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
/*
* Decompiled with CFR 0_118.
*/
package com.adobe.internal.io;
import com.adobe.internal.io.ByteArrayByteWriter;
import com.adobe.internal.io.ByteWriter;
import com.adobe.internal.io.RandomAccessFileByteWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.RandomAccessFile;
public final class InputStreamByteWriter
implements ByteWriter {
private ByteWriter byteWriter;
public InputStreamByteWriter(InputStream inputStream) throws IOException {
int bytesRead;
ByteArrayByteWriter writer = new ByteArrayByteWriter();
byte[] buffer = new byte[4096];
long position = 0;
while ((bytesRead = inputStream.read(buffer)) != -1) {
writer.write(position, buffer, 0, bytesRead);
position += (long)bytesRead;
}
this.byteWriter = writer;
inputStream.close();
}
public InputStreamByteWriter(InputStream inputStream, RandomAccessFile raf) throws IOException {
int bytesRead;
byte[] buffer = new byte[4096];
while ((bytesRead = inputStream.read(buffer)) != -1) {
raf.write(buffer, 0, bytesRead);
}
this.byteWriter = new RandomAccessFileByteWriter(raf);
inputStream.close();
}
@Override
public int read(long position) throws IOException {
return this.byteWriter.read(position);
}
@Override
public int read(long position, byte[] b, int offset, int length) throws IOException {
return this.byteWriter.read(position, b, offset, length);
}
@Override
public long length() throws IOException {
return this.byteWriter.length();
}
@Override
public void close() throws IOException {
this.byteWriter.close();
}
public String toString() {
return this.byteWriter.toString();
}
@Override
public void write(long position, int b) throws IOException {
this.byteWriter.write(position, b);
}
@Override
public void write(long position, byte[] b, int offset, int length) throws IOException {
this.byteWriter.write(position, b, offset, length);
}
@Override
public void flush() throws IOException {
this.byteWriter.flush();
}
}