BufferedRAFOutputStream.java
1.46 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
/*
* Decompiled with CFR 0_118.
*/
package com.day.io;
import java.io.IOException;
import java.io.OutputStream;
import java.io.RandomAccessFile;
public class BufferedRAFOutputStream
extends OutputStream {
private final byte[] buffer = new byte[8192];
private RandomAccessFile raf;
private long bufferStart;
private int bufferEnd;
private byte[] one = new byte[1];
public BufferedRAFOutputStream(RandomAccessFile raf) throws IOException {
this.raf = raf;
this.bufferStart = raf.getFilePointer();
}
public void write(int b) throws IOException {
this.one[0] = (byte)b;
this.write(this.one, 0, 1);
}
public void write(byte[] b) throws IOException {
this.write(b, 0, b.length);
}
public void write(byte[] b, int off, int len) throws IOException {
if (len > this.buffer.length - this.bufferEnd) {
this.flush();
this.raf.write(b, off, len);
} else {
System.arraycopy(b, off, this.buffer, this.bufferEnd, len);
this.bufferEnd += len;
}
}
public void flush() throws IOException {
this.raf.write(this.buffer, 0, this.bufferEnd);
this.bufferEnd = 0;
this.bufferStart = this.raf.getFilePointer();
}
public void close() throws IOException {
this.flush();
this.raf = null;
}
public long getFilePointer() {
return this.bufferStart + (long)this.bufferEnd;
}
}