Code example for JarFile

Methods: close, getEntry, getInputStream

0
	 *  
	 * @throws Exception 
	 */ 
	public void testGetInputStreamReturnsValidData() throws Exception { 
		byte[] defaultContents;
		JarFile defaultJarFile = new JarFile(file);
		try { 
			InputStream inputStream = defaultJarFile.getInputStream(defaultJarFile.getEntry(SAMPLE_JAR_CLASS));
			try { 
				defaultContents = IOUtils.toByteArray(inputStream);
			} finally { 
				inputStream.close();
			} 
		} finally { 
			defaultJarFile.close();
		} 
 
		NonLockingJarFileSpy jarFile = new NonLockingJarFileSpy(file);
		byte[] nonLockedContents = IOUtils.toByteArray(jarFile.getInputStream(jarFile.getEntry(SAMPLE_JAR_CLASS)));
 
		assertTrue("Expected same byte contents for input stream", Arrays.equals(defaultContents, nonLockedContents));