|
From: <caw...@us...> - 2007-09-10 14:54:51
|
Revision: 3117
http://rubyeclipse.svn.sourceforge.net/rubyeclipse/?rev=3117&view=rev
Author: cawilliams
Date: 2007-09-10 07:54:50 -0700 (Mon, 10 Sep 2007)
Log Message:
-----------
when grabbing the remote gem index, just run the original input stream right into an InflaterInputStream, then read out of that into a big byte array.
This should help fix the Out of Memory errors (somewhat, we may still need to stop buffering it all up into one big byte array and tehn converting that into a String, instead writing it to a temp file and then reading that in as a character array/Strings).
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-10 13:26:00 UTC (rev 3116)
+++ trunk/com.aptana.rdt/src/com/aptana/rdt/internal/core/gems/GemManager.java 2007-09-10 14:54:50 UTC (rev 3117)
@@ -1,7 +1,6 @@
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;
@@ -24,7 +23,7 @@
import java.util.SortedSet;
import java.util.TreeSet;
import java.util.zip.DataFormatException;
-import java.util.zip.Inflater;
+import java.util.zip.InflaterInputStream;
import javax.xml.parsers.FactoryConfigurationError;
import javax.xml.parsers.ParserConfigurationException;
@@ -249,7 +248,7 @@
private List<String> getContents() throws MalformedURLException,
IOException, DataFormatException {
- String outputString = decompress(getZippedGemIndex());
+ String outputString = new String(getZippedGemIndex());
String[] lineArray = outputString.split("\n");
return Arrays.asList(lineArray);
}
@@ -261,13 +260,13 @@
try {
URL url = new URL(GEM_INDEX_URL);
URLConnection con = url.openConnection();
- content = (InputStream) con.getContent();
+ content = new InflaterInputStream((InputStream) con.getContent());
while (true) {
int bytesToRead = content.available();
byte[] tmp = new byte[bytesToRead];
int length = content.read(tmp);
if (length == -1)
- break;
+ break;
while ((index + length) > input.length) { // if we'll overflow the
// array, we need to
// expand it
@@ -296,36 +295,6 @@
return newInput;
}
- private String decompress(byte[] input) throws DataFormatException {
- // Decompress the bytes
- Inflater decompresser = new Inflater();
- decompresser.setInput(input);
-
- // 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() {
if (!isRubyGemsInstalled()) return new HashSet<Gem>();
GemParser parser = new GemParser();
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|