1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package net.sf.beep4j;
17
18 import net.sf.beep4j.internal.util.Assert;
19 import net.sf.beep4j.internal.util.ByteUtil;
20
21
22
23
24
25
26 public final class ProfileInfo {
27
28 private final String uri;
29
30 private boolean base64;
31
32 private byte[] data;
33
34 private String content;
35
36 public ProfileInfo(String uri) {
37 Assert.notNull("uri", uri);
38 this.uri = uri;
39 }
40
41 public ProfileInfo(String uri, byte[] data) {
42 this(uri);
43 this.base64 = true;
44 this.data = data;
45 }
46
47 public ProfileInfo(String uri, String content) {
48 this(uri);
49 this.base64 = false;
50 this.content = content;
51 }
52
53
54
55
56
57
58 public final boolean hasContent() {
59 return data != null || content != null;
60 }
61
62
63
64
65
66
67 public final String getUri() {
68 return uri;
69 }
70
71
72
73
74
75
76 public final boolean isBase64Encoded() {
77 return base64;
78 }
79
80
81
82
83
84
85
86
87 public final String getContent() {
88 if (content == null) {
89 throw new IllegalStateException("ProfileInfo does not have textual content");
90 }
91 return content;
92 }
93
94
95
96
97
98
99
100
101 public final byte[] getBinaryContent() {
102 if (data == null) {
103 throw new IllegalStateException("ProfileInfo does not have binary data");
104 }
105 return data;
106 }
107
108
109
110
111
112
113 public final void appendTo(StringBuilder builder) {
114 if (hasContent()) {
115 if (isBase64Encoded()) {
116 builder.append(ByteUtil.base64Encode(data));
117 } else {
118 builder.append(content);
119 }
120 }
121 }
122
123 @Override
124 public String toString() {
125 return "<profile uri='" + uri + "' />";
126 }
127
128 }