281 return map.hashCode();
282 }
283
284 /**
285 * Returns a copy of the Attributes, implemented as follows:
286 * <pre>
287 * public Object clone() { return new Attributes(this); }
288 * </pre>
289 * Since the attribute names and values are themselves immutable,
290 * the Attributes returned can be safely modified without affecting
291 * the original.
292 */
293 public Object clone() {
294 return new Attributes(this);
295 }
296
297 /*
298 * Writes the current attributes to the specified data output stream.
299 * XXX Need to handle UTF8 values and break up lines longer than 72 bytes
300 */
301 void write(DataOutputStream os) throws IOException {
302 for (Entry<Object, Object> e : entrySet()) {
303 StringBuffer buffer = new StringBuffer(
304 ((Name) e.getKey()).toString());
305 buffer.append(": ");
306
307 String value = (String) e.getValue();
308 if (value != null) {
309 byte[] vb = value.getBytes("UTF8");
310 value = new String(vb, 0, 0, vb.length);
311 }
312 buffer.append(value);
313
314 buffer.append("\r\n");
315 Manifest.make72Safe(buffer);
316 os.writeBytes(buffer.toString());
317 }
318 os.writeBytes("\r\n");
319 }
320
321 /*
322 * Writes the current attributes to the specified data output stream,
323 * make sure to write out the MANIFEST_VERSION or SIGNATURE_VERSION
324 * attributes first.
325 *
326 * XXX Need to handle UTF8 values and break up lines longer than 72 bytes
327 */
328 void writeMain(DataOutputStream out) throws IOException
329 {
330 // write out the *-Version header first, if it exists
331 String vername = Name.MANIFEST_VERSION.toString();
332 String version = getValue(vername);
333 if (version == null) {
334 vername = Name.SIGNATURE_VERSION.toString();
335 version = getValue(vername);
336 }
337
338 if (version != null) {
339 out.writeBytes(vername+": "+version+"\r\n");
340 }
341
342 // write out all attributes except for the version
343 // we wrote out earlier
344 for (Entry<Object, Object> e : entrySet()) {
345 String name = ((Name) e.getKey()).toString();
346 if ((version != null) && !(name.equalsIgnoreCase(vername))) {
347
350
351 String value = (String) e.getValue();
352 if (value != null) {
353 byte[] vb = value.getBytes("UTF8");
354 value = new String(vb, 0, 0, vb.length);
355 }
356 buffer.append(value);
357
358 buffer.append("\r\n");
359 Manifest.make72Safe(buffer);
360 out.writeBytes(buffer.toString());
361 }
362 }
363 out.writeBytes("\r\n");
364 }
365
366 /*
367 * Reads attributes from the specified input stream.
368 * XXX Need to handle UTF8 values.
369 */
370 void read(Manifest.FastInputStream is, byte[] lbuf) throws IOException {
371 String name = null, value = null;
372 byte[] lastline = null;
373
374 int len;
375 while ((len = is.readLine(lbuf)) != -1) {
376 boolean lineContinued = false;
377 if (lbuf[--len] != '\n') {
378 throw new IOException("line too long");
379 }
380 if (len > 0 && lbuf[len-1] == '\r') {
381 --len;
382 }
383 if (len == 0) {
384 break;
385 }
386 int i = 0;
387 if (lbuf[0] == ' ') {
388 // continuation of previous line
389 if (name == null) {
|
281 return map.hashCode();
282 }
283
284 /**
285 * Returns a copy of the Attributes, implemented as follows:
286 * <pre>
287 * public Object clone() { return new Attributes(this); }
288 * </pre>
289 * Since the attribute names and values are themselves immutable,
290 * the Attributes returned can be safely modified without affecting
291 * the original.
292 */
293 public Object clone() {
294 return new Attributes(this);
295 }
296
297 /*
298 * Writes the current attributes to the specified data output stream.
299 * XXX Need to handle UTF8 values and break up lines longer than 72 bytes
300 */
301 @SuppressWarnings("deprecation")
302 void write(DataOutputStream os) throws IOException {
303 for (Entry<Object, Object> e : entrySet()) {
304 StringBuffer buffer = new StringBuffer(
305 ((Name) e.getKey()).toString());
306 buffer.append(": ");
307
308 String value = (String) e.getValue();
309 if (value != null) {
310 byte[] vb = value.getBytes("UTF8");
311 value = new String(vb, 0, 0, vb.length);
312 }
313 buffer.append(value);
314
315 buffer.append("\r\n");
316 Manifest.make72Safe(buffer);
317 os.writeBytes(buffer.toString());
318 }
319 os.writeBytes("\r\n");
320 }
321
322 /*
323 * Writes the current attributes to the specified data output stream,
324 * make sure to write out the MANIFEST_VERSION or SIGNATURE_VERSION
325 * attributes first.
326 *
327 * XXX Need to handle UTF8 values and break up lines longer than 72 bytes
328 */
329 @SuppressWarnings("deprecation")
330 void writeMain(DataOutputStream out) throws IOException
331 {
332 // write out the *-Version header first, if it exists
333 String vername = Name.MANIFEST_VERSION.toString();
334 String version = getValue(vername);
335 if (version == null) {
336 vername = Name.SIGNATURE_VERSION.toString();
337 version = getValue(vername);
338 }
339
340 if (version != null) {
341 out.writeBytes(vername+": "+version+"\r\n");
342 }
343
344 // write out all attributes except for the version
345 // we wrote out earlier
346 for (Entry<Object, Object> e : entrySet()) {
347 String name = ((Name) e.getKey()).toString();
348 if ((version != null) && !(name.equalsIgnoreCase(vername))) {
349
352
353 String value = (String) e.getValue();
354 if (value != null) {
355 byte[] vb = value.getBytes("UTF8");
356 value = new String(vb, 0, 0, vb.length);
357 }
358 buffer.append(value);
359
360 buffer.append("\r\n");
361 Manifest.make72Safe(buffer);
362 out.writeBytes(buffer.toString());
363 }
364 }
365 out.writeBytes("\r\n");
366 }
367
368 /*
369 * Reads attributes from the specified input stream.
370 * XXX Need to handle UTF8 values.
371 */
372 @SuppressWarnings("deprecation")
373 void read(Manifest.FastInputStream is, byte[] lbuf) throws IOException {
374 String name = null, value = null;
375 byte[] lastline = null;
376
377 int len;
378 while ((len = is.readLine(lbuf)) != -1) {
379 boolean lineContinued = false;
380 if (lbuf[--len] != '\n') {
381 throw new IOException("line too long");
382 }
383 if (len > 0 && lbuf[len-1] == '\r') {
384 --len;
385 }
386 if (len == 0) {
387 break;
388 }
389 int i = 0;
390 if (lbuf[0] == ' ') {
391 // continuation of previous line
392 if (name == null) {
|