Before utf-8 encoding:
uSMo@W?=4JG"BġV8c{ٝMuM$>X|y/.gq*J -;g2ú7Ӽ~dSJoa`uO0vlJ1Dr27_
1
OhKj1AOp-*
#zNHyYd٢[ޒҨaondNgB4J"G$ep4Ld&pFzrYګv+
r~
,14`,1<WnREI
uhtlG2g-F|3j9TJk†?̒McŃ34kOh;qkOmJxJFʹSȊpZ#-ƋÒ.]?Tw%w<-c=6ͭS
p\|q&yaߠ{hUjMO씱eIVTI
tX\>!?7u!%
After utf-8 encoding: %1F%EF%BF%BD%08%00%00%00%00%00%00%03uSMo%EF%BF%BD%40%10%EF%BF%BDW%EF%BF%BD%3F%0C%3D4%12J%13%EF%BF%BDG%1A%22%EF%BF%BDB%C4%A1%EF%BF%BD%EF%BF%BDV%EF%BF%BD8%EF%BF%BD%EF%BF%BDc%7B%EF%BF%BD%EF%BF%BD%D9%9DM%EF%BF%BD%10%EF%BF%BD etc etc..
Relevant code is below:
/**
* Load an attachment from the Couch database and set the result in the view on the UI thread. Two views are currently supported, {@link WebView} for HTML and {@link ImageView} for pngs
*
* @param view
* @param activity
* @param portalItemBase
*/
public static void loadAttachment(final View view, final Activity activity, final PortalItemBaseNode portalItemBase, final String inAttachmentID) {
AsyncTask<Void, Void, Object> task = new AsyncTask<Void, Void, Object>() {
private ProgressDialog progress;
private static final int TYPE_WEB = 1;
private static final int TYPE_IMAGE = 2;
private static final int TYPE_IMAGE_SCALEABLE = 3;
private int mType;
private Matrix imageMatrix;
@Override
protected void onPreExecute() {
if (view instanceof WebView) {
mType = TYPE_WEB;
} else if (view instanceof ImageViewTouch) {
mType = TYPE_IMAGE_SCALEABLE;
} else if (view instanceof ImageView) {
mType = TYPE_IMAGE;
}
progress = ProgressDialog.show(activity, activity.getString(R.string.please_wait), activity.getString(R.string.loading));
}
@Override
protected Object doInBackground(Void... arg0) {
String dbName = SevenCityApplication.getModel().getSelectedSitting().getDatabaseName();
String attachmentName = getFirstAttachmentName(portalItemBase);
InputStream in = SevenCityApplication.getModel().getSyncer().getAttachment(dbName, portalItemBase.getId(), attachmentName);
if (in != null) {
if (mType == TYPE_WEB) {
String result = "";
try {
result = inputStreamAsString(in);
in.close();
} catch (IOException e) {
e.printStackTrace();
}
return result;
} else if (mType == TYPE_IMAGE || mType == TYPE_IMAGE_SCALEABLE) {
Bitmap b = BitmapFactory.decodeStream(in);
try {
in.close();
} catch (IOException e) {
e.printStackTrace();
}
return b;
}
}
return null;
}
@Override
protected void onPostExecute(Object result) {
if (DebugHandler.LOG_ENABLED) {
DebugHandler.log(this, "LOADED " + (result != null) + " " + mType);
}
if (result != null) {
if (mType == TYPE_WEB) {
try {
String encoding = UTF_8;
String data = URLEncoder.encode((String) result, encoding).replaceAll("\\+", " ");
DebugHandler.log(this, "Before "+encoding+" encoding: "+result+"\nAfter "+encoding+" encoding: "+data);
((WebView) view).loadData(data, MIME_TYPE_TEXT_HTML, UTF_8);
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
} else if (mType == TYPE_IMAGE) {
((ImageView) view).setImageBitmap((Bitmap) result);
} else if (mType == TYPE_IMAGE_SCALEABLE) {
if (null == imageMatrix) {
imageMatrix = new Matrix();
} else {
imageMatrix = ((ImageViewTouch) view).getDisplayMatrix();
}
((ImageViewTouch) view).setImageBitmap((Bitmap) result);
}
} else {
if (DebugHandler.LOG_ENABLED) {
DebugHandler.log(this, "Attachment is null " + portalItemBase.getId());
}
}
progress.dismiss();
}
};
if (android.os.Build.VERSION.SDK_INT <= android.os.Build.VERSION_CODES.HONEYCOMB) {
task.execute();
} else {
task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
}
/**
* Get the name of the first attachement of the {@link CouchDbDocument} supplied
*
* @param doc
* @return
*/
public static String getFirstAttachmentName(CouchDbDocument doc) {
List<String> attachmentNames = doc.getDocument().getCurrentRevision().getAttachmentNames();
for(String attachmentName : attachmentNames) {
return attachmentName;
}
return null;
}
/**
* Read an input stream into a String
*
* @param stream
* @return
* @throws IOException
*/
public static String inputStreamAsString(InputStream stream) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(stream));
StringBuilder sb = new StringBuilder();
String line = null;
try {
while ((line = br.readLine()) != null) {
sb.append(line + "\n");
}
} catch (IOException e) {
e.printStackTrace();
} finally {
br.close();
stream.close();
}
return sb.toString();
}
/**
* Get the attachment from the DB dbName
*
* @param dbName
* @param id
* @param attachmentId
* @return
*/
public InputStream getAttachment(String dbName, String id, String attachmentId) {
InputStream ret = null;
if (id == null || attachmentId == null) {
return null;
} else {
Database structuralDB;
try {
structuralDB = SevenCityApplication.getDatabase(dbName);
Document doc = structuralDB.getDocument(id);
Revision rev = doc.getCurrentRevision();
Attachment att = rev.getAttachment(attachmentId);
if(att != null) {
ret = att.getContent();
}
} catch (CouchbaseLiteException e) {
e.printStackTrace();
}
return ret;
}
}
The attachment content type is text/html. The thnl rendered fine with the old CBL/Ektorp setup.
Do I have to process the InputStream in method inputStreamAsString differently with CBL 1.0.x?
--
You received this message because you are subscribed to the Google Groups "Couchbase Mobile" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mobile-couchba...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/mobile-couchbase/32ebbd25-f552-4435-a549-b558a79fae45%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
...
--
You received this message because you are subscribed to the Google Groups "Couchbase Mobile" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mobile-couchba...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/mobile-couchbase/be927ed5-f67c-4172-a2aa-b7237dcd24b2%40googlegroups.com.
...String data = URLEncoder.encode((String) result, encoding).<span style="color:#000
...<span style
--
You received this message because you are subscribed to the Google Groups "Couchbase Mobile" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mobile-couchba...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/mobile-couchbase/cdb404b0-62de-48fd-bd62-cebf501ed21e%40googlegroups.com.