You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

VersionedDataInputStream.java 2.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /* *******************************************************************
  2. * Copyright (c) 2005-2010 Contributors
  3. * All rights reserved.
  4. * This program and the accompanying materials are made available
  5. * under the terms of the Eclipse Public License v1.0
  6. * which accompanies this distribution and is available at
  7. * http://www.eclipse.org/legal/epl-v10.html
  8. *
  9. * Contributors:
  10. * Andy Clement (IBM, SpringSource)
  11. * ******************************************************************/
  12. package org.aspectj.weaver;
  13. import java.io.DataInputStream;
  14. import java.io.IOException;
  15. import java.io.InputStream;
  16. import org.aspectj.weaver.AjAttribute.WeaverVersionInfo;
  17. /**
  18. * Lightweight subclass of DataInputStream that knows what version of the weaver was used to construct the data in it. The input
  19. * stream has a constant pool reader attached which enables it to decode constant pool references found within the data being read.
  20. *
  21. * @author Andy Clement
  22. */
  23. public class VersionedDataInputStream extends DataInputStream {
  24. private WeaverVersionInfo version = new WeaverVersionInfo();// assume we are the latest unless something tells us otherwise...
  25. private ConstantPoolReader constantPoolReader;
  26. public VersionedDataInputStream(InputStream is, ConstantPoolReader constantPoolReader) {
  27. super(is);
  28. this.constantPoolReader = constantPoolReader;
  29. }
  30. public int getMajorVersion() {
  31. return version.getMajorVersion();
  32. }
  33. public int getMinorVersion() {
  34. return version.getMinorVersion();
  35. }
  36. public long getBuildstamp() {
  37. return version.getBuildstamp();
  38. }
  39. public void setVersion(WeaverVersionInfo version) {
  40. this.version = version;
  41. }
  42. public String readUtf8(int cpIndex) {
  43. if (constantPoolReader == null) {
  44. throw new IllegalStateException();
  45. }
  46. if (cpIndex < 0) {
  47. throw new IllegalStateException(cpIndex + "");
  48. }
  49. return constantPoolReader.readUtf8(cpIndex);
  50. }
  51. public boolean canDecompress() {
  52. return constantPoolReader != null;
  53. }
  54. public boolean isAtLeast169() {
  55. return getMajorVersion() >= AjAttribute.WeaverVersionInfo.WEAVER_VERSION_AJ169;
  56. }
  57. public String readPath() throws IOException {
  58. return readUtf8(readShort());
  59. }
  60. public String readSignature() throws IOException {
  61. return readUtf8(readShort());
  62. }
  63. public UnresolvedType readSignatureAsUnresolvedType() throws IOException {
  64. return UnresolvedType.forSignature(readUtf8(readShort()));
  65. }
  66. public String toString() {
  67. return "VersionedDataInputStream: version=" + version + " constantPoolReader?" + (constantPoolReader != null);
  68. }
  69. }