25 |
25 |
26 package com.sun.tools.javap; |
26 package com.sun.tools.javap; |
27 |
27 |
28 import java.io.EOFException; |
28 import java.io.EOFException; |
29 import java.io.FileNotFoundException; |
29 import java.io.FileNotFoundException; |
|
30 import java.io.FilterInputStream; |
|
31 import java.io.InputStream; |
30 import java.io.IOException; |
32 import java.io.IOException; |
31 import java.io.OutputStream; |
33 import java.io.OutputStream; |
32 import java.io.PrintWriter; |
34 import java.io.PrintWriter; |
33 import java.io.StringWriter; |
35 import java.io.StringWriter; |
34 import java.io.Writer; |
36 import java.io.Writer; |
|
37 import java.security.DigestInputStream; |
|
38 import java.security.MessageDigest; |
35 import java.text.MessageFormat; |
39 import java.text.MessageFormat; |
36 import java.util.ArrayList; |
40 import java.util.ArrayList; |
37 import java.util.Arrays; |
41 import java.util.Arrays; |
38 import java.util.HashMap; |
42 import java.util.HashMap; |
39 import java.util.Iterator; |
43 import java.util.Iterator; |
194 }, |
198 }, |
195 |
199 |
196 new Option(false, "-verify", "-verify-verbose") { |
200 new Option(false, "-verify", "-verify-verbose") { |
197 void process(JavapTask task, String opt, String arg) throws BadArgs { |
201 void process(JavapTask task, String opt, String arg) throws BadArgs { |
198 throw task.new BadArgs("err.verify.not.supported"); |
202 throw task.new BadArgs("err.verify.not.supported"); |
|
203 } |
|
204 }, |
|
205 |
|
206 new Option(false, "-sysinfo") { |
|
207 void process(JavapTask task, String opt, String arg) { |
|
208 task.options.sysInfo = true; |
199 } |
209 } |
200 }, |
210 }, |
201 |
211 |
202 new Option(false, "-Xold") { |
212 new Option(false, "-Xold") { |
203 void process(JavapTask task, String opt, String arg) throws BadArgs { |
213 void process(JavapTask task, String opt, String arg) throws BadArgs { |
492 } |
502 } |
493 } |
503 } |
494 Attribute.Factory attributeFactory = new Attribute.Factory(); |
504 Attribute.Factory attributeFactory = new Attribute.Factory(); |
495 attributeFactory.setCompat(options.compat); |
505 attributeFactory.setCompat(options.compat); |
496 attributeFactory.setJSR277(options.jsr277); |
506 attributeFactory.setJSR277(options.jsr277); |
497 ClassFile cf = ClassFile.read(fo.openInputStream(), attributeFactory); |
507 |
|
508 InputStream in = fo.openInputStream(); |
|
509 SizeInputStream sizeIn = null; |
|
510 MessageDigest md = null; |
|
511 if (options.sysInfo || options.verbose) { |
|
512 md = MessageDigest.getInstance("MD5"); |
|
513 in = new DigestInputStream(in, md); |
|
514 in = sizeIn = new SizeInputStream(in); |
|
515 } |
|
516 |
|
517 ClassFile cf = ClassFile.read(in, attributeFactory); |
|
518 |
|
519 if (options.sysInfo || options.verbose) { |
|
520 classWriter.setFile(fo.toUri()); |
|
521 classWriter.setLastModified(fo.getLastModified()); |
|
522 classWriter.setDigest("MD5", md.digest()); |
|
523 classWriter.setFileSize(sizeIn.size()); |
|
524 } |
|
525 |
498 classWriter.write(cf); |
526 classWriter.write(cf); |
|
527 |
499 } catch (ConstantPoolException e) { |
528 } catch (ConstantPoolException e) { |
500 diagnosticListener.report(createDiagnostic("err.bad.constant.pool", className, e.getLocalizedMessage())); |
529 diagnosticListener.report(createDiagnostic("err.bad.constant.pool", className, e.getLocalizedMessage())); |
501 ok = false; |
530 ok = false; |
502 } catch (EOFException e) { |
531 } catch (EOFException e) { |
503 diagnosticListener.report(createDiagnostic("err.end.of.file", className)); |
532 diagnosticListener.report(createDiagnostic("err.end.of.file", className)); |
663 //ResourceBundle bundle; |
692 //ResourceBundle bundle; |
664 Locale task_locale; |
693 Locale task_locale; |
665 Map<Locale, ResourceBundle> bundles; |
694 Map<Locale, ResourceBundle> bundles; |
666 |
695 |
667 private static final String progname = "javap"; |
696 private static final String progname = "javap"; |
|
697 |
|
698 private static class SizeInputStream extends FilterInputStream { |
|
699 SizeInputStream(InputStream in) { |
|
700 super(in); |
|
701 } |
|
702 |
|
703 int size() { |
|
704 return size; |
|
705 } |
|
706 |
|
707 @Override |
|
708 public int read(byte[] buf, int offset, int length) throws IOException { |
|
709 int n = super.read(buf, offset, length); |
|
710 if (n > 0) |
|
711 size += n; |
|
712 return n; |
|
713 } |
|
714 |
|
715 @Override |
|
716 public int read() throws IOException { |
|
717 int b = super.read(); |
|
718 size += 1; |
|
719 return b; |
|
720 } |
|
721 |
|
722 private int size; |
|
723 } |
668 } |
724 } |