296 |
298 |
297 /* |
299 /* |
298 * Writes the current attributes to the specified data output stream. |
300 * 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 |
301 * XXX Need to handle UTF8 values and break up lines longer than 72 bytes |
300 */ |
302 */ |
301 @SuppressWarnings("deprecation") |
303 void write(DataOutputStream out) throws IOException { |
302 void write(DataOutputStream os) throws IOException { |
304 StringBuilder buffer = new StringBuilder(72); |
303 for (Entry<Object, Object> e : entrySet()) { |
305 for (Entry<Object, Object> e : entrySet()) { |
304 StringBuffer buffer = new StringBuffer( |
306 buffer.setLength(0); |
305 ((Name) e.getKey()).toString()); |
307 buffer.append(e.getKey().toString()); |
306 buffer.append(": "); |
308 buffer.append(": "); |
307 |
309 buffer.append(e.getValue()); |
308 String value = (String) e.getValue(); |
310 Manifest.println72(out, buffer.toString()); |
309 if (value != null) { |
311 } |
310 byte[] vb = value.getBytes("UTF8"); |
312 Manifest.println(out); // empty line after individual section |
311 value = new String(vb, 0, 0, vb.length); |
|
312 } |
|
313 buffer.append(value); |
|
314 |
|
315 Manifest.make72Safe(buffer); |
|
316 buffer.append("\r\n"); |
|
317 os.writeBytes(buffer.toString()); |
|
318 } |
|
319 os.writeBytes("\r\n"); |
|
320 } |
313 } |
321 |
314 |
322 /* |
315 /* |
323 * Writes the current attributes to the specified data output stream, |
316 * Writes the current attributes to the specified data output stream, |
324 * make sure to write out the MANIFEST_VERSION or SIGNATURE_VERSION |
317 * make sure to write out the MANIFEST_VERSION or SIGNATURE_VERSION |
325 * attributes first. |
318 * attributes first. |
326 * |
319 * |
327 * XXX Need to handle UTF8 values and break up lines longer than 72 bytes |
320 * XXX Need to handle UTF8 values and break up lines longer than 72 bytes |
328 */ |
321 */ |
329 @SuppressWarnings("deprecation") |
322 void writeMain(DataOutputStream out) throws IOException { |
330 void writeMain(DataOutputStream out) throws IOException |
323 StringBuilder buffer = new StringBuilder(72); |
331 { |
324 |
332 // write out the *-Version header first, if it exists |
325 // write out the *-Version header first, if it exists |
333 String vername = Name.MANIFEST_VERSION.toString(); |
326 String vername = Name.MANIFEST_VERSION.toString(); |
334 String version = getValue(vername); |
327 String version = getValue(vername); |
335 if (version == null) { |
328 if (version == null) { |
336 vername = Name.SIGNATURE_VERSION.toString(); |
329 vername = Name.SIGNATURE_VERSION.toString(); |
337 version = getValue(vername); |
330 version = getValue(vername); |
338 } |
331 } |
339 |
332 |
340 if (version != null) { |
333 if (version != null) { |
341 out.writeBytes(vername+": "+version+"\r\n"); |
334 buffer.append(vername); |
|
335 buffer.append(": "); |
|
336 buffer.append(version); |
|
337 out.write(buffer.toString().getBytes(UTF_8)); |
|
338 Manifest.println(out); |
342 } |
339 } |
343 |
340 |
344 // write out all attributes except for the version |
341 // write out all attributes except for the version |
345 // we wrote out earlier |
342 // we wrote out earlier |
346 for (Entry<Object, Object> e : entrySet()) { |
343 for (Entry<Object, Object> e : entrySet()) { |
347 String name = ((Name) e.getKey()).toString(); |
344 String name = ((Name) e.getKey()).toString(); |
348 if ((version != null) && !(name.equalsIgnoreCase(vername))) { |
345 if ((version != null) && !(name.equalsIgnoreCase(vername))) { |
349 |
346 buffer.setLength(0); |
350 StringBuffer buffer = new StringBuffer(name); |
347 buffer.append(name); |
351 buffer.append(": "); |
348 buffer.append(": "); |
352 |
349 buffer.append(e.getValue()); |
353 String value = (String) e.getValue(); |
350 Manifest.println72(out, buffer.toString()); |
354 if (value != null) { |
351 } |
355 byte[] vb = value.getBytes("UTF8"); |
352 } |
356 value = new String(vb, 0, 0, vb.length); |
353 |
357 } |
354 Manifest.println(out); // empty line after main attributes section |
358 buffer.append(value); |
|
359 |
|
360 Manifest.make72Safe(buffer); |
|
361 buffer.append("\r\n"); |
|
362 out.writeBytes(buffer.toString()); |
|
363 } |
|
364 } |
|
365 out.writeBytes("\r\n"); |
|
366 } |
355 } |
367 |
356 |
368 /* |
357 /* |
369 * Reads attributes from the specified input stream. |
358 * Reads attributes from the specified input stream. |
370 * XXX Need to handle UTF8 values. |
|
371 */ |
359 */ |
372 void read(Manifest.FastInputStream is, byte[] lbuf) throws IOException { |
360 void read(Manifest.FastInputStream is, byte[] lbuf) throws IOException { |
373 read(is, lbuf, null, 0); |
361 read(is, lbuf, null, 0); |
374 } |
362 } |
375 |
363 |
376 @SuppressWarnings("deprecation") |
|
377 int read(Manifest.FastInputStream is, byte[] lbuf, String filename, int lineNumber) throws IOException { |
364 int read(Manifest.FastInputStream is, byte[] lbuf, String filename, int lineNumber) throws IOException { |
378 String name = null, value; |
365 String name = null, value; |
379 byte[] lastline = null; |
366 byte[] lastline = null; |
380 |
367 |
381 int len; |
368 int len; |
420 } |
407 } |
421 if (lbuf[i++] != ' ') { |
408 if (lbuf[i++] != ' ') { |
422 throw new IOException("invalid header field (" |
409 throw new IOException("invalid header field (" |
423 + Manifest.getErrorPosition(filename, lineNumber) + ")"); |
410 + Manifest.getErrorPosition(filename, lineNumber) + ")"); |
424 } |
411 } |
425 name = new String(lbuf, 0, 0, i - 2); |
412 name = new String(lbuf, 0, i - 2, UTF_8); |
426 if (is.peek() == ' ') { |
413 if (is.peek() == ' ') { |
427 lastline = new byte[len - i]; |
414 lastline = new byte[len - i]; |
428 System.arraycopy(lbuf, i, lastline, 0, len - i); |
415 System.arraycopy(lbuf, i, lastline, 0, len - i); |
429 continue; |
416 continue; |
430 } |
417 } |
431 value = new String(lbuf, i, len - i, "UTF8"); |
418 value = new String(lbuf, i, len - i, UTF_8); |
432 } |
419 } |
433 try { |
420 try { |
434 if ((putValue(name, value) != null) && (!lineContinued)) { |
421 if ((putValue(name, value) != null) && (!lineContinued)) { |
435 PlatformLogger.getLogger("java.util.jar").warning( |
422 PlatformLogger.getLogger("java.util.jar").warning( |
436 "Duplicate name in Manifest: " + name |
423 "Duplicate name in Manifest: " + name |