LazyRandomAccessFileByteWriter.java
2.44 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
/*
* Decompiled with CFR 0_118.
*/
package com.adobe.internal.io;
import com.adobe.internal.io.ByteWriter;
import com.adobe.internal.io.RandomAccessFileByteWriter;
import java.io.File;
import java.io.IOException;
import java.io.RandomAccessFile;
public class LazyRandomAccessFileByteWriter
implements ByteWriter {
private File file;
private ByteWriter byteWriter;
private boolean openFailed = false;
public LazyRandomAccessFileByteWriter(File file) throws IOException {
if (file == null) {
throw new IOException("File is not valid.");
}
this.file = file;
}
@Override
public int read(long position) throws IOException {
return this.getByteWriter().read(position);
}
@Override
public int read(long position, byte[] b, int offset, int length) throws IOException {
return this.getByteWriter().read(position, b, offset, length);
}
@Override
public long length() throws IOException {
return this.getByteWriter().length();
}
@Override
public void close() throws IOException {
if (this.byteWriter != null) {
this.byteWriter.close();
}
this.byteWriter = null;
this.file = null;
}
private ByteWriter getByteWriter() throws IOException {
if (this.byteWriter != null) {
return this.byteWriter;
}
if (this.openFailed) {
throw new IOException("Unable to open file.");
}
try {
RandomAccessFile raf;
try {
raf = new RandomAccessFile(this.file, "r");
}
catch (Exception e) {
IOException ioException = new IOException("Unable to open the RandomAccessFile for the File " + this.file);
ioException.initCause(e);
throw ioException;
}
this.byteWriter = new RandomAccessFileByteWriter(raf);
}
catch (IOException e) {
this.openFailed = true;
}
return this.byteWriter;
}
@Override
public void write(long position, int b) throws IOException {
this.getByteWriter().write(position, b);
}
@Override
public void write(long position, byte[] b, int offset, int length) throws IOException {
this.getByteWriter().write(position, b, offset, length);
}
@Override
public void flush() throws IOException {
this.getByteWriter().flush();
}
}