Small improvements

pull/162/head
M66B 6 years ago
parent 1269b0f49a
commit 45606afd3b

@ -61,8 +61,7 @@ import org.jsoup.Jsoup;
import org.jsoup.nodes.Element; import org.jsoup.nodes.Element;
import java.io.BufferedInputStream; import java.io.BufferedInputStream;
import java.io.ByteArrayInputStream; import java.io.BufferedOutputStream;
import java.io.ByteArrayOutputStream;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
@ -696,7 +695,7 @@ class Core {
throw new IllegalArgumentException("raw message file not found"); throw new IllegalArgumentException("raw message file not found");
Log.i(folder.name + " reading " + file); Log.i(folder.name + " reading " + file);
try (InputStream is = new FileInputStream(file)) { try (InputStream is = new BufferedInputStream(new FileInputStream(file))) {
imessage = new MimeMessage(isession, is); imessage = new MimeMessage(isession, is);
} }
} }
@ -776,7 +775,7 @@ class Core {
Message imessage = ifolder.getMessageByUID(message.uid); Message imessage = ifolder.getMessageByUID(message.uid);
if (imessage != null) if (imessage != null)
map.put(imessage, message); map.put(imessage, message);
} catch (MessageRemovedException ex) { } catch (MessagingException ex) {
Log.w(ex); Log.w(ex);
} }
@ -789,7 +788,7 @@ class Core {
EntityMessage message = map.get(imessage); EntityMessage message = map.get(imessage);
File file = File.createTempFile("draft", "." + message.id, context.getCacheDir()); File file = File.createTempFile("draft", "." + message.id, context.getCacheDir());
try (OutputStream os = new FileOutputStream(file)) { try (OutputStream os = new BufferedOutputStream(new FileOutputStream(file))) {
imessage.writeTo(os); imessage.writeTo(os);
} }
@ -1026,10 +1025,11 @@ class Core {
throw new MessageRemovedException(); throw new MessageRemovedException();
File file = message.getRawFile(context); File file = message.getRawFile(context);
try (OutputStream os = new FileOutputStream(file)) { try (OutputStream os = new BufferedOutputStream(new FileOutputStream(file))) {
imessage.writeTo(os); imessage.writeTo(os);
db.message().setMessageRaw(message.id, true);
} }
db.message().setMessageRaw(message.id, true);
} }
if (jargs.length() > 0) { if (jargs.length() > 0) {
@ -1911,17 +1911,20 @@ class Core {
Log.w(folder.name + " " + ex.getMessage()); Log.w(folder.name + " " + ex.getMessage());
Log.i(folder.name + " fetching raw message uid=" + uid); Log.i(folder.name + " fetching raw message uid=" + uid);
ByteArrayOutputStream bos = new ByteArrayOutputStream(); File file = File.createTempFile("serverbug", "." + uid, context.getCacheDir());
imessage.writeTo(bos); try (OutputStream os = new BufferedOutputStream(new FileOutputStream(file))) {
bos.close(); imessage.writeTo(os);
}
Properties properties = MessageHelper.getSessionProperties(); Properties props = MessageHelper.getSessionProperties();
Session isession = Session.getInstance(properties, null); Session isession = Session.getInstance(props, null);
Log.i(folder.name + " decoding again uid=" + uid); Log.i(folder.name + " decoding again uid=" + uid);
ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray()); try (InputStream is = new BufferedInputStream(new FileInputStream(file))) {
imessage = new MimeMessage(isession, bis); imessage = new MimeMessage(isession, is);
bis.close(); }
file.delete();
Log.i(folder.name + " synchronizing again uid=" + uid); Log.i(folder.name + " synchronizing again uid=" + uid);
return _synchronizeMessage(context, account, folder, uid, imessage, browsed, download, rules, state); return _synchronizeMessage(context, account, folder, uid, imessage, browsed, download, rules, state);

@ -114,6 +114,7 @@ import org.openintents.openpgp.OpenPgpError;
import org.openintents.openpgp.util.OpenPgpApi; import org.openintents.openpgp.util.OpenPgpApi;
import org.openintents.openpgp.util.OpenPgpServiceConnection; import org.openintents.openpgp.util.OpenPgpServiceConnection;
import java.io.BufferedOutputStream;
import java.io.BufferedWriter; import java.io.BufferedWriter;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
@ -1528,8 +1529,8 @@ public class FragmentCompose extends FragmentBase {
Log.i("Writing " + file + " size=" + bytes.length); Log.i("Writing " + file + " size=" + bytes.length);
try (OutputStream out = new FileOutputStream(file)) { try (OutputStream out = new FileOutputStream(file)) {
out.write(bytes); out.write(bytes);
db.attachment().setDownloaded(attachment.id, (long) bytes.length);
} }
db.attachment().setDownloaded(attachment.id, (long) bytes.length);
db.setTransactionSuccessful(); db.setTransactionSuccessful();
} finally { } finally {
@ -1973,7 +1974,7 @@ public class FragmentCompose extends FragmentBase {
} }
File tmp = File.createTempFile("image", ".resized", context.getCacheDir()); File tmp = File.createTempFile("image", ".resized", context.getCacheDir());
try (OutputStream out = new FileOutputStream(tmp)) { try (OutputStream out = new BufferedOutputStream(new FileOutputStream(tmp))) {
resized.compress("image/jpeg".equals(attachment.type) resized.compress("image/jpeg".equals(attachment.type)
? Bitmap.CompressFormat.JPEG ? Bitmap.CompressFormat.JPEG
: Bitmap.CompressFormat.PNG, : Bitmap.CompressFormat.PNG,

@ -61,6 +61,7 @@ import org.jsoup.safety.Whitelist;
import org.jsoup.select.NodeTraversor; import org.jsoup.select.NodeTraversor;
import org.jsoup.select.NodeVisitor; import org.jsoup.select.NodeVisitor;
import java.io.BufferedOutputStream;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
@ -702,7 +703,7 @@ public class HtmlHelper {
Log.i("Downloaded image source=" + a.source); Log.i("Downloaded image source=" + a.source);
try (OutputStream os = new FileOutputStream(file)) { try (OutputStream os = new BufferedOutputStream(new FileOutputStream(file))) {
bm.compress(Bitmap.CompressFormat.PNG, 90, os); bm.compress(Bitmap.CompressFormat.PNG, 90, os);
} }

@ -601,19 +601,18 @@ public class Log {
attachment.progress = 0; attachment.progress = 0;
attachment.id = db.attachment().insertAttachment(attachment); attachment.id = db.attachment().insertAttachment(attachment);
long size = 0;
File file = attachment.getFile(context); File file = attachment.getFile(context);
try (OutputStream os = new BufferedOutputStream(new FileOutputStream(file))) { try (OutputStream os = new BufferedOutputStream(new FileOutputStream(file))) {
long size = 0;
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
Map<String, ?> settings = prefs.getAll(); Map<String, ?> settings = prefs.getAll();
for (String key : settings.keySet()) for (String key : settings.keySet())
size += write(os, key + "=" + settings.get(key) + "\r\n"); size += write(os, key + "=" + settings.get(key) + "\r\n");
}
db.attachment().setDownloaded(attachment.id, size); db.attachment().setDownloaded(attachment.id, size);
} }
}
private static void attachAccounts(Context context, long id, int sequence) throws IOException { private static void attachAccounts(Context context, long id, int sequence) throws IOException {
DB db = DB.getInstance(context); DB db = DB.getInstance(context);
@ -628,11 +627,9 @@ public class Log {
attachment.progress = 0; attachment.progress = 0;
attachment.id = db.attachment().insertAttachment(attachment); attachment.id = db.attachment().insertAttachment(attachment);
long size = 0;
File file = attachment.getFile(context); File file = attachment.getFile(context);
try (OutputStream os = new BufferedOutputStream(new FileOutputStream(file))) { try (OutputStream os = new BufferedOutputStream(new FileOutputStream(file))) {
long size = 0;
List<EntityAccount> accounts = db.account().getAccounts(); List<EntityAccount> accounts = db.account().getAccounts();
for (EntityAccount account : accounts) for (EntityAccount account : accounts)
try { try {
@ -656,10 +653,10 @@ public class Log {
} catch (JSONException ex) { } catch (JSONException ex) {
size += write(os, ex.toString() + "\r\n"); size += write(os, ex.toString() + "\r\n");
} }
}
db.attachment().setDownloaded(attachment.id, size); db.attachment().setDownloaded(attachment.id, size);
} }
}
private static void attachNetworkInfo(Context context, long id, int sequence) throws IOException { private static void attachNetworkInfo(Context context, long id, int sequence) throws IOException {
DB db = DB.getInstance(context); DB db = DB.getInstance(context);
@ -674,10 +671,9 @@ public class Log {
attachment.progress = 0; attachment.progress = 0;
attachment.id = db.attachment().insertAttachment(attachment); attachment.id = db.attachment().insertAttachment(attachment);
long size = 0;
File file = attachment.getFile(context); File file = attachment.getFile(context);
try (OutputStream os = new BufferedOutputStream(new FileOutputStream(file))) { try (OutputStream os = new BufferedOutputStream(new FileOutputStream(file))) {
long size = 0;
ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
Network active = null; Network active = null;
@ -688,10 +684,10 @@ public class Log {
NetworkCapabilities caps = cm.getNetworkCapabilities(network); NetworkCapabilities caps = cm.getNetworkCapabilities(network);
size += write(os, (network.equals(active) ? "active=" : "network=") + network + " capabilities=" + caps + "\r\n\r\n"); size += write(os, (network.equals(active) ? "active=" : "network=") + network + " capabilities=" + caps + "\r\n\r\n");
} }
}
db.attachment().setDownloaded(attachment.id, size); db.attachment().setDownloaded(attachment.id, size);
} }
}
private static void attachLog(Context context, long id, int sequence) throws IOException { private static void attachLog(Context context, long id, int sequence) throws IOException {
DB db = DB.getInstance(context); DB db = DB.getInstance(context);
@ -706,19 +702,18 @@ public class Log {
attachment.progress = 0; attachment.progress = 0;
attachment.id = db.attachment().insertAttachment(attachment); attachment.id = db.attachment().insertAttachment(attachment);
long size = 0;
File file = attachment.getFile(context); File file = attachment.getFile(context);
try (OutputStream os = new BufferedOutputStream(new FileOutputStream(file))) { try (OutputStream os = new BufferedOutputStream(new FileOutputStream(file))) {
long size = 0;
long from = new Date().getTime() - 24 * 3600 * 1000L; long from = new Date().getTime() - 24 * 3600 * 1000L;
DateFormat TF = Helper.getTimeInstance(context); DateFormat TF = Helper.getTimeInstance(context);
for (EntityLog entry : db.log().getLogs(from)) for (EntityLog entry : db.log().getLogs(from))
size += write(os, String.format("%s %s\r\n", TF.format(entry.time), entry.data)); size += write(os, String.format("%s %s\r\n", TF.format(entry.time), entry.data));
}
db.attachment().setDownloaded(attachment.id, size); db.attachment().setDownloaded(attachment.id, size);
} }
}
private static void attachOperations(Context context, long id, int sequence) throws IOException { private static void attachOperations(Context context, long id, int sequence) throws IOException {
DB db = DB.getInstance(context); DB db = DB.getInstance(context);
@ -733,10 +728,9 @@ public class Log {
attachment.progress = 0; attachment.progress = 0;
attachment.id = db.attachment().insertAttachment(attachment); attachment.id = db.attachment().insertAttachment(attachment);
long size = 0;
File file = attachment.getFile(context); File file = attachment.getFile(context);
try (OutputStream os = new BufferedOutputStream(new FileOutputStream(file))) { try (OutputStream os = new BufferedOutputStream(new FileOutputStream(file))) {
long size = 0;
DateFormat TF = Helper.getTimeInstance(context); DateFormat TF = Helper.getTimeInstance(context);
for (EntityOperation op : db.operation().getOperations()) for (EntityOperation op : db.operation().getOperations())
@ -746,10 +740,10 @@ public class Log {
op.name, op.name,
op.args, op.args,
op.error)); op.error));
}
db.attachment().setDownloaded(attachment.id, size); db.attachment().setDownloaded(attachment.id, size);
} }
}
private static void attachLogcat(Context context, long id, int sequence) throws IOException { private static void attachLogcat(Context context, long id, int sequence) throws IOException {
DB db = DB.getInstance(context); DB db = DB.getInstance(context);
@ -767,7 +761,6 @@ public class Log {
Process proc = null; Process proc = null;
File file = attachment.getFile(context); File file = attachment.getFile(context);
try (OutputStream os = new BufferedOutputStream(new FileOutputStream(file))) { try (OutputStream os = new BufferedOutputStream(new FileOutputStream(file))) {
String[] cmd = new String[]{"logcat", String[] cmd = new String[]{"logcat",
"-d", "-d",
"-v", "threadtime", "-v", "threadtime",
@ -782,7 +775,6 @@ public class Log {
size += write(os, line + "\r\n"); size += write(os, line + "\r\n");
} }
db.attachment().setDownloaded(attachment.id, size); db.attachment().setDownloaded(attachment.id, size);
} finally { } finally {
if (proc != null) if (proc != null)

Loading…
Cancel
Save