+++ /dev/null
-/*******************************************************************************\r
- * ============LICENSE_START====================================================\r
- * * org.onap.aaf\r
- * * ===========================================================================\r
- * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
- * * ===========================================================================\r
- * * Licensed under the Apache License, Version 2.0 (the "License");\r
- * * you may not use this file except in compliance with the License.\r
- * * You may obtain a copy of the License at\r
- * * \r
- * * http://www.apache.org/licenses/LICENSE-2.0\r
- * * \r
- * * Unless required by applicable law or agreed to in writing, software\r
- * * distributed under the License is distributed on an "AS IS" BASIS,\r
- * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * * See the License for the specific language governing permissions and\r
- * * limitations under the License.\r
- * * ============LICENSE_END====================================================\r
- * *\r
- * * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
- * *\r
- ******************************************************************************/\r
-package org.onap.aaf.cadi.test;\r
-\r
-import static junit.framework.Assert.assertEquals;\r
-\r
-import java.io.ByteArrayInputStream;\r
-import java.io.FileInputStream;\r
-import java.io.IOException;\r
-\r
-import org.junit.Test;\r
-import org.onap.aaf.cadi.BufferedServletInputStream;\r
-\r
-public class JU_BufferedServletInputStream {\r
-\r
- @Test\r
- public void testByteRead() throws Exception {\r
- FileInputStream fis = new FileInputStream("test/CBUSevent.xml");\r
- BufferedServletInputStream bsis = new BufferedServletInputStream(fis);\r
- try {\r
- bsis.mark(0);\r
- int c;\r
- byte aa[] = new byte[260];\r
- for(int i=0;i<aa.length;++i) {\r
- c = bsis.read();\r
- if(c>=0) {\r
- aa[i]=(byte)c;\r
- }\r
- }\r
- System.out.println(new String(aa));\r
- \r
- bsis.reset();\r
-\r
- byte bb[] = new byte[400];\r
- for(int i=0;i<bb.length;++i) {\r
- c = bsis.read();\r
- if(c>=0) {\r
- bb[i]=(byte)c;\r
- }\r
- }\r
- System.out.println(new String(bb));\r
-\r
- } finally {\r
- bsis.close();\r
- fis.close();\r
- }\r
- }\r
- \r
- @Test\r
- public void testByteArray() throws Exception {\r
- FileInputStream fis = new FileInputStream("test/CBUSevent.xml");\r
- BufferedServletInputStream bsis = new BufferedServletInputStream(fis);\r
- try {\r
- bsis.mark(0);\r
- byte aa[] = new byte[260];\r
- bsis.read(aa);\r
- System.out.println(new String(aa));\r
- \r
- bsis.reset();\r
-\r
- byte bb[] = new byte[400];\r
- bsis.read(bb);\r
- System.out.println(new String(bb));\r
-\r
- } finally {\r
- bsis.close();\r
- fis.close();\r
- }\r
- }\r
-\r
- @Test\r
- public void testDoubleRead() throws Exception {\r
- FileInputStream fis = new FileInputStream("test/CBUSevent.xml");\r
- BufferedServletInputStream bsis = new BufferedServletInputStream(fis);\r
- try {\r
- bsis.mark(0);\r
- byte aa[] = new byte[260];\r
- bsis.read(aa);\r
- System.out.println(new String(aa));\r
- \r
- bsis.reset();\r
-\r
- byte bb[] = new byte[400];\r
- bsis.read(bb);\r
- System.out.println(new String(bb));\r
-\r
- } finally {\r
- bsis.close();\r
- fis.close();\r
- }\r
- }\r
-\r
- @Test\r
- public void testByteArray2() throws Exception {\r
- FileInputStream fis = new FileInputStream("test/CBUSevent.xml");\r
- try {\r
- BufferedServletInputStream bsis = new BufferedServletInputStream(fis);\r
- byte[] content = null;\r
- byte aa[] = new byte[500];\r
- for(int i=0;i<2000;++i) {\r
- bsis.mark(0);\r
- bsis.read(aa,0,260);\r
- if(i==0)System.out.println(new String(aa));\r
- \r
- bsis.reset();\r
- \r
- bsis.read(aa,0,aa.length);\r
- if(i==0) {\r
- System.out.println(new String(aa));\r
- content = aa;\r
- aa = new byte[400];\r
- }\r
- bsis = new BufferedServletInputStream(new ByteArrayInputStream(content));\r
- \r
- }\r
- \r
- System.out.println(new String(aa));\r
-\r
- } finally {\r
- fis.close();\r
- }\r
- }\r
-\r
- // "Bug" 4/22/2013 \r
- // Some XML code expects Buffered InputStream can never return 0... This isn't actually true, but we'll accommodate as far\r
- // as we can. \r
- // Here, we make sure we set and read the Buffered data, making sure the buffer is empty on the last test...\r
- @Test\r
- public void issue04_22_2013() throws IOException {\r
- String testString = "We want to read in and get out with a Buffered Stream seamlessly.";\r
- ByteArrayInputStream bais = new ByteArrayInputStream(testString.getBytes());\r
- BufferedServletInputStream bsis = new BufferedServletInputStream(bais);\r
- try {\r
- bsis.mark(0);\r
- byte aa[] = new byte[testString.length()]; // 65 count... important for our test (divisible by 5);\r
-\r
- int read;\r
- for(int i=0;i<aa.length;i+=5) {\r
- read = bsis.read(aa, i, 5);\r
- assertEquals(5,read);\r
- }\r
- System.out.println(new String(aa));\r
- \r
- bsis.reset();\r
-\r
- byte bb[] = new byte[aa.length];\r
- read = 0;\r
- for(int i=0;read>=0;i+=read) {\r
- read = bsis.read(bb,i,5);\r
- switch(i) {\r
- case 65:\r
- assertEquals(read,-1);\r
- break;\r
- default:\r
- assertEquals(read,5);\r
- }\r
- }\r
- System.out.println(new String(bb));\r
- assertEquals(testString,new String(aa));\r
- assertEquals(testString,new String(bb));\r
-\r
- } finally {\r
- bsis.close();\r
- bais.close();\r
- }\r
- \r
- }\r
- \r
-\r
-}\r