Skip to content

Commit 86217fe

Browse files
committed
Improve documentation and apply some code styling
1 parent 743ffec commit 86217fe

12 files changed

+459
-483
lines changed

src/main/java/com/dd/plist/ASCIIPropertyListParser.java

+131-114
Large diffs are not rendered by default.

src/main/java/com/dd/plist/BinaryPropertyListParser.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public final class BinaryPropertyListParser {
5050
private int minorVersion;
5151

5252
/**
53-
* property list in bytes
53+
* The property list data.
5454
*/
5555
private byte[] bytes;
5656

src/main/java/com/dd/plist/BinaryPropertyListWriter.java

+40-39
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,12 @@ public final class BinaryPropertyListWriter {
6767
* data that cannot be saved.
6868
*/
6969
BinaryPropertyListWriter(OutputStream outStr) throws IOException {
70-
out = new BufferedOutputStream(outStr);
70+
this.out = new BufferedOutputStream(outStr);
7171
}
7272

7373
BinaryPropertyListWriter(OutputStream outStr, int version) throws IOException {
7474
this.version = version;
75-
out = new BufferedOutputStream(outStr);
75+
this.out = new BufferedOutputStream(outStr);
7676
}
7777

7878
/**
@@ -143,6 +143,7 @@ public static void write(OutputStream out, NSObject root) throws IOException {
143143
throw new IOException("The given property list structure cannot be saved. " +
144144
"The required version of the binary format (" + versionString + ") is not yet supported.");
145145
}
146+
146147
BinaryPropertyListWriter w = new BinaryPropertyListWriter(out, minVersion);
147148
w.write(root);
148149
}
@@ -164,24 +165,24 @@ public static byte[] writeToArray(NSObject root) throws IOException {
164165

165166
void write(NSObject root) throws IOException {
166167
// magic bytes
167-
write(new byte[]{'b', 'p', 'l', 'i', 's', 't'});
168+
this.write(new byte[]{'b', 'p', 'l', 'i', 's', 't'});
168169

169170
//version
170171
switch (version) {
171172
case VERSION_00: {
172-
write(new byte[]{'0', '0'});
173+
this.write(new byte[]{'0', '0'});
173174
break;
174175
}
175176
case VERSION_10: {
176-
write(new byte[]{'1', '0'});
177+
this.write(new byte[]{'1', '0'});
177178
break;
178179
}
179180
case VERSION_15: {
180-
write(new byte[]{'1', '5'});
181+
this.write(new byte[]{'1', '5'});
181182
break;
182183
}
183184
case VERSION_20: {
184-
write(new byte[]{'2', '0'});
185+
this.write(new byte[]{'2', '0'});
185186
break;
186187
}
187188
default:
@@ -191,13 +192,13 @@ void write(NSObject root) throws IOException {
191192
// assign IDs to all the objects.
192193
root.assignIDs(this);
193194

194-
idSizeInBytes = computeIdSizeInBytes(idMap.size());
195+
idSizeInBytes = computeIdSizeInBytes(this.idMap.size());
195196

196197
// offsets of each object, indexed by ID
197-
long[] offsets = new long[idMap.size()];
198+
long[] offsets = new long[this.idMap.size()];
198199

199200
// write each object, save offset
200-
for (Map.Entry<NSObject, Integer> entry : idMap.entrySet()) {
201+
for (Map.Entry<NSObject, Integer> entry : this.idMap.entrySet()) {
201202
NSObject obj = entry.getKey();
202203
int id = entry.getValue();
203204
offsets[id] = count;
@@ -212,36 +213,36 @@ void write(NSObject root) throws IOException {
212213
long offsetTableOffset = count;
213214
int offsetSizeInBytes = computeOffsetSizeInBytes(count);
214215
for (long offset : offsets) {
215-
writeBytes(offset, offsetSizeInBytes);
216+
this.writeBytes(offset, offsetSizeInBytes);
216217
}
217218

218219
if (version != VERSION_15) {
219220
// write trailer
220221
// 6 null bytes
221-
write(new byte[6]);
222+
this.write(new byte[6]);
222223
// size of an offset
223-
write(offsetSizeInBytes);
224+
this.write(offsetSizeInBytes);
224225
// size of a ref
225-
write(idSizeInBytes);
226+
this.write(this.idSizeInBytes);
226227
// number of objects
227-
writeLong(idMap.size());
228+
this.writeLong(this.idMap.size());
228229
// top object
229-
writeLong(idMap.get(root));
230+
this.writeLong(this.idMap.get(root));
230231
// offset table offset
231-
writeLong(offsetTableOffset);
232+
this.writeLong(offsetTableOffset);
232233
}
233234

234-
out.flush();
235+
this.out.flush();
235236
}
236237

237238
void assignID(NSObject obj) {
238-
if (!idMap.containsKey(obj)) {
239-
idMap.put(obj, idMap.size());
239+
if (!this.idMap.containsKey(obj)) {
240+
this.idMap.put(obj, this.idMap.size());
240241
}
241242
}
242243

243244
int getID(NSObject obj) {
244-
return idMap.get(obj);
245+
return this.idMap.get(obj);
245246
}
246247

247248
private static int computeIdSizeInBytes(int numberOfIds) {
@@ -260,48 +261,48 @@ private int computeOffsetSizeInBytes(long maxOffset) {
260261
void writeIntHeader(int kind, int value) throws IOException {
261262
assert value >= 0;
262263
if (value < 15) {
263-
write((kind << 4) + value);
264+
this.write((kind << 4) + value);
264265
} else if (value < 256) {
265-
write((kind << 4) + 15);
266-
write(0x10);
267-
writeBytes(value, 1);
266+
this.write((kind << 4) + 15);
267+
this.write(0x10);
268+
this.writeBytes(value, 1);
268269
} else if (value < 65536) {
269-
write((kind << 4) + 15);
270-
write(0x11);
271-
writeBytes(value, 2);
270+
this.write((kind << 4) + 15);
271+
this.write(0x11);
272+
this.writeBytes(value, 2);
272273
} else {
273-
write((kind << 4) + 15);
274-
write(0x12);
275-
writeBytes(value, 4);
274+
this.write((kind << 4) + 15);
275+
this.write(0x12);
276+
this.writeBytes(value, 4);
276277
}
277278
}
278279

279280
void write(int b) throws IOException {
280-
out.write(b);
281-
count++;
281+
this.out.write(b);
282+
this.count++;
282283
}
283284

284285
void write(byte[] bytes) throws IOException {
285-
out.write(bytes);
286-
count += bytes.length;
286+
this.out.write(bytes);
287+
this.count += bytes.length;
287288
}
288289

289290
void writeBytes(long value, int bytes) throws IOException {
290291
// write low-order bytes big-endian style
291292
for (int i = bytes - 1; i >= 0; i--) {
292-
write((int) (value >> (8 * i)));
293+
this.write((int) (value >> (8 * i)));
293294
}
294295
}
295296

296297
void writeID(int id) throws IOException {
297-
writeBytes(id, idSizeInBytes);
298+
this.writeBytes(id, this.idSizeInBytes);
298299
}
299300

300301
void writeLong(long value) throws IOException {
301-
writeBytes(value, 8);
302+
this.writeBytes(value, 8);
302303
}
303304

304305
void writeDouble(double value) throws IOException {
305-
writeLong(Double.doubleToRawLongBits(value));
306+
this.writeLong(Double.doubleToRawLongBits(value));
306307
}
307308
}

0 commit comments

Comments
 (0)