diff options
Diffstat (limited to 'OpenKeychain/src')
2 files changed, 19 insertions, 26 deletions
| diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/UncachedKeyRing.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/UncachedKeyRing.java index 006af6073..a445e161f 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/UncachedKeyRing.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/UncachedKeyRing.java @@ -137,35 +137,30 @@ public class UncachedKeyRing {      public static UncachedKeyRing decodeFromData(byte[] data)              throws PgpGeneralException, IOException { -        Iterator<UncachedKeyRing> parsed = fromStream(new ByteArrayInputStream(data)); +        IteratorWithIOThrow<UncachedKeyRing> parsed = fromStream(new ByteArrayInputStream(data));          if ( ! parsed.hasNext()) {              throw new PgpGeneralException("Object not recognized as PGPKeyRing!");          } -        try { -            UncachedKeyRing ring = parsed.next(); +        UncachedKeyRing ring = parsed.next(); -            if (parsed.hasNext()) { -                throw new PgpGeneralException("Expected single keyring in stream, found at least two"); -            } +        if (parsed.hasNext()) { +            throw new PgpGeneralException("Expected single keyring in stream, found at least two"); +        } -            return ring; +        return ring; -        } catch (RuntimeException e) { -            // yes this is bad style. we should rework this in a better way -            throw new PgpGeneralException(e.getCause()); -        }      } -    public static Iterator<UncachedKeyRing> fromStream(final InputStream stream) { +    public static IteratorWithIOThrow<UncachedKeyRing> fromStream(final InputStream stream) { -        return new Iterator<UncachedKeyRing>() { +        return new IteratorWithIOThrow<UncachedKeyRing>() {              UncachedKeyRing mNext = null;              PGPObjectFactory mObjectFactory = null; -            private void cacheNext() { +            private void cacheNext() throws IOException {                  if (mNext != null) {                      return;                  } @@ -194,22 +189,19 @@ public class UncachedKeyRing {                          // if we are past the while loop, that means the objectFactory had no next                          mObjectFactory = null;                      } -                } catch (IOException e) { -                    throw new RuntimeException(e); -                    // Log.e(Constants.TAG, "IOException while processing stream. ArmoredInputStream CRC check failed?", e);                  } catch (ArrayIndexOutOfBoundsException e) { -                    Log.e(Constants.TAG, "ArmoredInputStream decode failed, symbol is not in decodingTable!", e); +                    throw new IOException(e);                  }              }              @Override -            public boolean hasNext() { +            public boolean hasNext() throws IOException {                  cacheNext();                  return mNext != null;              }              @Override -            public UncachedKeyRing next() { +            public UncachedKeyRing next() throws IOException {                  try {                      cacheNext();                      return mNext; @@ -217,15 +209,15 @@ public class UncachedKeyRing {                      mNext = null;                  }              } - -            @Override -            public void remove() { -                throw new UnsupportedOperationException(); -            }          };      } +    public interface IteratorWithIOThrow<E> { +        public boolean hasNext() throws IOException; +        public E next() throws IOException; +    } +      public void encodeArmored(OutputStream out, String version) throws IOException {          ArmoredOutputStream aos = new ArmoredOutputStream(out);          if (version != null) { diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/ImportKeysListLoader.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/ImportKeysListLoader.java index 41c7e0cbc..cecad2716 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/ImportKeysListLoader.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/ImportKeysListLoader.java @@ -27,6 +27,7 @@ import org.sufficientlysecure.keychain.keyimport.ParcelableKeyRing;  import org.sufficientlysecure.keychain.pgp.UncachedKeyRing;  import org.sufficientlysecure.keychain.operations.results.GetKeyResult;  import org.sufficientlysecure.keychain.operations.results.OperationResult; +import org.sufficientlysecure.keychain.pgp.UncachedKeyRing.IteratorWithIOThrow;  import org.sufficientlysecure.keychain.util.InputData;  import org.sufficientlysecure.keychain.util.Log;  import org.sufficientlysecure.keychain.util.PositionAwareInputStream; @@ -127,7 +128,7 @@ public class ImportKeysListLoader          BufferedInputStream bufferedInput = new BufferedInputStream(progressIn);          try {              // parse all keyrings -            Iterator<UncachedKeyRing> it = UncachedKeyRing.fromStream(bufferedInput); +            IteratorWithIOThrow<UncachedKeyRing> it = UncachedKeyRing.fromStream(bufferedInput);              while (it.hasNext()) {                  UncachedKeyRing ring = it.next();                  ImportKeysListEntry item = new ImportKeysListEntry(getContext(), ring); | 
