Changeset 20478

Show
Ignore:
Timestamp:
10/02/08 13:12:37 (3 months ago)
Author:
nori090
Message:

そもそも動いてなかった。間違い修正><

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • lang/java/misc/B.java

    r19743 r20478  
    11import java.io.ByteArrayInputStream; 
    2 import java.io.File; 
    3 import java.io.FileOutputStream; 
    4 import java.net.URL; 
    5 import java.net.URLClassLoader; 
     2import java.io.ByteArrayOutputStream; 
    63import java.util.zip.ZipInputStream; 
    74 
     
    7370    public static void main( String[] args ) { 
    7471        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(); 
    7874            byte[] b = new byte[1024]; 
    7975            int size = -1; 
     76            zip.getNextEntry(); 
    8077            while ( ( size = zip.read( b, 0, b.length ) ) != -1 ) { 
    81                 fos.write( b, 0, size ); 
     78                bos.write( b, 0, size ); 
    8279            } 
    83             fos.flush(); 
    84             fos.close(); 
    85             bais.close(); 
    8680            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(); 
    8990        } 
    9091        catch ( Exception e ) {