Happy Codings - Programming Code Examples
Html Css Web Design Sample Codes CPlusPlus Programming Sample Codes JavaScript Programming Sample Codes C Programming Sample Codes CSharp Programming Sample Codes Java Programming Sample Codes Php Programming Sample Codes Visual Basic Programming Sample Codes


Java Programming Code Examples

Java > Other Code Examples

Test reading jar resources

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
Test reading jar resources package com.ack.tools.jarinfo.testing; import com.ack.tools.jarinfo.JarByteLoader; import com.ack.tools.jarinfo.JarInfoException; import com.ack.tools.jarinfo.SuffixZipEntryFilter; import com.ack.tools.jarinfo.ZipEntryFilter; import com.ack.tools.jarinfo.testing.TestJarInfoConstants; import junit.framework.TestCase; /** * demonstrates how to load resources from * a given jar using the JarInfo package. */ public class TestReadingJarResources extends TestCase { public TestReadingJarResources( String s ) { super( s ); } protected void setUp() { } protected void tearDown() { } public void testAccessingJarResources() { String archiveName = TestJarInfoConstants.kZIP_FILE_ONE; ZipEntryFilter zipFilter = new SuffixZipEntryFilter( ".xsl" ); JarByteLoader jarByteLoader = null; try { // load zip entries based upon filter jarByteLoader = new JarByteLoader( archiveName, zipFilter ); System.out.println( "\nJarByteLoader successfully loaded -> " + archiveName ); // view contents of zip entries match ".xsl" System.out.println( jarByteLoader.getJarInfo() ); // load the specified resource String resourceName = "org/apache/tools/ant/taskdefs/optional/junit/xsl/junit-frames.xsl"; byte[] theBytes = jarByteLoader.getResourceAsBytes( resourceName ); System.out.println( "\nJarByteLoader loaded " + theBytes.length + " bytes for " + resourceName + " from " + archiveName ); // print out the resource System.out.println( new String( theBytes ) ); } catch( JarInfoException jie ) { jie.printStackTrace(); fail(); } } }