Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/com/sun/crypto/provider/CICO/ReadModel.java
41155 views
1
/*
2
* Copyright (c) 2007, 2015, 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
import java.io.IOException;
24
25
import javax.crypto.Cipher;
26
import javax.crypto.CipherInputStream;
27
import javax.crypto.CipherOutputStream;
28
29
/**
30
* ReadModel provides different way to test
31
* CipherInputStream.read()/read(byte[])/read(byte[], int, int) and
32
* CipherOutputStream.write(int)/write(byte[], int, int)/read(byte[]) API
33
*/
34
enum ReadModel {
35
READ_BYTE {
36
@Override
37
public void read(CipherInputStream cInput, CipherOutputStream ciOutput,
38
Cipher ciIn, int inputLen) throws IOException {
39
int buffer0 = cInput.read();
40
while (buffer0 != -1) {
41
ciOutput.write(buffer0);
42
buffer0 = cInput.read();
43
}
44
}
45
},
46
READ_BUFFER {
47
@Override
48
public void read(CipherInputStream cInput, CipherOutputStream ciOutput,
49
Cipher ciIn, int inputLen) throws IOException {
50
byte[] buffer1 = new byte[20];
51
int len1;
52
while ((len1 = cInput.read(buffer1)) != -1) {
53
ciOutput.write(buffer1, 0, len1);
54
}
55
56
}
57
},
58
READ_BUFFER_OFFSET {
59
@Override
60
public void read(CipherInputStream cInput, CipherOutputStream ciOutput,
61
Cipher ciIn, int inputLen) throws IOException {
62
byte[] buffer2 = new byte[ciIn.getOutputSize(inputLen)];
63
int offset2 = 0;
64
int len2 = 0;
65
while (len2 != -1) {
66
len2 = cInput.read(buffer2, offset2, buffer2.length - offset2);
67
offset2 += len2;
68
}
69
ciOutput.write(buffer2);
70
71
}
72
};
73
74
abstract public void read(CipherInputStream cInput,
75
CipherOutputStream ciOutput, Cipher ciIn, int inputLen)
76
throws IOException;
77
}
78
79