Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/java/util/Base64/TestEncodingDecodingLength.java
41149 views
1
/*
2
* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
*
5
* This code is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU General Public License version 2 only, as
7
* published by the Free Software Foundation.
8
*
9
* This code is distributed in the hope that it will be useful, but WITHOUT
10
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12
* version 2 for more details (a copy is included in the LICENSE file that
13
* accompanied this code).
14
*
15
* You should have received a copy of the GNU General Public License version
16
* 2 along with this work; if not, write to the Free Software Foundation,
17
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18
*
19
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20
* or visit www.oracle.com if you need additional information or have any
21
* questions.
22
*/
23
24
import java.nio.ByteBuffer;
25
import java.util.Arrays;
26
import java.util.Base64;
27
28
/**
29
* @test
30
* @bug 8210583 8217969 8218265
31
* @summary Tests Base64.Encoder.encode and Base64.Decoder.decode
32
* with the large size of input array/buffer
33
* @requires (sun.arch.data.model == "64" & os.maxMemory >= 10g)
34
* @run main/othervm -Xms6g -Xmx8g TestEncodingDecodingLength
35
*
36
*/
37
38
public class TestEncodingDecodingLength {
39
40
public static void main(String[] args) {
41
int size = Integer.MAX_VALUE - 8;
42
byte[] inputBytes = new byte[size];
43
byte[] outputBytes = new byte[size];
44
45
// Check encoder with large array length
46
Base64.Encoder encoder = Base64.getEncoder();
47
checkOOM("encode(byte[])", () -> encoder.encode(inputBytes));
48
checkIAE("encode(byte[] byte[])", () -> encoder.encode(inputBytes, outputBytes));
49
checkOOM("encodeToString(byte[])", () -> encoder.encodeToString(inputBytes));
50
checkOOM("encode(ByteBuffer)", () -> encoder.encode(ByteBuffer.wrap(inputBytes)));
51
52
// Check decoder with large array length,
53
// should not throw any exception
54
Arrays.fill(inputBytes, (byte) 86);
55
Base64.Decoder decoder = Base64.getDecoder();
56
decoder.decode(inputBytes);
57
decoder.decode(inputBytes, outputBytes);
58
decoder.decode(ByteBuffer.wrap(inputBytes));
59
}
60
61
private static final void checkOOM(String methodName, Runnable r) {
62
try {
63
r.run();
64
throw new RuntimeException("OutOfMemoryError should have been thrown by: " + methodName);
65
} catch (OutOfMemoryError er) {}
66
}
67
68
private static final void checkIAE(String methodName, Runnable r) {
69
try {
70
r.run();
71
throw new RuntimeException("IllegalArgumentException should have been thrown by: " + methodName);
72
} catch (IllegalArgumentException iae) {}
73
}
74
}
75
76
77