ttomcat-1778514358873.zip-extract/apache-tomcat-11.0.18-src/test/org/apache/catalina/webresources/TestJarInputStreamWrapper.java

Path
ttomcat-1778514358873.zip-extract/apache-tomcat-11.0.18-src/test/org/apache/catalina/webresources/TestJarInputStreamWrapper.java
Status
scanned
Type
file
Name
TestJarInputStreamWrapper.java
Extension
.java
Programming language
Java
Mime type
text/plain
File type
ASCII text, with CRLF line terminators
Tag

      
    
Rootfs path

      
    
Size
4877 (4.8 KB)
MD5
7ccc4a70a8095e8f38d3bcb735bef2c6
SHA1
2f0e1fe69ffabacf58465bfa3ef82aa54f19b76f
SHA256
77f88ed376500fa7ffe2e43321b1b83fc4152003fd92cac96dbaa07f16f1afd2
SHA512

      
    
SHA1_git
7d6c75a1b4a0b05e0345d0a16aa982840038294d
Is binary

      
    
Is text
True
Is archive

      
    
Is media

      
    
Is legal

      
    
Is manifest

      
    
Is readme

      
    
Is top level

      
    
Is key file

      
    
TestJarInputStreamWrapper.java | 4.8 KB |

/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.catalina.webresources; import java.io.File; import java.io.IOException; import java.io.InputStream; import java.lang.reflect.Method; import java.util.jar.JarFile; import java.util.zip.ZipEntry; import java.util.zip.ZipFile; import org.junit.Assert; import org.junit.Test; import org.apache.catalina.WebResource; public class TestJarInputStreamWrapper { @Test public void testReadAfterClose() throws Exception { Method m = InputStream.class.getMethod("read", (Class<?>[]) null); testMethodAfterClose(m, (Object[]) null); } @Test public void testSkipAfterClose() throws Exception { Method m = InputStream.class.getMethod("skip", long.class); testMethodAfterClose(m, Long.valueOf(1)); } @Test public void testAvailableAfterClose() throws Exception { Method m = InputStream.class.getMethod("available", (Class<?>[]) null); testMethodAfterClose(m, (Object[]) null); } @Test public void testCloseAfterClose() throws Exception { Method m = InputStream.class.getMethod("close", (Class<?>[]) null); testMethodAfterClose(m, (Object[]) null); } @Test public void testMarkAfterClose() throws Exception { Method m = InputStream.class.getMethod("mark", int.class); testMethodAfterClose(m, Integer.valueOf(1)); } @Test public void testResetAfterClose() throws Exception { Method m = InputStream.class.getMethod("reset", (Class<?>[]) null); testMethodAfterClose(m, (Object[]) null); } @Test public void testMarkSupportedAfterClose() throws Exception { Method m = InputStream.class.getMethod("markSupported", (Class<?>[]) null); testMethodAfterClose(m, (Object[]) null); } private void testMethodAfterClose(Method m, Object... params) throws IOException { InputStream unwrapped = getUnwrappedClosedInputStream(); InputStream wrapped = getWrappedClosedInputStream(); Object unwrappedReturn = null; Exception unwrappedException = null; Object wrappedReturn = null; Exception wrappedException = null; try { unwrappedReturn = m.invoke(unwrapped, params); } catch (Exception e) { unwrappedException = e; } try { wrappedReturn = m.invoke(wrapped, params); } catch (Exception e) { wrappedException = e; } if (unwrappedReturn == null) { Assert.assertNull(wrappedReturn); } else { Assert.assertNotNull(wrappedReturn); Assert.assertEquals(unwrappedReturn, wrappedReturn); } if (unwrappedException == null) { Assert.assertNull(wrappedException); } else { Assert.assertNotNull(wrappedException); Assert.assertEquals(unwrappedException.getClass(), wrappedException.getClass()); } } private InputStream getUnwrappedClosedInputStream() throws IOException { File file = new File("test/webresources/non-static-resources.jar"); JarFile jarFile = new JarFile(file, true, ZipFile.OPEN_READ, Runtime.version()); ZipEntry jarEntry = jarFile.getEntry("META-INF/MANIFEST.MF"); InputStream unwrapped = jarFile.getInputStream(jarEntry); unwrapped.close(); jarFile.close(); return unwrapped; } private InputStream getWrappedClosedInputStream() throws IOException { StandardRoot root = new StandardRoot(); root.setCachingAllowed(false); JarResourceSet jarResourceSet = new JarResourceSet(root, "/", "test/webresources/non-static-resources.jar", "/"); WebResource webResource = jarResourceSet.getResource("/META-INF/MANIFEST.MF"); InputStream wrapped = webResource.getInputStream(); wrapped.close(); return wrapped; } }
Detected license expression
apache-2.0
Detected license expression (SPDX)
Apache-2.0
Percentage of license text
26.56
Copyrights

      
    
Holders

      
    
Authors

      
    
License detections License expression License expression SPDX
apache_2_0-4bde3f57-78aa-4201-96bf-531cba09e7de apache-2.0 Apache-2.0
URL Start line End line
http://www.apache.org/licenses/LICENSE-2.0 9 9