reduce memory usage while parsing multiple keyrings from a stream

This commit is contained in:
Vincent Breitmoser
2014-07-31 18:25:20 +02:00
parent aa32c60a0a
commit ecb2c2c2b1
2 changed files with 72 additions and 31 deletions

View File

@@ -32,6 +32,7 @@ import org.sufficientlysecure.keychain.util.PositionAwareInputStream;
import java.io.BufferedInputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
public class ImportKeysListLoader
@@ -127,11 +128,12 @@ public class ImportKeysListLoader
BufferedInputStream bufferedInput = new BufferedInputStream(progressIn);
try {
// parse all keyrings
List<UncachedKeyRing> rings = UncachedKeyRing.fromStream(bufferedInput);
for (UncachedKeyRing key : rings) {
ImportKeysListEntry item = new ImportKeysListEntry(getContext(), key);
Iterator<UncachedKeyRing> it = UncachedKeyRing.fromStream(bufferedInput);
while (it.hasNext()) {
UncachedKeyRing ring = it.next();
ImportKeysListEntry item = new ImportKeysListEntry(getContext(), ring);
mData.add(item);
mParcelableRings.put(item.hashCode(), new ParcelableKeyRing(key.getEncoded()));
mParcelableRings.put(item.hashCode(), new ParcelableKeyRing(ring.getEncoded()));
}
} catch (IOException e) {
Log.e(Constants.TAG, "IOException on parsing key file! Return NoValidKeysException!", e);