in src/main/java/org/apache/commons/compress/harmony/unpack200/Archive.java [137:232]
public void unpack() throws Pack200Exception, IOException {
outputStream.setComment("PACK200");
try {
if (!inputStream.markSupported()) {
inputStream = new BufferedInputStream(inputStream);
if (!inputStream.markSupported()) {
throw new IllegalStateException();
}
}
inputStream.mark(2);
if (((inputStream.read() & 0xFF) | (inputStream.read() & 0xFF) << 8) == GZIPInputStream.GZIP_MAGIC) {
inputStream.reset();
inputStream = new BufferedInputStream(new GZIPInputStream(inputStream));
} else {
inputStream.reset();
}
inputStream.mark(4);
final int[] magic = {0xCA, 0xFE, 0xD0, 0x0D}; // Magic word for
// pack200
final int[] word = new int[4];
for (int i = 0; i < word.length; i++) {
word[i] = inputStream.read();
}
boolean compressedWithE0 = false;
for (int m = 0; m < magic.length; m++) {
if (word[m] != magic[m]) {
compressedWithE0 = true;
}
}
inputStream.reset();
if (compressedWithE0) { // The original Jar was not packed, so just
// copy it across
final JarInputStream jarInputStream = new JarInputStream(inputStream);
JarEntry jarEntry;
while ((jarEntry = jarInputStream.getNextJarEntry()) != null) {
outputStream.putNextEntry(jarEntry);
final byte[] bytes = new byte[16384];
int bytesRead = jarInputStream.read(bytes);
while (bytesRead != -1) {
outputStream.write(bytes, 0, bytesRead);
bytesRead = jarInputStream.read(bytes);
}
outputStream.closeEntry();
}
} else {
int i = 0;
while (available(inputStream)) {
i++;
final Segment segment = new Segment();
segment.setLogLevel(logLevel);
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 " + outputFileName);
}
segment.log(Segment.LOG_LEVEL_VERBOSE, "Reading segment " + i);
if (overrideDeflateHint) {
segment.overrideDeflateHint(deflateHint);
}
segment.unpack(inputStream, outputStream);
outputStream.flush();
if (inputStream instanceof FileInputStream) {
inputFileName = ((FileInputStream) inputStream).getFD().toString();
}
}
}
} finally {
try {
inputStream.close();
} catch (final Exception e) {
}
try {
outputStream.close();
} catch (final Exception e) {
}
if (logFile != null) {
try {
logFile.close();
} catch (final Exception e) {
}
}
}
if (removePackFile) {
boolean deleted = false;
if (inputFileName != null) {
final File file = new File(inputFileName);
deleted = file.delete();
}
if (!deleted) {
throw new Pack200Exception("Failed to delete the input file.");
}
}
}