Changeset 20478 for lang/java/misc/B.java
- Timestamp:
- 10/02/08 13:12:37 (3 months ago)
- Files:
-
- 1 modified
-
lang/java/misc/B.java (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
lang/java/misc/B.java
r19743 r20478 1 1 import java.io.ByteArrayInputStream; 2 import java.io.File; 3 import java.io.FileOutputStream; 4 import java.net.URL; 5 import java.net.URLClassLoader; 2 import java.io.ByteArrayOutputStream; 6 3 import java.util.zip.ZipInputStream; 7 4 … … 73 70 public static void main( String[] args ) { 74 71 try { 75 ByteArrayInputStream bais = new ByteArrayInputStream( buf ); 76 ZipInputStream zip = new ZipInputStream( bais ); 77 FileOutputStream fos = new FileOutputStream( "A.class" ); 72 ZipInputStream zip = new ZipInputStream( new ByteArrayInputStream( buf ) ); 73 ByteArrayOutputStream bos = new ByteArrayOutputStream(); 78 74 byte[] b = new byte[1024]; 79 75 int size = -1; 76 zip.getNextEntry(); 80 77 while ( ( size = zip.read( b, 0, b.length ) ) != -1 ) { 81 fos.write( b, 0, size );78 bos.write( b, 0, size ); 82 79 } 83 fos.flush();84 fos.close();85 bais.close();86 80 zip.close(); 87 URLClassLoader loader = new URLClassLoader( new URL[] { new File( "." ).toURI().toURL() } ); 88 loader.loadClass( "A" ).newInstance(); 81 final byte[] bin = bos.toByteArray(); 82 ClassLoader cl = new ClassLoader() { 83 @Override 84 protected Class<?> findClass( String name ) 85 throws ClassNotFoundException { 86 return super.defineClass( name, bin, 0, bin.length ); 87 } 88 }; 89 cl.loadClass( "A" ).newInstance(); 89 90 } 90 91 catch ( Exception e ) {
![(please configure the [header_logo] section in trac.ini)](/share/chrome/site/your_project_logo.png)