From f2df9e4d82faf7f3577bc1efd49115eb9c02f336 Mon Sep 17 00:00:00 2001 From: aclement Date: Tue, 18 May 2010 19:46:36 +0000 Subject: [PATCH] passing the correct compressors around (for small class file sizes enhancement) --- .../src/org/aspectj/weaver/AjAttribute.java | 15 ++++--- .../weaver/VersionedDataInputStream.java | 44 +++++++++++++++++-- 2 files changed, 50 insertions(+), 9 deletions(-) diff --git a/org.aspectj.matcher/src/org/aspectj/weaver/AjAttribute.java b/org.aspectj.matcher/src/org/aspectj/weaver/AjAttribute.java index 07149a518..982a5ab8c 100644 --- a/org.aspectj.matcher/src/org/aspectj/weaver/AjAttribute.java +++ b/org.aspectj.matcher/src/org/aspectj/weaver/AjAttribute.java @@ -52,10 +52,10 @@ public abstract class AjAttribute { /** * Just writes the contents */ - public byte[] getBytes() { + public byte[] getBytes(ConstantPoolWriter compressor) { try { ByteArrayOutputStream b0 = new ByteArrayOutputStream(); - CompressingDataOutputStream s0 = new CompressingDataOutputStream(b0); + CompressingDataOutputStream s0 = new CompressingDataOutputStream(b0, compressor); write(s0); s0.close(); return b0.toByteArray(); @@ -67,10 +67,12 @@ public abstract class AjAttribute { /** * Writes the full attribute, i.e. name_index, length, and contents + * + * @param constantPool */ - public byte[] getAllBytes(short nameIndex) { + public byte[] getAllBytes(short nameIndex, ConstantPoolWriter dataCompressor) { try { - byte[] bytes = getBytes(); + byte[] bytes = getBytes(dataCompressor); ByteArrayOutputStream b0 = new ByteArrayOutputStream(); DataOutputStream s0 = new DataOutputStream(b0); @@ -86,12 +88,13 @@ public abstract class AjAttribute { } } - public static AjAttribute read(AjAttribute.WeaverVersionInfo v, String name, byte[] bytes, ISourceContext context, World w) { + public static AjAttribute read(AjAttribute.WeaverVersionInfo v, String name, byte[] bytes, ISourceContext context, World w, + ConstantPoolReader dataDecompressor) { try { if (bytes == null) { bytes = new byte[0]; } - VersionedDataInputStream s = new VersionedDataInputStream(new ByteArrayInputStream(bytes)); + VersionedDataInputStream s = new VersionedDataInputStream(new ByteArrayInputStream(bytes), dataDecompressor); s.setVersion(v); if (name.equals(Aspect.AttributeName)) { return new Aspect(PerClause.readPerClause(s, context)); diff --git a/org.aspectj.matcher/src/org/aspectj/weaver/VersionedDataInputStream.java b/org.aspectj.matcher/src/org/aspectj/weaver/VersionedDataInputStream.java index 160d7018b..8e4d297d3 100644 --- a/org.aspectj.matcher/src/org/aspectj/weaver/VersionedDataInputStream.java +++ b/org.aspectj.matcher/src/org/aspectj/weaver/VersionedDataInputStream.java @@ -1,5 +1,5 @@ /* ******************************************************************* - * Copyright (c) 2005 IBM + * Copyright (c) 2005-2010 Contributors * All rights reserved. * This program and the accompanying materials are made available * under the terms of the Eclipse Public License v1.0 @@ -7,26 +7,38 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * Andy Clement initial implementation + * Andy Clement (IBM, SpringSource) * ******************************************************************/ package org.aspectj.weaver; import java.io.DataInputStream; +import java.io.IOException; import java.io.InputStream; import org.aspectj.weaver.AjAttribute.WeaverVersionInfo; /** - * Lightweight subclass of DataInputStream that knows what version of the weaver was used to construct the data in it. + * Lightweight subclass of DataInputStream that knows what version of the weaver was used to construct the data in it. The input + * stream has a constant pool reader attached which enables it to decode constant pool references found within the data being read. + * + * @author Andy Clement */ public class VersionedDataInputStream extends DataInputStream { + private WeaverVersionInfo version = new WeaverVersionInfo();// assume we are the latest unless something tells us otherwise... + private ConstantPoolReader constantPoolReader; + public VersionedDataInputStream(InputStream is) { super(is); } + public VersionedDataInputStream(InputStream is, ConstantPoolReader constantPoolReader) { + super(is); + this.constantPoolReader = constantPoolReader; + } + public int getMajorVersion() { return version.getMajorVersion(); } @@ -42,4 +54,30 @@ public class VersionedDataInputStream extends DataInputStream { public void setVersion(WeaverVersionInfo version) { this.version = version; } + + public String accessUtf8(int cpIndex) { + if (constantPoolReader == null) { + throw new IllegalStateException(); + } + if (cpIndex < 0) { + throw new IllegalStateException(cpIndex + ""); + } + return constantPoolReader.readUtf8(cpIndex); + } + + public boolean canDecompress() { + return constantPoolReader != null; + } + + public boolean isAtLeast169() { + return getMajorVersion() >= AjAttribute.WeaverVersionInfo.WEAVER_VERSION_AJ169; + } + + public String readPath() throws IOException { + return accessUtf8(readShort()); + } + + public String readSignature() throws IOException { + return accessUtf8(readShort()); + } } \ No newline at end of file -- 2.39.5