FileDocCategorySizeDatePackage
ByteCodeHelper.javaAPI DocHibernate 3.2.52109Thu Aug 03 15:35:26 BST 2006org.hibernate.bytecode.util

ByteCodeHelper

public class ByteCodeHelper extends Object
A helper for reading byte code from various input sources.
author
Steve Ebersole

Fields Summary
Constructors Summary
private ByteCodeHelper()

	
Methods Summary
public static byte[]readByteCode(java.io.InputStream inputStream)
Reads class byte array info from the given input stream.

The stream is closed within this method!

param
inputStream
return
throws
IOException

		if ( inputStream == null ) {
			throw new IOException( "null input stream" );
		}

		byte[] buffer = new byte[409600];
		byte[] classBytes = new byte[0];
		int r = 0;

		try {
			r = inputStream.read( buffer );
			while ( r >= buffer.length ) {
				byte[] temp = new byte[ classBytes.length + buffer.length ];
				System.arraycopy( classBytes, 0, temp, 0, classBytes.length );
				System.arraycopy( buffer, 0, temp, classBytes.length, buffer.length );
				classBytes = temp;
			}
			if ( r != -1 ) {
				byte[] temp = new byte[ classBytes.length + r ];
				System.arraycopy( classBytes, 0, temp, 0, classBytes.length );
				System.arraycopy( buffer, 0, temp, classBytes.length, r );
				classBytes = temp;
			}
		}
		finally {
			try {
				inputStream.close();
			}
			catch (IOException ignore) {
				// intentionally empty
			}
		}

		return classBytes;
	
public static byte[]readByteCode(java.io.File file)

		return ByteCodeHelper.readByteCode( new FileInputStream( file ) );
	
public static byte[]readByteCode(java.util.zip.ZipInputStream zip)

        ByteArrayOutputStream bout = new ByteArrayOutputStream();
        InputStream in = new BufferedInputStream( zip );
        int b;
        while ( ( b = in.read() ) != -1 ) {
            bout.write( b );
        }
        return bout.toByteArray();