DurboValue.java
2.21 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
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* javax.jcr.Binary
* javax.jcr.RepositoryException
* javax.jcr.Value
* javax.jcr.ValueFactory
* org.apache.commons.io.IOUtils
*/
package com.day.durbo;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import javax.jcr.Binary;
import javax.jcr.RepositoryException;
import javax.jcr.Value;
import javax.jcr.ValueFactory;
import org.apache.commons.io.IOUtils;
public class DurboValue {
private final int type;
private byte[] bytes;
private InputStream in;
private long size;
public DurboValue(int type, byte[] bytes) {
this.type = type;
this.bytes = bytes;
this.size = bytes.length;
}
public DurboValue(int type, InputStream in, long size) {
this.type = type;
this.in = in;
this.size = size;
}
public int getType() {
return this.type;
}
public int getSize() {
if (this.size > Integer.MAX_VALUE) {
throw new IllegalArgumentException("Size greater than 2^31. Use getLength() instead.");
}
return (int)this.size;
}
public long getLength() {
return this.size;
}
public byte[] getBytes() throws IOException {
if (this.bytes == null) {
this.bytes = IOUtils.toByteArray((InputStream)this.in);
this.in.close();
this.in = null;
}
return this.bytes;
}
public String getString() throws IOException {
return new String(this.getBytes(), "utf-8");
}
public double getDouble() throws IOException {
return Double.parseDouble(this.getString());
}
public InputStream getStream() {
if (this.in == null) {
return new ByteArrayInputStream(this.bytes);
}
return this.in;
}
public boolean isByteArrayBased() {
return this.bytes != null;
}
public Value toJcrValue(ValueFactory factory) throws IOException, RepositoryException {
if (this.type == 2) {
return factory.createValue(factory.createBinary(this.getStream()));
}
return factory.createValue(this.getString(), this.type);
}
}