[hibernate-commits] Hibernate SVN: r20863 - core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/bytecode/util.

hibernate-commits at lists.jboss.org hibernate-commits at lists.jboss.org
Thu Nov 11 21:35:27 EST 2010


Author: stliu
Date: 2010-11-11 21:35:26 -0500 (Thu, 11 Nov 2010)
New Revision: 20863

Modified:
   core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/bytecode/util/ByteCodeHelper.java
Log:
JBPAPP-5409 HHH-5453 ByteCodeHelper.readByteCode won't load classes bigger than a constant size

Modified: core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/bytecode/util/ByteCodeHelper.java
===================================================================
--- core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/bytecode/util/ByteCodeHelper.java	2010-11-11 21:33:41 UTC (rev 20862)
+++ core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/bytecode/util/ByteCodeHelper.java	2010-11-12 02:35:26 UTC (rev 20863)
@@ -46,9 +46,11 @@
 	 * <p/>
 	 * The stream is closed within this method!
 	 *
-	 * @param inputStream
-	 * @return
-	 * @throws IOException
+	 * @param inputStream The stream containing the class binary; null will lead to an {@link IOException}
+	 *
+	 * @return The read bytes
+	 *
+	 * @throws IOException Indicates a problem accessing the given stream.
 	 */
 	public static byte[] readByteCode(InputStream inputStream) throws IOException {
 		if ( inputStream == null ) {
@@ -57,19 +59,24 @@
 
 		byte[] buffer = new byte[409600];
 		byte[] classBytes = new byte[0];
-		int r = 0;
 
 		try {
-			r = inputStream.read( buffer );
+			int r = inputStream.read( buffer );
 			while ( r >= buffer.length ) {
 				byte[] temp = new byte[ classBytes.length + buffer.length ];
+				// copy any previously read bytes into the temp array
 				System.arraycopy( classBytes, 0, temp, 0, classBytes.length );
+				// copy the just read bytes into the temp array (after the previously read)
 				System.arraycopy( buffer, 0, temp, classBytes.length, buffer.length );
 				classBytes = temp;
+				// read the next set of bytes into buffer
+				r = inputStream.read( buffer );
 			}
 			if ( r != -1 ) {
 				byte[] temp = new byte[ classBytes.length + r ];
+				// copy any previously read bytes into the temp array
 				System.arraycopy( classBytes, 0, temp, 0, classBytes.length );
+				// copy the just read bytes into the temp array (after the previously read)
 				System.arraycopy( buffer, 0, temp, classBytes.length, r );
 				classBytes = temp;
 			}
@@ -85,11 +92,29 @@
 
 		return classBytes;
 	}
-
+	
+	/**
+	 * Read class definition from a file.
+	 *
+	 * @param file The file to read.
+	 *
+	 * @return The class bytes
+	 *
+	 * @throws IOException Indicates a problem accessing the given stream.
+	 */
 	public static byte[] readByteCode(File file) throws IOException {
 		return ByteCodeHelper.readByteCode( new FileInputStream( file ) );
 	}
-
+	
+	/**
+	 * Read class definition a zip (jar) file entry.
+	 *
+	 * @param zip The zip entry stream.
+	 * 
+	 * @return The class bytes
+	 *
+	 * @throws IOException Indicates a problem accessing the given stream.
+	 */
 	public static byte[] readByteCode(ZipInputStream zip) throws IOException {
         ByteArrayOutputStream bout = new ByteArrayOutputStream();
         InputStream in = new BufferedInputStream( zip );



More information about the hibernate-commits mailing list