You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by sj...@apache.org on 2008/07/22 18:28:11 UTC
svn commit: r678796 - in
/harmony/enhanced/classlib/trunk/modules/pack200/src:
main/java/org/apache/harmony/unpack200/
test/java/org/apache/harmony/unpack200/tests/
Author: sjanuary
Date: Tue Jul 22 09:28:09 2008
New Revision: 678796
URL: http://svn.apache.org/viewvc?rev=678796&view=rev
Log:
Apply patch for HARMONY-5916 ([classlib][pack200] Isolating I/O and processing stages )
Modified:
harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/unpack200/Archive.java
harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/unpack200/AttrDefinitionBands.java
harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/unpack200/BandSet.java
harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/unpack200/BcBands.java
harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/unpack200/ClassBands.java
harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/unpack200/CpBands.java
harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/unpack200/FileBands.java
harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/unpack200/IcBands.java
harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/unpack200/NewAttributeBands.java
harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/unpack200/Segment.java
harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/unpack200/SegmentHeader.java
harmony/enhanced/classlib/trunk/modules/pack200/src/test/java/org/apache/harmony/unpack200/tests/BandSetTest.java
Modified: harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/unpack200/Archive.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/unpack200/Archive.java?rev=678796&r1=678795&r2=678796&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/unpack200/Archive.java (original)
+++ harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/unpack200/Archive.java Tue Jul 22 09:28:09 2008
@@ -149,6 +149,8 @@
segment
.setLogStream(logFile != null ? (OutputStream) logFile
: (OutputStream) System.out);
+ segment.setPreRead(false);
+
if (i == 1) {
segment.log(Segment.LOG_LEVEL_VERBOSE,
"Unpacking from " + inputFileName + " to "
Modified: harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/unpack200/AttrDefinitionBands.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/unpack200/AttrDefinitionBands.java?rev=678796&r1=678795&r2=678796&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/unpack200/AttrDefinitionBands.java (original)
+++ harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/unpack200/AttrDefinitionBands.java Tue Jul 22 09:28:09 2008
@@ -48,7 +48,7 @@
*
* @see org.apache.harmony.unpack200.BandSet#unpack(java.io.InputStream)
*/
- public void unpack(InputStream in) throws IOException, Pack200Exception {
+ public void read(InputStream in) throws IOException, Pack200Exception {
int attributeDefinitionCount = header.getAttributeDefinitionCount();
attributeDefinitionHeader = decodeBandInt("attr_definition_headers",
in, Codec.BYTE1, attributeDefinitionCount);
@@ -78,6 +78,10 @@
attributeDefinitionMap.checkMap();
}
+ public void unpack() throws Pack200Exception, IOException {
+
+ }
+
public AttributeLayoutMap getAttributeDefinitionMap() {
return attributeDefinitionMap;
}
Modified: harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/unpack200/BandSet.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/unpack200/BandSet.java?rev=678796&r1=678795&r2=678796&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/unpack200/BandSet.java (original)
+++ harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/unpack200/BandSet.java Tue Jul 22 09:28:09 2008
@@ -43,9 +43,16 @@
*/
public abstract class BandSet {
- public abstract void unpack(InputStream inputStream) throws IOException,
+ public abstract void read(InputStream inputStream) throws IOException,
Pack200Exception;
+ public abstract void unpack() throws IOException, Pack200Exception;
+
+ public void unpack(InputStream in) throws IOException, Pack200Exception {
+ read(in);
+ unpack();
+ }
+
protected Segment segment;
protected SegmentHeader header;
Modified: harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/unpack200/BcBands.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/unpack200/BcBands.java?rev=678796&r1=678795&r2=678796&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/unpack200/BcBands.java (original)
+++ harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/unpack200/BcBands.java Tue Jul 22 09:28:09 2008
@@ -69,6 +69,8 @@
private int[] bcEscSize;
private int[][] bcEscByte;
+ private List wideByteCodes;
+
/**
* @param segment
*/
@@ -81,17 +83,12 @@
*
* @see org.apache.harmony.unpack200.BandSet#unpack(java.io.InputStream)
*/
- public void unpack(InputStream in) throws IOException, Pack200Exception {
+ public void read(InputStream in) throws IOException, Pack200Exception {
AttributeLayoutMap attributeDefinitionMap = segment
.getAttrDefinitionBands().getAttributeDefinitionMap();
int classCount = header.getClassCount();
long[][] methodFlags = segment.getClassBands().getMethodFlags();
- int[] codeMaxNALocals = segment.getClassBands().getCodeMaxNALocals();
- int[] codeMaxStack = segment.getClassBands().getCodeMaxStack();
- ArrayList[][] methodAttributes = segment.getClassBands()
- .getMethodAttributes();
- String[][] methodDescr = segment.getClassBands().getMethodDescr();
int bcCaseCountCount = 0;
int bcByteCount = 0;
@@ -121,14 +118,12 @@
AttributeLayout nativeModifier = attributeDefinitionMap
.getAttributeLayout(AttributeLayout.ACC_NATIVE,
AttributeLayout.CONTEXT_METHOD);
- AttributeLayout staticModifier = attributeDefinitionMap
- .getAttributeLayout(AttributeLayout.ACC_STATIC,
- AttributeLayout.CONTEXT_METHOD);
+
methodByteCodePacked = new byte[classCount][][];
int bcParsed = 0;
List switchIsTableSwitch = new ArrayList();
- List wideByteCodes = new ArrayList();
+ wideByteCodes = new ArrayList();
for (int c = 0; c < classCount; c++) {
int numberOfMethods = methodFlags[c].length;
methodByteCodePacked[c] = new byte[numberOfMethods][];
@@ -360,6 +355,31 @@
bcEscSize = decodeBandInt("bc_escsize", in, Codec.UNSIGNED5, bcEscCount);
bcEscByte = decodeBandInt("bc_escbyte", in, Codec.BYTE1, bcEscSize);
+
+ }
+
+ public void unpack() throws Pack200Exception {
+ int classCount = header.getClassCount();
+ long[][] methodFlags = segment.getClassBands().getMethodFlags();
+ int[] codeMaxNALocals = segment.getClassBands().getCodeMaxNALocals();
+ int[] codeMaxStack = segment.getClassBands().getCodeMaxStack();
+ ArrayList[][] methodAttributes = segment.getClassBands()
+ .getMethodAttributes();
+ String[][] methodDescr = segment.getClassBands().getMethodDescr();
+
+ AttributeLayoutMap attributeDefinitionMap = segment
+ .getAttrDefinitionBands().getAttributeDefinitionMap();
+
+ AttributeLayout abstractModifier = attributeDefinitionMap
+ .getAttributeLayout(AttributeLayout.ACC_ABSTRACT,
+ AttributeLayout.CONTEXT_METHOD);
+ AttributeLayout nativeModifier = attributeDefinitionMap
+ .getAttributeLayout(AttributeLayout.ACC_NATIVE,
+ AttributeLayout.CONTEXT_METHOD);
+ AttributeLayout staticModifier = attributeDefinitionMap
+ .getAttributeLayout(AttributeLayout.ACC_STATIC,
+ AttributeLayout.CONTEXT_METHOD);
+
int[] wideByteCodeArray = new int[wideByteCodes.size()];
for (int index = 0; index < wideByteCodeArray.length; index++) {
wideByteCodeArray[index] = ((Integer) wideByteCodes.get(index))
@@ -401,10 +421,10 @@
maxLocal += SegmentUtils
.countInvokeInterfaceArgs(methodDescr[c][m]);
String[] cpClass = segment.getCpBands().getCpClass();
- operandManager.setCurrentClass(cpClass[segment.getClassBands()
- .getClassThisInts()[c]]);
- operandManager.setSuperClass(cpClass[segment.getClassBands()
- .getClassSuperInts()[c]]);
+ operandManager.setCurrentClass(cpClass[segment
+ .getClassBands().getClassThisInts()[c]]);
+ operandManager.setSuperClass(cpClass[segment
+ .getClassBands().getClassSuperInts()[c]]);
List exceptionTable = new ArrayList();
if (handlerCount != null) {
for (int j = 0; j < handlerCount[i]; j++) {
Modified: harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/unpack200/ClassBands.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/unpack200/ClassBands.java?rev=678796&r1=678795&r2=678796&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/unpack200/ClassBands.java (original)
+++ harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/unpack200/ClassBands.java Tue Jul 22 09:28:09 2008
@@ -132,7 +132,7 @@
*
* @see org.apache.harmony.unpack200.BandSet#unpack(java.io.InputStream)
*/
- public void unpack(InputStream in) throws IOException, Pack200Exception {
+ public void read(InputStream in) throws IOException, Pack200Exception {
int classCount = header.getClassCount();
classThisInts = decodeBandInt("class_this", in, Codec.DELTA5, classCount);
classThis = getReferences(classThisInts, cpBands.getCpClass());
@@ -153,6 +153,10 @@
}
+ public void unpack() {
+
+ }
+
private void parseFieldBands(InputStream in) throws IOException,
Pack200Exception {
fieldDescrInts = decodeBandInt("field_descr", in, Codec.DELTA5,
Modified: harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/unpack200/CpBands.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/unpack200/CpBands.java?rev=678796&r1=678795&r2=678796&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/unpack200/CpBands.java (original)
+++ harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/unpack200/CpBands.java Tue Jul 22 09:28:09 2008
@@ -103,7 +103,7 @@
super(segment);
}
- public void unpack(InputStream in) throws IOException, Pack200Exception {
+ public void read(InputStream in) throws IOException, Pack200Exception {
parseCpUtf8(in);
parseCpInt(in);
parseCpFloat(in);
@@ -130,6 +130,10 @@
imethodOffset = methodOffset + cpMethodClass.length;
}
+ public void unpack() {
+
+ }
+
/**
* Parses the constant pool class names, using {@link #cpClassCount} to
* populate {@link #cpClass} from {@link #cpUTF8}.
Modified: harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/unpack200/FileBands.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/unpack200/FileBands.java?rev=678796&r1=678795&r2=678796&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/unpack200/FileBands.java (original)
+++ harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/unpack200/FileBands.java Tue Jul 22 09:28:09 2008
@@ -58,7 +58,7 @@
*
* @see org.apache.harmony.unpack200.BandSet#unpack(java.io.InputStream)
*/
- public void unpack(InputStream in) throws IOException, Pack200Exception {
+ public void read(InputStream in) throws IOException, Pack200Exception {
int numberOfFiles = header.getNumberOfFiles();
SegmentOptions options = header.getOptions();
@@ -93,13 +93,17 @@
// not the right choice, and we should just serialize it here?
fileBits[i] = new byte[size];
int read = in.read(fileBits[i]);
- if (read < size) {
+ if (size != 0 && read < size) {
throw new Pack200Exception("Expected to read " + size
+ " bytes but read " + read);
}
}
}
+ public void unpack() {
+
+ }
+
public byte[][] getFileBits() {
return fileBits;
}
Modified: harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/unpack200/IcBands.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/unpack200/IcBands.java?rev=678796&r1=678795&r2=678796&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/unpack200/IcBands.java (original)
+++ harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/unpack200/IcBands.java Tue Jul 22 09:28:09 2008
@@ -53,7 +53,7 @@
*
* @see org.apache.harmony.unpack200.BandSet#unpack(java.io.InputStream)
*/
- public void unpack(InputStream in) throws IOException, Pack200Exception {
+ public void read(InputStream in) throws IOException, Pack200Exception {
// Read IC bands
int innerClassCount = header.getInnerClassCount();
int[] icThisClassInts = decodeBandInt("ic_this_class", in,
@@ -105,6 +105,11 @@
}
}
+ public void unpack() throws IOException, Pack200Exception {
+
+ }
+
+
public IcTuple[] getIcTuples() {
return icAll;
}
Modified: harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/unpack200/NewAttributeBands.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/unpack200/NewAttributeBands.java?rev=678796&r1=678795&r2=678796&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/unpack200/NewAttributeBands.java (original)
+++ harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/unpack200/NewAttributeBands.java Tue Jul 22 09:28:09 2008
@@ -63,7 +63,7 @@
*
* @see org.apache.harmony.unpack200.BandSet#unpack(java.io.InputStream)
*/
- public void unpack(InputStream in) throws IOException, Pack200Exception {
+ public void read(InputStream in) throws IOException, Pack200Exception {
// does nothing - use parseAttributes instead
}
@@ -949,4 +949,8 @@
}
}
+ public void unpack() throws IOException, Pack200Exception {
+
+ }
+
}
\ No newline at end of file
Modified: harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/unpack200/Segment.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/unpack200/Segment.java?rev=678796&r1=678795&r2=678796&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/unpack200/Segment.java (original)
+++ harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/unpack200/Segment.java Tue Jul 22 09:28:09 2008
@@ -17,7 +17,8 @@
package org.apache.harmony.unpack200;
import java.io.BufferedInputStream;
-import java.io.BufferedOutputStream;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStream;
@@ -92,10 +93,20 @@
private boolean deflateHint;
+ private boolean doPreRead;
+
private int logLevel;
private PrintWriter logStream;
+ private byte[][] classFilesContents;
+
+ private boolean[] fileDeflate;
+
+ private boolean[] fileIsClass;
+
+ private InputStream internalBuffer;
+
private ClassFile buildClassFile(int classNum) throws Pack200Exception {
ClassFile classFile = new ClassFile();
classFile.major = header.getDefaultClassMajorVersion(); // TODO If
@@ -348,8 +359,8 @@
}
/**
- * This performs the actual work of parsing against a non-static instance of
- * Segment.
+ * This performs reading the data from the stream into non-static instance of
+ * Segment. After the completion of this method stream can be freed.
*
* @param in
* the input stream to read from
@@ -359,23 +370,87 @@
* if a problem occurs with an unexpected value or unsupported
* codec
*/
- private void parseSegment(InputStream in) throws IOException,
+ private void readSegment(InputStream in) throws IOException,
Pack200Exception {
log(LOG_LEVEL_VERBOSE, "-------");
- header = new SegmentHeader(this);
- header.unpack(in);
cpBands = new CpBands(this);
- cpBands.unpack(in);
+ cpBands.read(in);
attrDefinitionBands = new AttrDefinitionBands(this);
- attrDefinitionBands.unpack(in);
+ attrDefinitionBands.read(in);
icBands = new IcBands(this);
- icBands.unpack(in);
+ icBands.read(in);
classBands = new ClassBands(this);
- classBands.unpack(in);
+ classBands.read(in);
bcBands = new BcBands(this);
- bcBands.unpack(in);
+ bcBands.read(in);
fileBands = new FileBands(this);
- fileBands.unpack(in);
+ fileBands.read(in);
+
+ fileBands.processFileBits();
+ }
+
+ /**
+ * This performs the actual work of parsing against a non-static instance of
+ * Segment. This method is intended to run concurrently for multiple segments.
+ *
+ * @throws IOException
+ * if a problem occurs during reading from the underlying stream
+ * @throws Pack200Exception
+ * if a problem occurs with an unexpected value or unsupported
+ * codec
+ */
+ private void parseSegment() throws IOException, Pack200Exception {
+
+ header.unpack();
+ cpBands.unpack();
+ attrDefinitionBands.unpack();
+ icBands.unpack();
+ classBands.unpack();
+ bcBands.unpack();
+ fileBands.unpack();
+
+ int classNum = 0;
+ int numberOfFiles = header.getNumberOfFiles();
+ String[] fileName = fileBands.getFileName();
+ long[] fileOptions = fileBands.getFileOptions();
+ SegmentOptions options = header.getOptions();
+
+ classFilesContents = new byte[numberOfFiles][];
+ fileDeflate = new boolean[numberOfFiles];
+ fileIsClass = new boolean[numberOfFiles];
+
+ ByteArrayOutputStream bos = new ByteArrayOutputStream();
+ DataOutputStream dos = new DataOutputStream(bos);
+
+ for (int i = 0; i < numberOfFiles; i++) {
+ String name = fileName[i];
+
+ boolean nameIsEmpty = (name == null) || name.equals("");
+ boolean isClass = (fileOptions[i] & 2) == 2 || nameIsEmpty;
+ if (isClass && nameIsEmpty) {
+ name = cpBands.getCpClass()[classBands.getClassThisInts()[classNum]] + ".class";
+ fileName[i] = name;
+ }
+
+ if (!overrideDeflateHint) {
+ fileDeflate[i] = (fileOptions[i] & 1) == 1 || options.shouldDeflate();
+ } else {
+ fileDeflate[i] = deflateHint;
+ }
+
+ fileIsClass[i] = isClass;
+
+ if (isClass) {
+ ClassFile classFile = buildClassFile(classNum);
+ classFile.write(dos);
+ dos.flush();
+
+ classFilesContents[classNum] = bos.toByteArray();
+ bos.reset();
+
+ classNum++;
+ }
+ }
}
/**
@@ -389,9 +464,40 @@
*/
public void unpack(InputStream in, JarOutputStream out) throws IOException,
Pack200Exception {
+ unpackRead(in);
+ unpackProcess();
+ unpackWrite(out);
+ }
+
+ /*
+ * Package-private accessors for unpacking stages
+ */
+ void unpackRead(InputStream in) throws IOException, Pack200Exception {
if (!in.markSupported())
in = new BufferedInputStream(in);
- parseSegment(in);
+
+ header = new SegmentHeader(this);
+ header.read(in);
+
+ int size = (int)header.getArchiveSize() - header.getArchiveSizeOffset();
+
+ if (doPreRead && header.getArchiveSize() != 0) {
+ byte[] data = new byte[size];
+ in.read(data);
+ internalBuffer = new BufferedInputStream(new ByteArrayInputStream(data));
+ } else {
+ readSegment(in);
+ }
+ }
+
+ void unpackProcess() throws IOException, Pack200Exception {
+ if(internalBuffer != null) {
+ readSegment(internalBuffer);
+ }
+ parseSegment();
+ }
+
+ void unpackWrite(JarOutputStream out) throws IOException, Pack200Exception {
writeJar(out);
}
@@ -411,12 +517,8 @@
*/
public void writeJar(JarOutputStream out) throws IOException,
Pack200Exception {
- fileBands.processFileBits();
- BufferedOutputStream buffer = new BufferedOutputStream(out);
- DataOutputStream dos = new DataOutputStream(buffer);
String[] fileName = fileBands.getFileName();
long[] fileModtime = fileBands.getFileModtime();
- long[] fileOptions = fileBands.getFileOptions();
long[] fileSize = fileBands.getFileSize();
byte[][] fileBits = fileBands.getFileBits();
@@ -425,43 +527,31 @@
int classNum = 0;
int numberOfFiles = header.getNumberOfFiles();
long archiveModtime = header.getArchiveModtime();
- SegmentOptions options = header.getOptions();
+
for (int i = 0; i < numberOfFiles; i++) {
String name = fileName[i];
long modtime = archiveModtime + fileModtime[i];
- boolean deflate = (fileOptions[i] & 1) == 1
- || options.shouldDeflate();
- if (overrideDeflateHint) { // Overridden by a command line argument
- deflate = deflateHint;
- }
- boolean isClass = (fileOptions[i] & 2) == 2 || name == null
- || name.equals("");
- if (isClass) {
- // pull from headers
- if (name == null || name.equals(""))
- name = cpBands.getCpClass()[classBands.getClassThisInts()[classNum]] + ".class";
- }
+ boolean deflate = fileDeflate[i];
+
JarEntry entry = new JarEntry(name);
if (deflate)
entry.setMethod(ZipEntry.DEFLATED);
entry.setTime(modtime);
out.putNextEntry(entry);
- if (isClass) {
+ if (fileIsClass[i]) {
// write to dos
- ClassFile classFile = buildClassFile(classNum);
- classFile.write(dos);
- dos.flush();
+ entry.setSize(classFilesContents[classNum].length);
+ out.write(classFilesContents[classNum]);
classNum++;
} else {
long size = fileSize[i];
entry.setSize(size);
- // TODO pull from in
+
byte[] data = fileBits[i];
out.write(data);
}
}
- dos.flush();
}
public SegmentConstantPool getConstantPool() {
@@ -472,6 +562,10 @@
return header;
}
+ public void setPreRead(boolean value) {
+ doPreRead = value;
+ }
+
protected AttrDefinitionBands getAttrDefinitionBands() {
return attrDefinitionBands;
}
Modified: harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/unpack200/SegmentHeader.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/unpack200/SegmentHeader.java?rev=678796&r1=678795&r2=678796&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/unpack200/SegmentHeader.java (original)
+++ harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/unpack200/SegmentHeader.java Tue Jul 22 09:28:09 2008
@@ -94,8 +94,15 @@
this.segment = segment;
}
- public void unpack(InputStream in) throws IOException, Pack200Exception,
+ public int getArchiveSizeOffset() {
+ return archiveSizeOffset;
+ }
+
+ private int archiveSizeOffset;
+
+ public void read(InputStream in) throws IOException, Pack200Exception,
Error, Pack200Exception {
+
long word[] = decodeScalar("archive_magic_word", in, Codec.BYTE1,
magic.length);
for (int m = 0; m < magic.length; m++)
@@ -117,6 +124,12 @@
readFully(in, bandHeaders);
setBandHeadersData(bandHeaders);
}
+
+ archiveSizeOffset = archiveSizeOffset - in.available();
+ }
+
+ public void unpack() {
+
}
/**
@@ -272,6 +285,7 @@
if (options.hasArchiveFileCounts()) {
setArchiveSize(decodeScalar("archive_size_hi", in, Codec.UNSIGNED5) << 32
| decodeScalar("archive_size_lo", in, Codec.UNSIGNED5));
+ archiveSizeOffset = in.available();
setSegmentsRemaining(decodeScalar("archive_next_count", in,
Codec.UNSIGNED5));
setArchiveModtime(decodeScalar("archive_modtime", in,
Modified: harmony/enhanced/classlib/trunk/modules/pack200/src/test/java/org/apache/harmony/unpack200/tests/BandSetTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/pack200/src/test/java/org/apache/harmony/unpack200/tests/BandSetTest.java?rev=678796&r1=678795&r2=678796&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/pack200/src/test/java/org/apache/harmony/unpack200/tests/BandSetTest.java (original)
+++ harmony/enhanced/classlib/trunk/modules/pack200/src/test/java/org/apache/harmony/unpack200/tests/BandSetTest.java Tue Jul 22 09:28:09 2008
@@ -40,10 +40,13 @@
private final BandSet bandSet = new BandSet(new MockSegment()) {
- public void unpack(InputStream inputStream) throws IOException,
+ public void read(InputStream inputStream) throws IOException,
Pack200Exception {
}
+ public void unpack() throws IOException, Pack200Exception {
+ }
+
};
public void testDecodeBandInt() throws IOException, Pack200Exception {