author | erikj |
Tue, 12 Sep 2017 19:03:39 +0200 | |
changeset 47216 | 71c04702a3d5 |
parent 21964 | jdk/test/java/util/Base64/Base64GetEncoderTest.java@73a3fd499f24 |
child 48689 | e704f48d8277 |
permissions | -rw-r--r-- |
17207
f6a2a1d7bb17
8007799: Base64.getEncoder(0, byte[]) returns an encoder that unexpectedly inserts line separators
msheppar
parents:
diff
changeset
|
1 |
/* |
f6a2a1d7bb17
8007799: Base64.getEncoder(0, byte[]) returns an encoder that unexpectedly inserts line separators
msheppar
parents:
diff
changeset
|
2 |
* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. |
f6a2a1d7bb17
8007799: Base64.getEncoder(0, byte[]) returns an encoder that unexpectedly inserts line separators
msheppar
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
f6a2a1d7bb17
8007799: Base64.getEncoder(0, byte[]) returns an encoder that unexpectedly inserts line separators
msheppar
parents:
diff
changeset
|
4 |
* |
f6a2a1d7bb17
8007799: Base64.getEncoder(0, byte[]) returns an encoder that unexpectedly inserts line separators
msheppar
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
f6a2a1d7bb17
8007799: Base64.getEncoder(0, byte[]) returns an encoder that unexpectedly inserts line separators
msheppar
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
f6a2a1d7bb17
8007799: Base64.getEncoder(0, byte[]) returns an encoder that unexpectedly inserts line separators
msheppar
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
f6a2a1d7bb17
8007799: Base64.getEncoder(0, byte[]) returns an encoder that unexpectedly inserts line separators
msheppar
parents:
diff
changeset
|
8 |
* |
f6a2a1d7bb17
8007799: Base64.getEncoder(0, byte[]) returns an encoder that unexpectedly inserts line separators
msheppar
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
f6a2a1d7bb17
8007799: Base64.getEncoder(0, byte[]) returns an encoder that unexpectedly inserts line separators
msheppar
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
f6a2a1d7bb17
8007799: Base64.getEncoder(0, byte[]) returns an encoder that unexpectedly inserts line separators
msheppar
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
f6a2a1d7bb17
8007799: Base64.getEncoder(0, byte[]) returns an encoder that unexpectedly inserts line separators
msheppar
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
f6a2a1d7bb17
8007799: Base64.getEncoder(0, byte[]) returns an encoder that unexpectedly inserts line separators
msheppar
parents:
diff
changeset
|
13 |
* accompanied this code). |
f6a2a1d7bb17
8007799: Base64.getEncoder(0, byte[]) returns an encoder that unexpectedly inserts line separators
msheppar
parents:
diff
changeset
|
14 |
* |
f6a2a1d7bb17
8007799: Base64.getEncoder(0, byte[]) returns an encoder that unexpectedly inserts line separators
msheppar
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
f6a2a1d7bb17
8007799: Base64.getEncoder(0, byte[]) returns an encoder that unexpectedly inserts line separators
msheppar
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
f6a2a1d7bb17
8007799: Base64.getEncoder(0, byte[]) returns an encoder that unexpectedly inserts line separators
msheppar
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
f6a2a1d7bb17
8007799: Base64.getEncoder(0, byte[]) returns an encoder that unexpectedly inserts line separators
msheppar
parents:
diff
changeset
|
18 |
* |
f6a2a1d7bb17
8007799: Base64.getEncoder(0, byte[]) returns an encoder that unexpectedly inserts line separators
msheppar
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
f6a2a1d7bb17
8007799: Base64.getEncoder(0, byte[]) returns an encoder that unexpectedly inserts line separators
msheppar
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
f6a2a1d7bb17
8007799: Base64.getEncoder(0, byte[]) returns an encoder that unexpectedly inserts line separators
msheppar
parents:
diff
changeset
|
21 |
* questions. |
f6a2a1d7bb17
8007799: Base64.getEncoder(0, byte[]) returns an encoder that unexpectedly inserts line separators
msheppar
parents:
diff
changeset
|
22 |
*/ |
f6a2a1d7bb17
8007799: Base64.getEncoder(0, byte[]) returns an encoder that unexpectedly inserts line separators
msheppar
parents:
diff
changeset
|
23 |
|
f6a2a1d7bb17
8007799: Base64.getEncoder(0, byte[]) returns an encoder that unexpectedly inserts line separators
msheppar
parents:
diff
changeset
|
24 |
|
f6a2a1d7bb17
8007799: Base64.getEncoder(0, byte[]) returns an encoder that unexpectedly inserts line separators
msheppar
parents:
diff
changeset
|
25 |
|
f6a2a1d7bb17
8007799: Base64.getEncoder(0, byte[]) returns an encoder that unexpectedly inserts line separators
msheppar
parents:
diff
changeset
|
26 |
import java.io.ByteArrayOutputStream; |
f6a2a1d7bb17
8007799: Base64.getEncoder(0, byte[]) returns an encoder that unexpectedly inserts line separators
msheppar
parents:
diff
changeset
|
27 |
import java.io.IOException; |
f6a2a1d7bb17
8007799: Base64.getEncoder(0, byte[]) returns an encoder that unexpectedly inserts line separators
msheppar
parents:
diff
changeset
|
28 |
import java.io.OutputStream; |
f6a2a1d7bb17
8007799: Base64.getEncoder(0, byte[]) returns an encoder that unexpectedly inserts line separators
msheppar
parents:
diff
changeset
|
29 |
import java.nio.ByteBuffer; |
f6a2a1d7bb17
8007799: Base64.getEncoder(0, byte[]) returns an encoder that unexpectedly inserts line separators
msheppar
parents:
diff
changeset
|
30 |
|
f6a2a1d7bb17
8007799: Base64.getEncoder(0, byte[]) returns an encoder that unexpectedly inserts line separators
msheppar
parents:
diff
changeset
|
31 |
import java.util.Base64; |
f6a2a1d7bb17
8007799: Base64.getEncoder(0, byte[]) returns an encoder that unexpectedly inserts line separators
msheppar
parents:
diff
changeset
|
32 |
|
f6a2a1d7bb17
8007799: Base64.getEncoder(0, byte[]) returns an encoder that unexpectedly inserts line separators
msheppar
parents:
diff
changeset
|
33 |
import static java.nio.charset.StandardCharsets.US_ASCII; |
f6a2a1d7bb17
8007799: Base64.getEncoder(0, byte[]) returns an encoder that unexpectedly inserts line separators
msheppar
parents:
diff
changeset
|
34 |
|
f6a2a1d7bb17
8007799: Base64.getEncoder(0, byte[]) returns an encoder that unexpectedly inserts line separators
msheppar
parents:
diff
changeset
|
35 |
/** |
f6a2a1d7bb17
8007799: Base64.getEncoder(0, byte[]) returns an encoder that unexpectedly inserts line separators
msheppar
parents:
diff
changeset
|
36 |
* @test |
f6a2a1d7bb17
8007799: Base64.getEncoder(0, byte[]) returns an encoder that unexpectedly inserts line separators
msheppar
parents:
diff
changeset
|
37 |
* @bug 8007799 |
f6a2a1d7bb17
8007799: Base64.getEncoder(0, byte[]) returns an encoder that unexpectedly inserts line separators
msheppar
parents:
diff
changeset
|
38 |
* @summary test Encoder with linemax == 0, line separator should not appear in encoded data |
f6a2a1d7bb17
8007799: Base64.getEncoder(0, byte[]) returns an encoder that unexpectedly inserts line separators
msheppar
parents:
diff
changeset
|
39 |
*/ |
f6a2a1d7bb17
8007799: Base64.getEncoder(0, byte[]) returns an encoder that unexpectedly inserts line separators
msheppar
parents:
diff
changeset
|
40 |
|
f6a2a1d7bb17
8007799: Base64.getEncoder(0, byte[]) returns an encoder that unexpectedly inserts line separators
msheppar
parents:
diff
changeset
|
41 |
public class Base64GetEncoderTest { |
f6a2a1d7bb17
8007799: Base64.getEncoder(0, byte[]) returns an encoder that unexpectedly inserts line separators
msheppar
parents:
diff
changeset
|
42 |
|
f6a2a1d7bb17
8007799: Base64.getEncoder(0, byte[]) returns an encoder that unexpectedly inserts line separators
msheppar
parents:
diff
changeset
|
43 |
public static void main(String args[]) throws Throwable { |
21363
82e139fdd879
8025003: Base64 should be less strict with padding
sherman
parents:
17207
diff
changeset
|
44 |
final Base64.Encoder encoder = Base64.getMimeEncoder(0, "$$$".getBytes(US_ASCII)); |
17207
f6a2a1d7bb17
8007799: Base64.getEncoder(0, byte[]) returns an encoder that unexpectedly inserts line separators
msheppar
parents:
diff
changeset
|
45 |
|
f6a2a1d7bb17
8007799: Base64.getEncoder(0, byte[]) returns an encoder that unexpectedly inserts line separators
msheppar
parents:
diff
changeset
|
46 |
testEncodeToString(encoder); |
f6a2a1d7bb17
8007799: Base64.getEncoder(0, byte[]) returns an encoder that unexpectedly inserts line separators
msheppar
parents:
diff
changeset
|
47 |
|
f6a2a1d7bb17
8007799: Base64.getEncoder(0, byte[]) returns an encoder that unexpectedly inserts line separators
msheppar
parents:
diff
changeset
|
48 |
testWrapEncode1(encoder); |
f6a2a1d7bb17
8007799: Base64.getEncoder(0, byte[]) returns an encoder that unexpectedly inserts line separators
msheppar
parents:
diff
changeset
|
49 |
|
f6a2a1d7bb17
8007799: Base64.getEncoder(0, byte[]) returns an encoder that unexpectedly inserts line separators
msheppar
parents:
diff
changeset
|
50 |
testEncodeToStringWithLongInputData(encoder); |
f6a2a1d7bb17
8007799: Base64.getEncoder(0, byte[]) returns an encoder that unexpectedly inserts line separators
msheppar
parents:
diff
changeset
|
51 |
|
f6a2a1d7bb17
8007799: Base64.getEncoder(0, byte[]) returns an encoder that unexpectedly inserts line separators
msheppar
parents:
diff
changeset
|
52 |
testWrapEncode2(encoder); |
f6a2a1d7bb17
8007799: Base64.getEncoder(0, byte[]) returns an encoder that unexpectedly inserts line separators
msheppar
parents:
diff
changeset
|
53 |
|
f6a2a1d7bb17
8007799: Base64.getEncoder(0, byte[]) returns an encoder that unexpectedly inserts line separators
msheppar
parents:
diff
changeset
|
54 |
} |
f6a2a1d7bb17
8007799: Base64.getEncoder(0, byte[]) returns an encoder that unexpectedly inserts line separators
msheppar
parents:
diff
changeset
|
55 |
|
f6a2a1d7bb17
8007799: Base64.getEncoder(0, byte[]) returns an encoder that unexpectedly inserts line separators
msheppar
parents:
diff
changeset
|
56 |
private static void testWrapEncode2(final Base64.Encoder encoder) |
f6a2a1d7bb17
8007799: Base64.getEncoder(0, byte[]) returns an encoder that unexpectedly inserts line separators
msheppar
parents:
diff
changeset
|
57 |
throws IOException { |
f6a2a1d7bb17
8007799: Base64.getEncoder(0, byte[]) returns an encoder that unexpectedly inserts line separators
msheppar
parents:
diff
changeset
|
58 |
System.err.println("\nEncoder.wrap test II "); |
f6a2a1d7bb17
8007799: Base64.getEncoder(0, byte[]) returns an encoder that unexpectedly inserts line separators
msheppar
parents:
diff
changeset
|
59 |
final byte[] secondTestBuffer = |
f6a2a1d7bb17
8007799: Base64.getEncoder(0, byte[]) returns an encoder that unexpectedly inserts line separators
msheppar
parents:
diff
changeset
|
60 |
"api/java_util/Base64/index.html#GetEncoderMimeCustom[noLineSeparatorInEncodedString]" |
f6a2a1d7bb17
8007799: Base64.getEncoder(0, byte[]) returns an encoder that unexpectedly inserts line separators
msheppar
parents:
diff
changeset
|
61 |
.getBytes(US_ASCII); |
f6a2a1d7bb17
8007799: Base64.getEncoder(0, byte[]) returns an encoder that unexpectedly inserts line separators
msheppar
parents:
diff
changeset
|
62 |
String base64EncodedString; |
f6a2a1d7bb17
8007799: Base64.getEncoder(0, byte[]) returns an encoder that unexpectedly inserts line separators
msheppar
parents:
diff
changeset
|
63 |
ByteArrayOutputStream secondEncodingStream = new ByteArrayOutputStream(); |
f6a2a1d7bb17
8007799: Base64.getEncoder(0, byte[]) returns an encoder that unexpectedly inserts line separators
msheppar
parents:
diff
changeset
|
64 |
OutputStream base64EncodingStream = encoder.wrap(secondEncodingStream); |
f6a2a1d7bb17
8007799: Base64.getEncoder(0, byte[]) returns an encoder that unexpectedly inserts line separators
msheppar
parents:
diff
changeset
|
65 |
base64EncodingStream.write(secondTestBuffer); |
f6a2a1d7bb17
8007799: Base64.getEncoder(0, byte[]) returns an encoder that unexpectedly inserts line separators
msheppar
parents:
diff
changeset
|
66 |
base64EncodingStream.close(); |
f6a2a1d7bb17
8007799: Base64.getEncoder(0, byte[]) returns an encoder that unexpectedly inserts line separators
msheppar
parents:
diff
changeset
|
67 |
|
f6a2a1d7bb17
8007799: Base64.getEncoder(0, byte[]) returns an encoder that unexpectedly inserts line separators
msheppar
parents:
diff
changeset
|
68 |
final byte[] encodedByteArray = secondEncodingStream.toByteArray(); |
f6a2a1d7bb17
8007799: Base64.getEncoder(0, byte[]) returns an encoder that unexpectedly inserts line separators
msheppar
parents:
diff
changeset
|
69 |
|
f6a2a1d7bb17
8007799: Base64.getEncoder(0, byte[]) returns an encoder that unexpectedly inserts line separators
msheppar
parents:
diff
changeset
|
70 |
System.err.print("result = " + new String(encodedByteArray, US_ASCII) |
f6a2a1d7bb17
8007799: Base64.getEncoder(0, byte[]) returns an encoder that unexpectedly inserts line separators
msheppar
parents:
diff
changeset
|
71 |
+ " after wrap Base64 encoding of string"); |
f6a2a1d7bb17
8007799: Base64.getEncoder(0, byte[]) returns an encoder that unexpectedly inserts line separators
msheppar
parents:
diff
changeset
|
72 |
|
f6a2a1d7bb17
8007799: Base64.getEncoder(0, byte[]) returns an encoder that unexpectedly inserts line separators
msheppar
parents:
diff
changeset
|
73 |
base64EncodedString = new String(encodedByteArray, US_ASCII); |
f6a2a1d7bb17
8007799: Base64.getEncoder(0, byte[]) returns an encoder that unexpectedly inserts line separators
msheppar
parents:
diff
changeset
|
74 |
|
f6a2a1d7bb17
8007799: Base64.getEncoder(0, byte[]) returns an encoder that unexpectedly inserts line separators
msheppar
parents:
diff
changeset
|
75 |
if (base64EncodedString.contains("$$$")) { |
f6a2a1d7bb17
8007799: Base64.getEncoder(0, byte[]) returns an encoder that unexpectedly inserts line separators
msheppar
parents:
diff
changeset
|
76 |
throw new RuntimeException( |
f6a2a1d7bb17
8007799: Base64.getEncoder(0, byte[]) returns an encoder that unexpectedly inserts line separators
msheppar
parents:
diff
changeset
|
77 |
"Base64 encoding contains line separator after wrap 2 invoked ... \n"); |
f6a2a1d7bb17
8007799: Base64.getEncoder(0, byte[]) returns an encoder that unexpectedly inserts line separators
msheppar
parents:
diff
changeset
|
78 |
} |
f6a2a1d7bb17
8007799: Base64.getEncoder(0, byte[]) returns an encoder that unexpectedly inserts line separators
msheppar
parents:
diff
changeset
|
79 |
} |
f6a2a1d7bb17
8007799: Base64.getEncoder(0, byte[]) returns an encoder that unexpectedly inserts line separators
msheppar
parents:
diff
changeset
|
80 |
|
f6a2a1d7bb17
8007799: Base64.getEncoder(0, byte[]) returns an encoder that unexpectedly inserts line separators
msheppar
parents:
diff
changeset
|
81 |
private static void testEncodeToStringWithLongInputData( |
f6a2a1d7bb17
8007799: Base64.getEncoder(0, byte[]) returns an encoder that unexpectedly inserts line separators
msheppar
parents:
diff
changeset
|
82 |
final Base64.Encoder encoder) { |
f6a2a1d7bb17
8007799: Base64.getEncoder(0, byte[]) returns an encoder that unexpectedly inserts line separators
msheppar
parents:
diff
changeset
|
83 |
System.err.println("\n\nEncoder.encodeToStringWithLongInputData test "); |
f6a2a1d7bb17
8007799: Base64.getEncoder(0, byte[]) returns an encoder that unexpectedly inserts line separators
msheppar
parents:
diff
changeset
|
84 |
|
f6a2a1d7bb17
8007799: Base64.getEncoder(0, byte[]) returns an encoder that unexpectedly inserts line separators
msheppar
parents:
diff
changeset
|
85 |
final byte[] secondTestBuffer = |
f6a2a1d7bb17
8007799: Base64.getEncoder(0, byte[]) returns an encoder that unexpectedly inserts line separators
msheppar
parents:
diff
changeset
|
86 |
"api/java_util/Base64/index.html#GetEncoderMimeCustom[noLineSeparatorInEncodedString]" |
f6a2a1d7bb17
8007799: Base64.getEncoder(0, byte[]) returns an encoder that unexpectedly inserts line separators
msheppar
parents:
diff
changeset
|
87 |
.getBytes(US_ASCII); |
f6a2a1d7bb17
8007799: Base64.getEncoder(0, byte[]) returns an encoder that unexpectedly inserts line separators
msheppar
parents:
diff
changeset
|
88 |
String base64EncodedString; |
f6a2a1d7bb17
8007799: Base64.getEncoder(0, byte[]) returns an encoder that unexpectedly inserts line separators
msheppar
parents:
diff
changeset
|
89 |
base64EncodedString = encoder.encodeToString(secondTestBuffer); |
f6a2a1d7bb17
8007799: Base64.getEncoder(0, byte[]) returns an encoder that unexpectedly inserts line separators
msheppar
parents:
diff
changeset
|
90 |
|
f6a2a1d7bb17
8007799: Base64.getEncoder(0, byte[]) returns an encoder that unexpectedly inserts line separators
msheppar
parents:
diff
changeset
|
91 |
System.err.println("Second Base64 encoded string is " |
f6a2a1d7bb17
8007799: Base64.getEncoder(0, byte[]) returns an encoder that unexpectedly inserts line separators
msheppar
parents:
diff
changeset
|
92 |
+ base64EncodedString); |
f6a2a1d7bb17
8007799: Base64.getEncoder(0, byte[]) returns an encoder that unexpectedly inserts line separators
msheppar
parents:
diff
changeset
|
93 |
|
f6a2a1d7bb17
8007799: Base64.getEncoder(0, byte[]) returns an encoder that unexpectedly inserts line separators
msheppar
parents:
diff
changeset
|
94 |
if (base64EncodedString.contains("$$$")) { |
f6a2a1d7bb17
8007799: Base64.getEncoder(0, byte[]) returns an encoder that unexpectedly inserts line separators
msheppar
parents:
diff
changeset
|
95 |
throw new RuntimeException( |
f6a2a1d7bb17
8007799: Base64.getEncoder(0, byte[]) returns an encoder that unexpectedly inserts line separators
msheppar
parents:
diff
changeset
|
96 |
"Base64 encoding contains line separator after encodeToString invoked ... \n"); |
f6a2a1d7bb17
8007799: Base64.getEncoder(0, byte[]) returns an encoder that unexpectedly inserts line separators
msheppar
parents:
diff
changeset
|
97 |
} |
f6a2a1d7bb17
8007799: Base64.getEncoder(0, byte[]) returns an encoder that unexpectedly inserts line separators
msheppar
parents:
diff
changeset
|
98 |
} |
f6a2a1d7bb17
8007799: Base64.getEncoder(0, byte[]) returns an encoder that unexpectedly inserts line separators
msheppar
parents:
diff
changeset
|
99 |
|
f6a2a1d7bb17
8007799: Base64.getEncoder(0, byte[]) returns an encoder that unexpectedly inserts line separators
msheppar
parents:
diff
changeset
|
100 |
private static void testWrapEncode1(final Base64.Encoder encoder) |
f6a2a1d7bb17
8007799: Base64.getEncoder(0, byte[]) returns an encoder that unexpectedly inserts line separators
msheppar
parents:
diff
changeset
|
101 |
throws IOException { |
f6a2a1d7bb17
8007799: Base64.getEncoder(0, byte[]) returns an encoder that unexpectedly inserts line separators
msheppar
parents:
diff
changeset
|
102 |
System.err.println("\nEncoder.wrap test I "); |
f6a2a1d7bb17
8007799: Base64.getEncoder(0, byte[]) returns an encoder that unexpectedly inserts line separators
msheppar
parents:
diff
changeset
|
103 |
|
f6a2a1d7bb17
8007799: Base64.getEncoder(0, byte[]) returns an encoder that unexpectedly inserts line separators
msheppar
parents:
diff
changeset
|
104 |
final byte[] bytesIn = "fo".getBytes(US_ASCII); |
f6a2a1d7bb17
8007799: Base64.getEncoder(0, byte[]) returns an encoder that unexpectedly inserts line separators
msheppar
parents:
diff
changeset
|
105 |
String base64EncodedString; |
f6a2a1d7bb17
8007799: Base64.getEncoder(0, byte[]) returns an encoder that unexpectedly inserts line separators
msheppar
parents:
diff
changeset
|
106 |
ByteArrayOutputStream encodingStream = new ByteArrayOutputStream(); |
f6a2a1d7bb17
8007799: Base64.getEncoder(0, byte[]) returns an encoder that unexpectedly inserts line separators
msheppar
parents:
diff
changeset
|
107 |
OutputStream encoding = encoder.wrap(encodingStream); |
f6a2a1d7bb17
8007799: Base64.getEncoder(0, byte[]) returns an encoder that unexpectedly inserts line separators
msheppar
parents:
diff
changeset
|
108 |
encoding.write(bytesIn); |
f6a2a1d7bb17
8007799: Base64.getEncoder(0, byte[]) returns an encoder that unexpectedly inserts line separators
msheppar
parents:
diff
changeset
|
109 |
encoding.close(); |
f6a2a1d7bb17
8007799: Base64.getEncoder(0, byte[]) returns an encoder that unexpectedly inserts line separators
msheppar
parents:
diff
changeset
|
110 |
|
f6a2a1d7bb17
8007799: Base64.getEncoder(0, byte[]) returns an encoder that unexpectedly inserts line separators
msheppar
parents:
diff
changeset
|
111 |
final byte[] encodedBytes = encodingStream.toByteArray(); |
f6a2a1d7bb17
8007799: Base64.getEncoder(0, byte[]) returns an encoder that unexpectedly inserts line separators
msheppar
parents:
diff
changeset
|
112 |
|
f6a2a1d7bb17
8007799: Base64.getEncoder(0, byte[]) returns an encoder that unexpectedly inserts line separators
msheppar
parents:
diff
changeset
|
113 |
System.err.print("result = " + new String(encodedBytes, US_ASCII) |
f6a2a1d7bb17
8007799: Base64.getEncoder(0, byte[]) returns an encoder that unexpectedly inserts line separators
msheppar
parents:
diff
changeset
|
114 |
+ " after the Base64 encoding \n"); |
f6a2a1d7bb17
8007799: Base64.getEncoder(0, byte[]) returns an encoder that unexpectedly inserts line separators
msheppar
parents:
diff
changeset
|
115 |
|
f6a2a1d7bb17
8007799: Base64.getEncoder(0, byte[]) returns an encoder that unexpectedly inserts line separators
msheppar
parents:
diff
changeset
|
116 |
base64EncodedString = new String(encodedBytes, US_ASCII); |
f6a2a1d7bb17
8007799: Base64.getEncoder(0, byte[]) returns an encoder that unexpectedly inserts line separators
msheppar
parents:
diff
changeset
|
117 |
|
f6a2a1d7bb17
8007799: Base64.getEncoder(0, byte[]) returns an encoder that unexpectedly inserts line separators
msheppar
parents:
diff
changeset
|
118 |
if (base64EncodedString.contains("$$$")) { |
f6a2a1d7bb17
8007799: Base64.getEncoder(0, byte[]) returns an encoder that unexpectedly inserts line separators
msheppar
parents:
diff
changeset
|
119 |
throw new RuntimeException( |
f6a2a1d7bb17
8007799: Base64.getEncoder(0, byte[]) returns an encoder that unexpectedly inserts line separators
msheppar
parents:
diff
changeset
|
120 |
"Base64 encoding contains line separator after wrap I test ... \n"); |
f6a2a1d7bb17
8007799: Base64.getEncoder(0, byte[]) returns an encoder that unexpectedly inserts line separators
msheppar
parents:
diff
changeset
|
121 |
} |
f6a2a1d7bb17
8007799: Base64.getEncoder(0, byte[]) returns an encoder that unexpectedly inserts line separators
msheppar
parents:
diff
changeset
|
122 |
} |
f6a2a1d7bb17
8007799: Base64.getEncoder(0, byte[]) returns an encoder that unexpectedly inserts line separators
msheppar
parents:
diff
changeset
|
123 |
|
f6a2a1d7bb17
8007799: Base64.getEncoder(0, byte[]) returns an encoder that unexpectedly inserts line separators
msheppar
parents:
diff
changeset
|
124 |
private static void testEncodeToString(final Base64.Encoder encoder) { |
f6a2a1d7bb17
8007799: Base64.getEncoder(0, byte[]) returns an encoder that unexpectedly inserts line separators
msheppar
parents:
diff
changeset
|
125 |
final byte[] bytesIn = "fo".getBytes(US_ASCII); |
f6a2a1d7bb17
8007799: Base64.getEncoder(0, byte[]) returns an encoder that unexpectedly inserts line separators
msheppar
parents:
diff
changeset
|
126 |
|
f6a2a1d7bb17
8007799: Base64.getEncoder(0, byte[]) returns an encoder that unexpectedly inserts line separators
msheppar
parents:
diff
changeset
|
127 |
System.err.println("\nEncoder.encodeToString test "); |
f6a2a1d7bb17
8007799: Base64.getEncoder(0, byte[]) returns an encoder that unexpectedly inserts line separators
msheppar
parents:
diff
changeset
|
128 |
|
f6a2a1d7bb17
8007799: Base64.getEncoder(0, byte[]) returns an encoder that unexpectedly inserts line separators
msheppar
parents:
diff
changeset
|
129 |
String base64EncodedString = encoder.encodeToString(bytesIn); |
f6a2a1d7bb17
8007799: Base64.getEncoder(0, byte[]) returns an encoder that unexpectedly inserts line separators
msheppar
parents:
diff
changeset
|
130 |
|
f6a2a1d7bb17
8007799: Base64.getEncoder(0, byte[]) returns an encoder that unexpectedly inserts line separators
msheppar
parents:
diff
changeset
|
131 |
System.err.println("Base64 encoded string is " + base64EncodedString); |
f6a2a1d7bb17
8007799: Base64.getEncoder(0, byte[]) returns an encoder that unexpectedly inserts line separators
msheppar
parents:
diff
changeset
|
132 |
|
f6a2a1d7bb17
8007799: Base64.getEncoder(0, byte[]) returns an encoder that unexpectedly inserts line separators
msheppar
parents:
diff
changeset
|
133 |
if (base64EncodedString.contains("$$$")) { |
f6a2a1d7bb17
8007799: Base64.getEncoder(0, byte[]) returns an encoder that unexpectedly inserts line separators
msheppar
parents:
diff
changeset
|
134 |
throw new RuntimeException("Base64 encoding contains line separator after Encoder.encodeToString invoked ... \n"); |
f6a2a1d7bb17
8007799: Base64.getEncoder(0, byte[]) returns an encoder that unexpectedly inserts line separators
msheppar
parents:
diff
changeset
|
135 |
} |
f6a2a1d7bb17
8007799: Base64.getEncoder(0, byte[]) returns an encoder that unexpectedly inserts line separators
msheppar
parents:
diff
changeset
|
136 |
} |
f6a2a1d7bb17
8007799: Base64.getEncoder(0, byte[]) returns an encoder that unexpectedly inserts line separators
msheppar
parents:
diff
changeset
|
137 |
} |