Allow entries to be streamed from JarURLConnections' jar file
Fixes gh-23821
This commit is contained in:
		
							parent
							
								
									2d9d40bd2d
								
							
						
					
					
						commit
						f3d4b3e5ac
					
				| 
						 | 
					@ -24,6 +24,7 @@ import java.security.Permission;
 | 
				
			||||||
import java.util.Enumeration;
 | 
					import java.util.Enumeration;
 | 
				
			||||||
import java.util.jar.JarEntry;
 | 
					import java.util.jar.JarEntry;
 | 
				
			||||||
import java.util.jar.Manifest;
 | 
					import java.util.jar.Manifest;
 | 
				
			||||||
 | 
					import java.util.stream.Stream;
 | 
				
			||||||
import java.util.zip.ZipEntry;
 | 
					import java.util.zip.ZipEntry;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
| 
						 | 
					@ -67,6 +68,11 @@ class JarFileWrapper extends AbstractJarFile {
 | 
				
			||||||
		return this.parent.entries();
 | 
							return this.parent.entries();
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						@Override
 | 
				
			||||||
 | 
						public Stream<JarEntry> stream() {
 | 
				
			||||||
 | 
							return this.parent.stream();
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	@Override
 | 
						@Override
 | 
				
			||||||
	public JarEntry getJarEntry(String name) {
 | 
						public JarEntry getJarEntry(String name) {
 | 
				
			||||||
		return this.parent.getJarEntry(name);
 | 
							return this.parent.getJarEntry(name);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -28,6 +28,7 @@ import java.util.Enumeration;
 | 
				
			||||||
import java.util.Set;
 | 
					import java.util.Set;
 | 
				
			||||||
import java.util.jar.JarOutputStream;
 | 
					import java.util.jar.JarOutputStream;
 | 
				
			||||||
import java.util.jar.Manifest;
 | 
					import java.util.jar.Manifest;
 | 
				
			||||||
 | 
					import java.util.stream.Stream;
 | 
				
			||||||
import java.util.zip.ZipEntry;
 | 
					import java.util.zip.ZipEntry;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import org.junit.jupiter.api.AfterEach;
 | 
					import org.junit.jupiter.api.AfterEach;
 | 
				
			||||||
| 
						 | 
					@ -150,6 +151,12 @@ class JarFileWrapperTests {
 | 
				
			||||||
				.isThrownBy(() -> JarFileWrapper.class.getDeclaredMethod("close"));
 | 
									.isThrownBy(() -> JarFileWrapper.class.getDeclaredMethod("close"));
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						@Test
 | 
				
			||||||
 | 
						void streamDelegatestoParent() {
 | 
				
			||||||
 | 
							this.wrapper.stream();
 | 
				
			||||||
 | 
							this.parent.verify(Call.STREAM);
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/**
 | 
						/**
 | 
				
			||||||
	 * {@link JarFile} that we can spy (even on Java 11+)
 | 
						 * {@link JarFile} that we can spy (even on Java 11+)
 | 
				
			||||||
	 */
 | 
						 */
 | 
				
			||||||
| 
						 | 
					@ -179,6 +186,12 @@ class JarFileWrapperTests {
 | 
				
			||||||
			return super.entries();
 | 
								return super.entries();
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							@Override
 | 
				
			||||||
 | 
							public Stream<java.util.jar.JarEntry> stream() {
 | 
				
			||||||
 | 
								mark(Call.STREAM);
 | 
				
			||||||
 | 
								return super.stream();
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		@Override
 | 
							@Override
 | 
				
			||||||
		public JarEntry getJarEntry(String name) {
 | 
							public JarEntry getJarEntry(String name) {
 | 
				
			||||||
			mark(Call.GET_JAR_ENTRY);
 | 
								mark(Call.GET_JAR_ENTRY);
 | 
				
			||||||
| 
						 | 
					@ -257,7 +270,9 @@ class JarFileWrapperTests {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			GET_COMMENT,
 | 
								GET_COMMENT,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			SIZE
 | 
								SIZE,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								STREAM
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -21,6 +21,9 @@ import java.io.File;
 | 
				
			||||||
import java.io.FileNotFoundException;
 | 
					import java.io.FileNotFoundException;
 | 
				
			||||||
import java.io.InputStream;
 | 
					import java.io.InputStream;
 | 
				
			||||||
import java.net.URL;
 | 
					import java.net.URL;
 | 
				
			||||||
 | 
					import java.util.List;
 | 
				
			||||||
 | 
					import java.util.jar.JarEntry;
 | 
				
			||||||
 | 
					import java.util.stream.Collectors;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import org.junit.jupiter.api.AfterEach;
 | 
					import org.junit.jupiter.api.AfterEach;
 | 
				
			||||||
import org.junit.jupiter.api.BeforeEach;
 | 
					import org.junit.jupiter.api.BeforeEach;
 | 
				
			||||||
| 
						 | 
					@ -201,6 +204,14 @@ class JarURLConnectionTests {
 | 
				
			||||||
		assertThat(connection.getLastModified()).isEqualTo(connection.getJarEntry().getTime());
 | 
							assertThat(connection.getLastModified()).isEqualTo(connection.getJarEntry().getTime());
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						@Test
 | 
				
			||||||
 | 
						void entriesCanBeStreamedFromJarFileOfConnection() throws Exception {
 | 
				
			||||||
 | 
							URL url = new URL("jar:" + this.rootJarFile.toURI().toURL() + "!/");
 | 
				
			||||||
 | 
							JarURLConnection connection = JarURLConnection.get(url, this.jarFile);
 | 
				
			||||||
 | 
							List<String> entryNames = connection.getJarFile().stream().map(JarEntry::getName).collect(Collectors.toList());
 | 
				
			||||||
 | 
							assertThat(entryNames).hasSize(12);
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	@Test
 | 
						@Test
 | 
				
			||||||
	void jarEntryBasicName() {
 | 
						void jarEntryBasicName() {
 | 
				
			||||||
		assertThat(new JarEntryName(new StringSequence("a/b/C.class")).toString()).isEqualTo("a/b/C.class");
 | 
							assertThat(new JarEntryName(new StringSequence("a/b/C.class")).toString()).isEqualTo("a/b/C.class");
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue