Skip to content

Commit 7c21bad

Browse files
author
John Jiang
committed
8299748: java/util/zip/Deinflate.java failing on s390x
Backport-of: 26fb0f87897e7d7b193e08c1d69e6c0fa12c976c
1 parent 156d998 commit 7c21bad

File tree

1 file changed

+50
-21
lines changed

1 file changed

+50
-21
lines changed

test/jdk/java/util/zip/DeInflate.java

Lines changed: 50 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2011, 2018, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2011, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -47,11 +47,12 @@ static void checkStream(Deflater def, byte[] in, int len,
4747
Arrays.fill(out1, (byte)0);
4848
Arrays.fill(out2, (byte)0);
4949

50-
ByteArrayOutputStream baos = new ByteArrayOutputStream();
51-
try (DeflaterOutputStream defos = new DeflaterOutputStream(baos, def)) {
52-
defos.write(in, 0, len);
50+
try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
51+
try (DeflaterOutputStream defos = new DeflaterOutputStream(baos, def)) {
52+
defos.write(in, 0, len);
53+
}
54+
out1 = baos.toByteArray();
5355
}
54-
out1 = baos.toByteArray();
5556
int m = out1.length;
5657

5758
Inflater inf = new Inflater(nowrap);
@@ -118,27 +119,55 @@ static void checkByteBufferReadonly(Deflater def, Inflater inf,
118119
} catch (ReadOnlyBufferException robe) {}
119120
}
120121

121-
static void check(Deflater def, byte[] in, int len,
122-
byte[] out1, byte[] out2, boolean nowrap)
122+
/**
123+
* Uses the {@code def} deflater to deflate the input data {@code in} of length {@code len}.
124+
* A new {@link Inflater} is then created within this method to inflate the deflated data. The
125+
* inflated data is then compared with the {@code in} to assert that it matches the original
126+
* input data.
127+
* This method repeats these checks for the different overloaded methods of
128+
* {@code Deflater.deflate(...)} and {@code Inflater.inflate(...)}
129+
*
130+
* @param def the deflater to use for deflating the contents in {@code in}
131+
* @param in the input content
132+
* @param len the length of the input content to use
133+
* @param nowrap will be passed to the constructor of the {@code Inflater} used in this
134+
* method
135+
* @throws Throwable if any error occurs during the check
136+
*/
137+
static void check(Deflater def, byte[] in, int len, boolean nowrap)
123138
throws Throwable
124139
{
125-
Arrays.fill(out1, (byte)0);
126-
Arrays.fill(out2, (byte)0);
127-
140+
byte[] tempBuffer = new byte[len];
141+
byte[] out1, out2;
142+
int m = 0, n = 0;
143+
Inflater inf = new Inflater(nowrap);
128144
def.setInput(in, 0, len);
129145
def.finish();
130-
int m = def.deflate(out1);
131146

132-
Inflater inf = new Inflater(nowrap);
133-
inf.setInput(out1, 0, m);
134-
int n = inf.inflate(out2);
147+
try (ByteArrayOutputStream baos = new ByteArrayOutputStream(len)) {
148+
while (!def.finished()) {
149+
int temp_counter = def.deflate(tempBuffer);
150+
m += temp_counter;
151+
baos.write(tempBuffer, 0, temp_counter);
152+
}
153+
out1 = baos.toByteArray();
154+
baos.reset();
135155

136-
if (n != len ||
137-
!Arrays.equals(Arrays.copyOf(in, len), Arrays.copyOf(out2, len)) ||
138-
inf.inflate(out2) != 0) {
139-
System.out.printf("m=%d, n=%d, len=%d, eq=%b%n",
140-
m, n, len, Arrays.equals(in, out2));
141-
throw new RuntimeException("De/inflater failed:" + def);
156+
inf.setInput(out1, 0, m);
157+
158+
while (!inf.finished()) {
159+
int temp_counter = inf.inflate(tempBuffer);
160+
n += temp_counter;
161+
baos.write(tempBuffer, 0, temp_counter);
162+
}
163+
out2 = baos.toByteArray();
164+
if (n != len ||
165+
!Arrays.equals(in, 0, len, out2, 0, len) ||
166+
inf.inflate(out2) != 0) {
167+
System.out.printf("m=%d, n=%d, len=%d, eq=%b%n",
168+
m, n, len, Arrays.equals(in, out2));
169+
throw new RuntimeException("De/inflater failed:" + def);
170+
}
142171
}
143172

144173
// readable
@@ -287,7 +316,7 @@ public static void main(String[] args) throws Throwable {
287316
: new Random().nextInt(dataIn.length);
288317
// use a new deflater
289318
Deflater def = newDeflater(level, strategy, dowrap, dataOut2);
290-
check(def, dataIn, len, dataOut1, dataOut2, dowrap);
319+
check(def, dataIn, len, dowrap);
291320
def.end();
292321

293322
// reuse the deflater (with reset) and test on stream, which

0 commit comments

Comments
 (0)