Path: blob/master/test/jdk/com/sun/crypto/provider/CICO/ReadModel.java
41155 views
/*1* Copyright (c) 2007, 2015, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/22import java.io.IOException;2324import javax.crypto.Cipher;25import javax.crypto.CipherInputStream;26import javax.crypto.CipherOutputStream;2728/**29* ReadModel provides different way to test30* CipherInputStream.read()/read(byte[])/read(byte[], int, int) and31* CipherOutputStream.write(int)/write(byte[], int, int)/read(byte[]) API32*/33enum ReadModel {34READ_BYTE {35@Override36public void read(CipherInputStream cInput, CipherOutputStream ciOutput,37Cipher ciIn, int inputLen) throws IOException {38int buffer0 = cInput.read();39while (buffer0 != -1) {40ciOutput.write(buffer0);41buffer0 = cInput.read();42}43}44},45READ_BUFFER {46@Override47public void read(CipherInputStream cInput, CipherOutputStream ciOutput,48Cipher ciIn, int inputLen) throws IOException {49byte[] buffer1 = new byte[20];50int len1;51while ((len1 = cInput.read(buffer1)) != -1) {52ciOutput.write(buffer1, 0, len1);53}5455}56},57READ_BUFFER_OFFSET {58@Override59public void read(CipherInputStream cInput, CipherOutputStream ciOutput,60Cipher ciIn, int inputLen) throws IOException {61byte[] buffer2 = new byte[ciIn.getOutputSize(inputLen)];62int offset2 = 0;63int len2 = 0;64while (len2 != -1) {65len2 = cInput.read(buffer2, offset2, buffer2.length - offset2);66offset2 += len2;67}68ciOutput.write(buffer2);6970}71};7273abstract public void read(CipherInputStream cInput,74CipherOutputStream ciOutput, Cipher ciIn, int inputLen)75throws IOException;76}777879