|
From: <caw...@us...> - 2007-09-10 13:17:26
|
Revision: 3115
http://rubyeclipse.svn.sourceforge.net/rubyeclipse/?rev=3115&view=rev
Author: cawilliams
Date: 2007-09-10 06:17:21 -0700 (Mon, 10 Sep 2007)
Log Message:
-----------
try to fix #5823 - Out of memory error after startup - "Loading remote gem information".
In decompress method, loop over inflater grabbing up to 1K of data at a time and stuffing it into a ByteArrayOutputStream, then turn that into a String. Rather than making a big byte array and trying to expand it all at once.
Modified Paths:
--------------
trunk/com.aptana.rdt/src/com/aptana/rdt/internal/core/gems/GemManager.java
Modified: trunk/com.aptana.rdt/src/com/aptana/rdt/internal/core/gems/GemManager.java
===================================================================
--- trunk/com.aptana.rdt/src/com/aptana/rdt/internal/core/gems/GemManager.java 2007-09-07 19:52:42 UTC (rev 3114)
+++ trunk/com.aptana.rdt/src/com/aptana/rdt/internal/core/gems/GemManager.java 2007-09-10 13:17:21 UTC (rev 3115)
@@ -1,6 +1,7 @@
package com.aptana.rdt.internal.core.gems;
import java.io.BufferedReader;
+import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
@@ -285,14 +286,30 @@
// Decompress the bytes
Inflater decompresser = new Inflater();
decompresser.setInput(input);
- byte[] result = new byte[input.length * 10]; // XXX This is a hack. I
- // have no idea what the
- // length should be here
- int resultLength = decompresser.inflate(result);
- decompresser.end();
- // Decode the bytes into a String
- return new String(result, 0, resultLength);
+ // Create an expandable byte array to hold the decompressed data
+ ByteArrayOutputStream bos = new ByteArrayOutputStream(input.length);
+
+ try {
+ // Decompress the data
+ byte[] buf = new byte[1024];
+ while (!decompresser.finished()) {
+ int count = decompresser.inflate(buf);
+ bos.write(buf, 0, count);
+ }
+ // Get the decompressed data
+ byte[] result = bos.toByteArray();
+
+ // Decode the bytes into a String
+ return new String(result);
+ } catch (DataFormatException e) {
+ return "";
+ } finally {
+ try {
+ bos.close();
+ } catch (IOException ioe) {}
+ decompresser.end();
+ }
}
private Set<Gem> loadLocalGems() {
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|