@@ -67,12 +67,12 @@ public final class BinaryPropertyListWriter {
67
67
* data that cannot be saved.
68
68
*/
69
69
BinaryPropertyListWriter (OutputStream outStr ) throws IOException {
70
- out = new BufferedOutputStream (outStr );
70
+ this . out = new BufferedOutputStream (outStr );
71
71
}
72
72
73
73
BinaryPropertyListWriter (OutputStream outStr , int version ) throws IOException {
74
74
this .version = version ;
75
- out = new BufferedOutputStream (outStr );
75
+ this . out = new BufferedOutputStream (outStr );
76
76
}
77
77
78
78
/**
@@ -143,6 +143,7 @@ public static void write(OutputStream out, NSObject root) throws IOException {
143
143
throw new IOException ("The given property list structure cannot be saved. " +
144
144
"The required version of the binary format (" + versionString + ") is not yet supported." );
145
145
}
146
+
146
147
BinaryPropertyListWriter w = new BinaryPropertyListWriter (out , minVersion );
147
148
w .write (root );
148
149
}
@@ -164,24 +165,24 @@ public static byte[] writeToArray(NSObject root) throws IOException {
164
165
165
166
void write (NSObject root ) throws IOException {
166
167
// magic bytes
167
- write (new byte []{'b' , 'p' , 'l' , 'i' , 's' , 't' });
168
+ this . write (new byte []{'b' , 'p' , 'l' , 'i' , 's' , 't' });
168
169
169
170
//version
170
171
switch (version ) {
171
172
case VERSION_00 : {
172
- write (new byte []{'0' , '0' });
173
+ this . write (new byte []{'0' , '0' });
173
174
break ;
174
175
}
175
176
case VERSION_10 : {
176
- write (new byte []{'1' , '0' });
177
+ this . write (new byte []{'1' , '0' });
177
178
break ;
178
179
}
179
180
case VERSION_15 : {
180
- write (new byte []{'1' , '5' });
181
+ this . write (new byte []{'1' , '5' });
181
182
break ;
182
183
}
183
184
case VERSION_20 : {
184
- write (new byte []{'2' , '0' });
185
+ this . write (new byte []{'2' , '0' });
185
186
break ;
186
187
}
187
188
default :
@@ -191,13 +192,13 @@ void write(NSObject root) throws IOException {
191
192
// assign IDs to all the objects.
192
193
root .assignIDs (this );
193
194
194
- idSizeInBytes = computeIdSizeInBytes (idMap .size ());
195
+ idSizeInBytes = computeIdSizeInBytes (this . idMap .size ());
195
196
196
197
// offsets of each object, indexed by ID
197
- long [] offsets = new long [idMap .size ()];
198
+ long [] offsets = new long [this . idMap .size ()];
198
199
199
200
// write each object, save offset
200
- for (Map .Entry <NSObject , Integer > entry : idMap .entrySet ()) {
201
+ for (Map .Entry <NSObject , Integer > entry : this . idMap .entrySet ()) {
201
202
NSObject obj = entry .getKey ();
202
203
int id = entry .getValue ();
203
204
offsets [id ] = count ;
@@ -212,36 +213,36 @@ void write(NSObject root) throws IOException {
212
213
long offsetTableOffset = count ;
213
214
int offsetSizeInBytes = computeOffsetSizeInBytes (count );
214
215
for (long offset : offsets ) {
215
- writeBytes (offset , offsetSizeInBytes );
216
+ this . writeBytes (offset , offsetSizeInBytes );
216
217
}
217
218
218
219
if (version != VERSION_15 ) {
219
220
// write trailer
220
221
// 6 null bytes
221
- write (new byte [6 ]);
222
+ this . write (new byte [6 ]);
222
223
// size of an offset
223
- write (offsetSizeInBytes );
224
+ this . write (offsetSizeInBytes );
224
225
// size of a ref
225
- write (idSizeInBytes );
226
+ this . write (this . idSizeInBytes );
226
227
// number of objects
227
- writeLong (idMap .size ());
228
+ this . writeLong (this . idMap .size ());
228
229
// top object
229
- writeLong (idMap .get (root ));
230
+ this . writeLong (this . idMap .get (root ));
230
231
// offset table offset
231
- writeLong (offsetTableOffset );
232
+ this . writeLong (offsetTableOffset );
232
233
}
233
234
234
- out .flush ();
235
+ this . out .flush ();
235
236
}
236
237
237
238
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 ());
240
241
}
241
242
}
242
243
243
244
int getID (NSObject obj ) {
244
- return idMap .get (obj );
245
+ return this . idMap .get (obj );
245
246
}
246
247
247
248
private static int computeIdSizeInBytes (int numberOfIds ) {
@@ -260,48 +261,48 @@ private int computeOffsetSizeInBytes(long maxOffset) {
260
261
void writeIntHeader (int kind , int value ) throws IOException {
261
262
assert value >= 0 ;
262
263
if (value < 15 ) {
263
- write ((kind << 4 ) + value );
264
+ this . write ((kind << 4 ) + value );
264
265
} 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 );
268
269
} 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 );
272
273
} 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 );
276
277
}
277
278
}
278
279
279
280
void write (int b ) throws IOException {
280
- out .write (b );
281
- count ++;
281
+ this . out .write (b );
282
+ this . count ++;
282
283
}
283
284
284
285
void write (byte [] bytes ) throws IOException {
285
- out .write (bytes );
286
- count += bytes .length ;
286
+ this . out .write (bytes );
287
+ this . count += bytes .length ;
287
288
}
288
289
289
290
void writeBytes (long value , int bytes ) throws IOException {
290
291
// write low-order bytes big-endian style
291
292
for (int i = bytes - 1 ; i >= 0 ; i --) {
292
- write ((int ) (value >> (8 * i )));
293
+ this . write ((int ) (value >> (8 * i )));
293
294
}
294
295
}
295
296
296
297
void writeID (int id ) throws IOException {
297
- writeBytes (id , idSizeInBytes );
298
+ this . writeBytes (id , this . idSizeInBytes );
298
299
}
299
300
300
301
void writeLong (long value ) throws IOException {
301
- writeBytes (value , 8 );
302
+ this . writeBytes (value , 8 );
302
303
}
303
304
304
305
void writeDouble (double value ) throws IOException {
305
- writeLong (Double .doubleToRawLongBits (value ));
306
+ this . writeLong (Double .doubleToRawLongBits (value ));
306
307
}
307
308
}
0 commit comments