aboutsummaryrefslogtreecommitdiffstats
path: root/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations
diff options
context:
space:
mode:
authorVincent Breitmoser <valodim@mugenguild.com>2016-02-22 23:38:02 +0100
committerVincent Breitmoser <valodim@mugenguild.com>2016-02-22 23:38:02 +0100
commita0c90f0ad57b66d6e7e0957526748b2e4a239063 (patch)
treebe139ea868ffde874c5cf6a696d94005032b05b0 /OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations
parent4df63ccdeb8bd26f507c88980b360bdc367faa0f (diff)
downloadopen-keychain-a0c90f0ad57b66d6e7e0957526748b2e4a239063.tar.gz
open-keychain-a0c90f0ad57b66d6e7e0957526748b2e4a239063.tar.bz2
open-keychain-a0c90f0ad57b66d6e7e0957526748b2e4a239063.zip
documentation and cleanup
Diffstat (limited to 'OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations')
-rw-r--r--OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/CharsetVerifier.java24
-rw-r--r--OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/InputDataOperation.java2
2 files changed, 23 insertions, 3 deletions
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/CharsetVerifier.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/CharsetVerifier.java
index 5d63ced22..c563beeac 100644
--- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/CharsetVerifier.java
+++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/CharsetVerifier.java
@@ -12,7 +12,14 @@ import android.content.ClipDescription;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
-
+/** This class can be used to guess whether a stream of data is encoded in a given
+ * charset or not.
+ *
+ * An object of this class must be initialized with a byte[] buffer, which should
+ * be filled with data, then processed with {@link #readBytesFromBuffer}. This can
+ * be done any number of times. Once all data has been read, a final status can be
+ * read using the getter methods.
+ */
public class CharsetVerifier {
private final ByteBuffer bufWrap;
@@ -58,7 +65,7 @@ public class CharsetVerifier {
charsetDecoder.reset();
}
- public void write(int pos, int len) {
+ public void readBytesFromBuffer(int pos, int len) {
if (isFinished) {
throw new IllegalStateException("cannot write again after reading charset status!");
}
@@ -111,12 +118,25 @@ public class CharsetVerifier {
return charset;
}
+ /** Returns true if the data which was read is definitely binary.
+ *
+ * This can happen when either the supplied mimeType indicated a non-ambiguous
+ * binary data type, or if we guessed a charset but got errors while decoding.
+ */
public boolean isDefinitelyBinary() {
finishIfNecessary();
return !isTextMimeType && (!isPossibleTextMimeType || (isGuessed && isFaulty));
}
+ /** Returns true iff the data which was read is probably (or
+ * definitely) text.
+ *
+ * The corner case where isDefinitelyBinary returns false but isProbablyText
+ * returns true is where the charset was provided by the data (so is not
+ * guessed) but is still faulty.
+ */
public boolean isProbablyText() {
+ finishIfNecessary();
return isTextMimeType || isPossibleTextMimeType && (!isGuessed || !isFaulty);
}
}
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/InputDataOperation.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/InputDataOperation.java
index ff9377581..74d94d83e 100644
--- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/InputDataOperation.java
+++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/InputDataOperation.java
@@ -335,7 +335,7 @@ public class InputDataOperation extends BaseOperation<InputDataParcel> {
do {
totalLength += len;
out.write(buf, 0, len);
- charsetVerifier.write(0, len);
+ charsetVerifier.readBytesFromBuffer(0, len);
} while ((len = is.read(buf)) > 0);
log.add(LogType.MSG_DATA_MIME_LENGTH, 3, Long.toString(totalLength));