Small fix around intermideate charset (ISO-8859-1).
After a few investigation, it is found that ISO-8859-1 is confirmed to be the best charset for that use. Modify comment so that we explicitly mention it. Change-Id: I16e487fab33964a1665a1dd6991f2e8598f8895e
This commit is contained in:
@@ -43,15 +43,20 @@ public class VCardConfig {
|
||||
* The charset used during import.
|
||||
* </p>
|
||||
* <p>
|
||||
* We cannot determine which charset should be used to interpret a given vCard file
|
||||
* at first, while we have to decode sime encoded data (e.g. BASE64) to binary.
|
||||
* In order to avoid "misinterpretation" of charset as much as possible,
|
||||
* "ISO-8859-1" (a.k.a Latin-1) is first used for reading a stream.
|
||||
* When charset is specified in a property (with "CHARSET=..." parameter),
|
||||
* We cannot determine which charset should be used to interpret lines in vCard,
|
||||
* while Java requires us to specify it when InputStream is used.
|
||||
* We need to rely on the mechanism due to some performance reason.
|
||||
* </p>
|
||||
* <p>
|
||||
* In order to avoid "misinterpretation" of charset and lose any data in vCard,
|
||||
* "ISO-8859-1" is first used for reading the stream.
|
||||
* When a charset is specified in a property (with "CHARSET=..." parameter),
|
||||
* the string is decoded to raw bytes and encoded into the specific charset,
|
||||
* assuming "ISO-8859-1" is able to map "all" 8bit characters to some unicode,
|
||||
* and it has 1 to 1 mapping in all 8bit characters.
|
||||
* If the assumption is not correct, this setting will cause some bug.
|
||||
* </p>
|
||||
* <p>
|
||||
* Unicode specification there's a one to one mapping between each byte in ISO-8859-1
|
||||
* and a codepoint, and Java specification requires runtime must have the charset.
|
||||
* Thus, ISO-8859-1 is one effective mapping for intermediate mapping.
|
||||
* </p>
|
||||
*/
|
||||
public static final String DEFAULT_INTERMEDIATE_CHARSET = "ISO-8859-1";
|
||||
|
||||
@@ -68,7 +68,7 @@ public class VCardEntryConstructor implements VCardInterpreter {
|
||||
private final List<VCardEntryHandler> mEntryHandlers = new ArrayList<VCardEntryHandler>();
|
||||
|
||||
public VCardEntryConstructor() {
|
||||
this(VCardConfig.VCARD_TYPE_V21_GENERIC, null, null, false);
|
||||
this(VCardConfig.VCARD_TYPE_V21_GENERIC, null);
|
||||
}
|
||||
|
||||
public VCardEntryConstructor(final int vcardType) {
|
||||
@@ -85,7 +85,7 @@ public class VCardEntryConstructor implements VCardInterpreter {
|
||||
}
|
||||
|
||||
/**
|
||||
* @hide
|
||||
* @hide Just for testing.
|
||||
*/
|
||||
public VCardEntryConstructor(final int vcardType, final Account account,
|
||||
final String inputCharset, final boolean strictLineBreakParsing) {
|
||||
|
||||
@@ -15,7 +15,6 @@
|
||||
*/
|
||||
package com.android.vcard;
|
||||
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
|
||||
import com.android.vcard.exception.VCardAgentNotSupportedException;
|
||||
@@ -64,12 +63,12 @@ import java.util.Set;
|
||||
}
|
||||
}
|
||||
|
||||
private static final String sDefaultEncoding = "8BIT";
|
||||
private static final String DEFAULT_ENCODING = "8BIT";
|
||||
|
||||
protected boolean mCanceled;
|
||||
protected VCardInterpreter mInterpreter;
|
||||
|
||||
protected final String mImportCharset;
|
||||
protected final String mIntermediateCharset;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
@@ -136,20 +135,15 @@ import java.util.Set;
|
||||
private long mTimeHandleBase64;
|
||||
|
||||
public VCardParserImpl_V21() {
|
||||
this(VCardConfig.VCARD_TYPE_DEFAULT, null);
|
||||
this(VCardConfig.VCARD_TYPE_DEFAULT);
|
||||
}
|
||||
|
||||
public VCardParserImpl_V21(int vcardType) {
|
||||
this(vcardType, null);
|
||||
}
|
||||
|
||||
public VCardParserImpl_V21(int vcardType, String importCharset) {
|
||||
if ((vcardType & VCardConfig.FLAG_TORELATE_NEST) != 0) {
|
||||
mNestCount = 1;
|
||||
}
|
||||
|
||||
mImportCharset = (!TextUtils.isEmpty(importCharset) ? importCharset :
|
||||
VCardConfig.DEFAULT_INTERMEDIATE_CHARSET);
|
||||
mIntermediateCharset = VCardConfig.DEFAULT_INTERMEDIATE_CHARSET;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -385,7 +379,7 @@ import java.util.Set;
|
||||
* "AGENT" [params] ":" vcard CRLF
|
||||
*/
|
||||
protected boolean parseItem() throws IOException, VCardException {
|
||||
mCurrentEncoding = sDefaultEncoding;
|
||||
mCurrentEncoding = DEFAULT_ENCODING;
|
||||
|
||||
final String line = getNonEmptyLine();
|
||||
long start = System.currentTimeMillis();
|
||||
@@ -928,7 +922,7 @@ import java.util.Set;
|
||||
}
|
||||
|
||||
protected String getDefaultEncoding() {
|
||||
return sDefaultEncoding;
|
||||
return DEFAULT_ENCODING;
|
||||
}
|
||||
|
||||
|
||||
@@ -938,7 +932,7 @@ import java.util.Set;
|
||||
throw new NullPointerException("InputStream must not be null.");
|
||||
}
|
||||
|
||||
final InputStreamReader tmpReader = new InputStreamReader(is, mImportCharset);
|
||||
final InputStreamReader tmpReader = new InputStreamReader(is, mIntermediateCharset);
|
||||
if (VCardConfig.showPerformanceLog()) {
|
||||
mReader = new CustomBufferedReader(tmpReader);
|
||||
} else {
|
||||
|
||||
@@ -46,11 +46,7 @@ import java.util.Set;
|
||||
}
|
||||
|
||||
public VCardParserImpl_V30(int vcardType) {
|
||||
super(vcardType, null);
|
||||
}
|
||||
|
||||
public VCardParserImpl_V30(int vcardType, String importCharset) {
|
||||
super(vcardType, importCharset);
|
||||
super(vcardType);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -98,10 +98,6 @@ public final class VCardParser_V21 implements VCardParser {
|
||||
mVCardParserImpl = new VCardParserImpl_V21(vcardType);
|
||||
}
|
||||
|
||||
public VCardParser_V21(int parseType, String inputCharset) {
|
||||
mVCardParserImpl = new VCardParserImpl_V21(parseType, null);
|
||||
}
|
||||
|
||||
public void parse(InputStream is, VCardInterpreter interepreter)
|
||||
throws IOException, VCardException {
|
||||
mVCardParserImpl.parse(is, interepreter);
|
||||
|
||||
@@ -76,10 +76,6 @@ public class VCardParser_V30 implements VCardParser {
|
||||
mVCardParserImpl = new VCardParserImpl_V30(vcardType);
|
||||
}
|
||||
|
||||
public VCardParser_V30(int vcardType, String importCharset) {
|
||||
mVCardParserImpl = new VCardParserImpl_V30(vcardType, importCharset);
|
||||
}
|
||||
|
||||
public void parse(InputStream is, VCardInterpreter interepreter)
|
||||
throws IOException, VCardException {
|
||||
mVCardParserImpl.parse(is, interepreter);
|
||||
|
||||
@@ -66,8 +66,7 @@ public class ContentValuesVerifier implements VCardEntryHandler {
|
||||
|
||||
public void verify(InputStream is, int vCardType, final VCardParser vCardParser)
|
||||
throws IOException, VCardException {
|
||||
VCardEntryConstructor builder =
|
||||
new VCardEntryConstructor(vCardType, null, null, false);
|
||||
VCardEntryConstructor builder = new VCardEntryConstructor(vCardType, null);
|
||||
builder.addEntryHandler(this);
|
||||
try {
|
||||
vCardParser.parse(is, builder);
|
||||
|
||||
@@ -62,8 +62,7 @@ public class ContentValuesVerifierElem {
|
||||
} else {
|
||||
vCardParser = new VCardParser_V21();
|
||||
}
|
||||
VCardEntryConstructor builder =
|
||||
new VCardEntryConstructor(vCardType, null, null, false);
|
||||
final VCardEntryConstructor builder = new VCardEntryConstructor(vCardType, null);
|
||||
builder.addEntryHandler(mHandler);
|
||||
try {
|
||||
vCardParser.parse(is, builder);
|
||||
|
||||
@@ -62,23 +62,11 @@ import java.util.List;
|
||||
private boolean mStrictLineBreakParsing;
|
||||
|
||||
public VNodeBuilder() {
|
||||
this(VCardConfig.DEFAULT_INTERMEDIATE_CHARSET, VCardConfig.DEFAULT_IMPORT_CHARSET, false);
|
||||
this(VCardConfig.DEFAULT_IMPORT_CHARSET, false);
|
||||
}
|
||||
|
||||
public VNodeBuilder(String targetCharset, boolean strictLineBreakParsing) {
|
||||
this(null, targetCharset, strictLineBreakParsing);
|
||||
}
|
||||
|
||||
/**
|
||||
* @hide sourceCharset is temporal.
|
||||
*/
|
||||
public VNodeBuilder(String sourceCharset, String targetCharset,
|
||||
boolean strictLineBreakParsing) {
|
||||
if (sourceCharset != null) {
|
||||
mSourceCharset = sourceCharset;
|
||||
} else {
|
||||
mSourceCharset = VCardConfig.DEFAULT_INTERMEDIATE_CHARSET;
|
||||
}
|
||||
mSourceCharset = VCardConfig.DEFAULT_INTERMEDIATE_CHARSET;
|
||||
if (targetCharset != null) {
|
||||
mTargetCharset = targetCharset;
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user