catch EOFException during import

This commit is contained in:
Thialfihar 2010-05-21 14:42:12 +00:00
parent 97745873e7
commit 71f5af31e4

View File

@ -19,6 +19,7 @@ package org.thialfihar.android.apg;
import java.io.BufferedInputStream; import java.io.BufferedInputStream;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.EOFException;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
@ -711,41 +712,45 @@ public class Apg {
BufferedInputStream bufferedInput = new BufferedInputStream(progressIn); BufferedInputStream bufferedInput = new BufferedInputStream(progressIn);
int newKeys = 0; int newKeys = 0;
int oldKeys = 0; int oldKeys = 0;
while (true) { try {
InputStream in = PGPUtil.getDecoderStream(bufferedInput); while (true) {
PGPObjectFactory objectFactory = new PGPObjectFactory(in); InputStream in = PGPUtil.getDecoderStream(bufferedInput);
Object obj = objectFactory.nextObject(); PGPObjectFactory objectFactory = new PGPObjectFactory(in);
// if the first is already a null object, then we can stop trying Object obj = objectFactory.nextObject();
if (obj == null) { // if the first is already a null object, then we can stop trying
break; if (obj == null) {
} break;
while (obj != null) { }
PGPPublicKeyRing publicKeyRing; while (obj != null) {
PGPSecretKeyRing secretKeyRing; PGPPublicKeyRing publicKeyRing;
// a return value that doesn't match any Id.return_value.* values, in case PGPSecretKeyRing secretKeyRing;
// saveKeyRing is never called // a return value that doesn't match any Id.return_value.* values, in case
int retValue = 2107; // saveKeyRing is never called
int retValue = 2107;
if (type == Id.type.secret_key && obj instanceof PGPSecretKeyRing) {
secretKeyRing = (PGPSecretKeyRing) obj; if (type == Id.type.secret_key && obj instanceof PGPSecretKeyRing) {
retValue = saveKeyRing(context, secretKeyRing); secretKeyRing = (PGPSecretKeyRing) obj;
} else if (type == Id.type.public_key && obj instanceof PGPPublicKeyRing) { retValue = saveKeyRing(context, secretKeyRing);
publicKeyRing = (PGPPublicKeyRing) obj; } else if (type == Id.type.public_key && obj instanceof PGPPublicKeyRing) {
retValue = saveKeyRing(context, publicKeyRing); publicKeyRing = (PGPPublicKeyRing) obj;
} retValue = saveKeyRing(context, publicKeyRing);
}
if (retValue == Id.return_value.error) {
throw new GeneralException(context.getString(R.string.error_savingKeys)); if (retValue == Id.return_value.error) {
} throw new GeneralException(context.getString(R.string.error_savingKeys));
}
if (retValue == Id.return_value.updated) {
++oldKeys; if (retValue == Id.return_value.updated) {
} else if (retValue == Id.return_value.ok) { ++oldKeys;
++newKeys; } else if (retValue == Id.return_value.ok) {
} ++newKeys;
progress.setProgress((int)(100 * progressIn.position() / fileSize), 100); }
obj = objectFactory.nextObject(); progress.setProgress((int)(100 * progressIn.position() / fileSize), 100);
obj = objectFactory.nextObject();
}
} }
} catch (EOFException e) {
// nothing to do, we are done
} }
progress.setProgress(R.string.progress_reloadingKeys, 100, 100); progress.setProgress(R.string.progress_reloadingKeys, 100, 100);