Bug 578739 - Optimize ImageLoader copy to ByteArrayOutputStream

Testing was done using three images. A simple screenshot (230kB), and
two satellite image samples (15MB and 50MB) from
https://effigis.com/en/solutions/satellite-images/satellite-image-samples/.
Testing was conducted by timing in code how long the loop in the
original code took, and then how long the transferTo() call took.

By using transferTo(), instead of a loop the following speed
improvements were seen:

1) On the 230kB file, loading was 20.7% faster
2) On the first 15MB Thailand satellite image, loading was 25% faster
3) On the 50MB Germany satellite image, loading was 22.7% faster

Change-Id: I8042d7ded51444d4e6fffeca1ac2c5f6be5ad05a
Signed-off-by: Joel Majano <jmajano@redhat.com>
Reviewed-on: https://git.eclipse.org/r/c/platform/eclipse.platform.swt/+/190786
Tested-by: Alexander Kurtakov <akurtako@redhat.com>
Reviewed-by: Alexander Kurtakov <akurtako@redhat.com>
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/ImageLoader.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/ImageLoader.java
index edd343e..7a0f7ae 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/ImageLoader.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/ImageLoader.java
@@ -178,16 +178,12 @@
 }
 
 ImageData [] getImageDataArrayFromStream(InputStream stream) {
-	byte[] buffer = new byte[2048];
 	long loader = GDK.gdk_pixbuf_loader_new();
-	int length;
 	List<ImageData> imgDataList = new ArrayList<>();
 	try {
 		// 1) Load InputStream into byte array
 		ByteArrayOutputStream baos = new ByteArrayOutputStream();
-		while ((length = stream.read(buffer)) > -1) {
-			baos.write(buffer, 0, length);
-		}
+		stream.transferTo(baos);
 		baos.flush();
 		byte[] data_buffer = baos.toByteArray();
 		if (data_buffer.length == 0) SWT.error(SWT.ERROR_UNSUPPORTED_FORMAT);	// empty stream