/**
* 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();
/**
* 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);
}
}
- 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));
/* *******************************************************************
- * 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
* 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();
}
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