optimize string operations a bit

This commit is contained in:
M. Dietrich 2014-09-01 10:40:45 +02:00
parent 3558fa5f5b
commit 2acf510ea9
12 changed files with 26 additions and 26 deletions

View File

@ -106,8 +106,8 @@ public class PgpEngine {
outputFile.getAbsolutePath(), options); outputFile.getAbsolutePath(), options);
int imageHeight = options.outHeight; int imageHeight = options.outHeight;
int imageWidth = options.outWidth; int imageWidth = options.outWidth;
message.setBody("" + outputFile.getSize() + "," message.setBody(Long.toString(outputFile.getSize()) + ','
+ imageWidth + "," + imageHeight); + imageWidth + ',' + imageHeight);
message.setEncryption(Message.ENCRYPTION_DECRYPTED); message.setEncryption(Message.ENCRYPTION_DECRYPTED);
PgpEngine.this.mXmppConnectionService PgpEngine.this.mXmppConnectionService
.updateMessage(message); .updateMessage(message);

View File

@ -150,13 +150,13 @@ public class Message extends AbstractEntity {
public String getReadableBody(Context context) { public String getReadableBody(Context context) {
if ((encryption == ENCRYPTION_PGP) && (type == TYPE_TEXT)) { if ((encryption == ENCRYPTION_PGP) && (type == TYPE_TEXT)) {
return "" + context.getText(R.string.encrypted_message_received); return context.getText(R.string.encrypted_message_received).toString();
} else if ((encryption == ENCRYPTION_OTR) && (type == TYPE_IMAGE)) { } else if ((encryption == ENCRYPTION_OTR) && (type == TYPE_IMAGE)) {
return "" + context.getText(R.string.encrypted_image_received); return context.getText(R.string.encrypted_image_received).toString();
} else if (encryption == ENCRYPTION_DECRYPTION_FAILED) { } else if (encryption == ENCRYPTION_DECRYPTION_FAILED) {
return "" + context.getText(R.string.decryption_failed); return context.getText(R.string.decryption_failed).toString();
} else if (type == TYPE_IMAGE) { } else if (type == TYPE_IMAGE) {
return "" + context.getText(R.string.image_file); return context.getText(R.string.image_file).toString();
} else { } else {
return body.trim(); return body.trim();
} }

View File

@ -137,7 +137,7 @@ public class DatabaseBackend extends SQLiteOpenHelper {
public CopyOnWriteArrayList<Conversation> getConversations(int status) { public CopyOnWriteArrayList<Conversation> getConversations(int status) {
CopyOnWriteArrayList<Conversation> list = new CopyOnWriteArrayList<Conversation>(); CopyOnWriteArrayList<Conversation> list = new CopyOnWriteArrayList<Conversation>();
SQLiteDatabase db = this.getReadableDatabase(); SQLiteDatabase db = this.getReadableDatabase();
String[] selectionArgs = { "" + status }; String[] selectionArgs = { Integer.toString(status) };
Cursor cursor = db.rawQuery("select * from " + Conversation.TABLENAME Cursor cursor = db.rawQuery("select * from " + Conversation.TABLENAME
+ " where " + Conversation.STATUS + " = ? order by " + " where " + Conversation.STATUS + " = ? order by "
+ Conversation.CREATED + " desc", selectionArgs); + Conversation.CREATED + " desc", selectionArgs);
@ -163,7 +163,7 @@ public class DatabaseBackend extends SQLiteOpenHelper {
+ "=?", selectionArgs, null, null, Message.TIME_SENT + "=?", selectionArgs, null, null, Message.TIME_SENT
+ " DESC", String.valueOf(limit)); + " DESC", String.valueOf(limit));
} else { } else {
String[] selectionArgs = { conversation.getUuid(), "" + timestamp }; String[] selectionArgs = { conversation.getUuid(), Long.toString(timestamp) };
cursor = db.query(Message.TABLENAME, null, Message.CONVERSATION cursor = db.query(Message.TABLENAME, null, Message.CONVERSATION
+ "=? and " + Message.TIME_SENT + "<?", selectionArgs, + "=? and " + Message.TIME_SENT + "<?", selectionArgs,
null, null, Message.TIME_SENT + " DESC", null, null, Message.TIME_SENT + " DESC",

View File

@ -180,7 +180,7 @@ public class FileBackend {
long size = file.getSize(); long size = file.getSize();
int width = scalledBitmap.getWidth(); int width = scalledBitmap.getWidth();
int height = scalledBitmap.getHeight(); int height = scalledBitmap.getHeight();
message.setBody("" + size + "," + width + "," + height); message.setBody(Long.toString(size) + ',' + width + ',' + height);
return file; return file;
} catch (FileNotFoundException e) { } catch (FileNotFoundException e) {
throw new ImageCopyException(R.string.error_file_not_found); throw new ImageCopyException(R.string.error_file_not_found);

View File

@ -146,10 +146,10 @@ public class Element {
} }
public void setAttribute(String name, long value) { public void setAttribute(String name, long value) {
this.setAttribute(name, "" + value); this.setAttribute(name, Long.toString(value));
} }
public void setAttribute(String name, int value) { public void setAttribute(String name, int value) {
this.setAttribute(name, "" + value); this.setAttribute(name, Integer.toString(value));
} }
} }

View File

@ -117,9 +117,9 @@ public class JingleCandidate {
Element element = new Element("candidate"); Element element = new Element("candidate");
element.setAttribute("cid", this.getCid()); element.setAttribute("cid", this.getCid());
element.setAttribute("host", this.getHost()); element.setAttribute("host", this.getHost());
element.setAttribute("port", "" + this.getPort()); element.setAttribute("port", Integer.toString(this.getPort()));
element.setAttribute("jid", this.getJid()); element.setAttribute("jid", this.getJid());
element.setAttribute("priority", "" + this.getPriority()); element.setAttribute("priority", Integer.toString(this.getPriority()));
if (this.getType() == TYPE_DIRECT) { if (this.getType() == TYPE_DIRECT) {
element.setAttribute("type", "direct"); element.setAttribute("type", "direct");
} else if (this.getType() == TYPE_PROXY) { } else if (this.getType() == TYPE_PROXY) {

View File

@ -95,7 +95,7 @@ public class JingleConnection {
BitmapFactory.decodeFile(file.getAbsolutePath(), options); BitmapFactory.decodeFile(file.getAbsolutePath(), options);
int imageHeight = options.outHeight; int imageHeight = options.outHeight;
int imageWidth = options.outWidth; int imageWidth = options.outWidth;
message.setBody("" + file.getSize() + "," + imageWidth + "," message.setBody(Long.toString(file.getSize()) + ',' + imageWidth + ','
+ imageHeight); + imageHeight);
mXmppConnectionService.databaseBackend.createMessage(message); mXmppConnectionService.databaseBackend.createMessage(message);
mXmppConnectionService.markMessage(message, mXmppConnectionService.markMessage(message,
@ -302,7 +302,7 @@ public class JingleConnection {
} }
if (supportedFile) { if (supportedFile) {
long size = Long.parseLong(fileSize.getContent()); long size = Long.parseLong(fileSize.getContent());
message.setBody("" + size); message.setBody(Long.toString(size));
conversation.getMessages().add(message); conversation.getMessages().add(message);
if (size <= this.mJingleConnectionManager if (size <= this.mJingleConnectionManager
.getAutoAcceptFileSize()) { .getAutoAcceptFileSize()) {
@ -630,7 +630,7 @@ public class JingleConnection {
this.transportId = this.mJingleConnectionManager.nextRandomId(); this.transportId = this.mJingleConnectionManager.nextRandomId();
content.setTransportId(this.transportId); content.setTransportId(this.transportId);
content.ibbTransport().setAttribute("block-size", content.ibbTransport().setAttribute("block-size",
"" + this.ibbBlockSize); Integer.toString(this.ibbBlockSize));
packet.setContent(content); packet.setContent(content);
this.sendJinglePacket(packet); this.sendJinglePacket(packet);
} }
@ -652,7 +652,7 @@ public class JingleConnection {
Content content = new Content("initiator", "a-file-offer"); Content content = new Content("initiator", "a-file-offer");
content.setTransportId(this.transportId); content.setTransportId(this.transportId);
content.ibbTransport().setAttribute("block-size", content.ibbTransport().setAttribute("block-size",
"" + this.ibbBlockSize); Integer.toString(this.ibbBlockSize));
answer.setContent(content); answer.setContent(content);
this.sendJinglePacket(answer); this.sendJinglePacket(answer);
return true; return true;

View File

@ -59,7 +59,7 @@ public class JingleInbandTransport extends JingleTransport {
Element open = iq.addChild("open", "http://jabber.org/protocol/ibb"); Element open = iq.addChild("open", "http://jabber.org/protocol/ibb");
open.setAttribute("sid", this.sessionId); open.setAttribute("sid", this.sessionId);
open.setAttribute("stanza", "iq"); open.setAttribute("stanza", "iq");
open.setAttribute("block-size", "" + this.blockSize); open.setAttribute("block-size", Integer.toString(this.blockSize));
this.account.getXmppConnection().sendIqPacket(iq, this.account.getXmppConnection().sendIqPacket(iq,
new OnIqPacketReceived() { new OnIqPacketReceived() {
@ -134,8 +134,8 @@ public class JingleInbandTransport extends JingleTransport {
iq.setTo(this.counterpart); iq.setTo(this.counterpart);
Element data = iq.addChild("data", Element data = iq.addChild("data",
"http://jabber.org/protocol/ibb"); "http://jabber.org/protocol/ibb");
data.setAttribute("seq", "" + this.seq); data.setAttribute("seq", Integer.toString(this.seq));
data.setAttribute("block-size", "" + this.blockSize); data.setAttribute("block-size", Integer.toString(this.blockSize));
data.setAttribute("sid", this.sessionId); data.setAttribute("sid", this.sessionId);
data.setContent(base64); data.setContent(base64);
this.account.getXmppConnection().sendIqPacket(iq, this.account.getXmppConnection().sendIqPacket(iq,

View File

@ -58,10 +58,10 @@ public class JingleSocks5Transport extends JingleTransport {
byte[] reply = new byte[2]; byte[] reply = new byte[2];
outputStream.write(login); outputStream.write(login);
inputStream.read(reply); inputStream.read(reply);
final String connect = Character.toString('\u0005') + '\u0001' + '\u0000'
+ '\u0003' + '\u0028' + destination + '\u0000'
+ '\u0000';
if (Arrays.equals(reply, expectedReply)) { if (Arrays.equals(reply, expectedReply)) {
String connect = "" + '\u0005' + '\u0001' + '\u0000'
+ '\u0003' + '\u0028' + destination + '\u0000'
+ '\u0000';
outputStream.write(connect.getBytes()); outputStream.write(connect.getBytes());
byte[] result = new byte[2]; byte[] result = new byte[2];
inputStream.read(result); inputStream.read(result);

View File

@ -30,7 +30,7 @@ public class Content extends Element {
"urn:xmpp:jingle:apps:file-transfer:3"); "urn:xmpp:jingle:apps:file-transfer:3");
Element offer = description.addChild("offer"); Element offer = description.addChild("offer");
Element file = offer.addChild("file"); Element file = offer.addChild("file");
file.addChild("size").setContent("" + actualFile.getSize()); file.addChild("size").setContent(Long.toString(actualFile.getSize()));
if (otr) { if (otr) {
file.addChild("name").setContent(actualFile.getName() + ".otr"); file.addChild("name").setContent(actualFile.getName() + ".otr");
} else { } else {

View File

@ -7,7 +7,7 @@ public class AckPacket extends AbstractStanza {
public AckPacket(int sequence, int smVersion) { public AckPacket(int sequence, int smVersion) {
super("a"); super("a");
this.setAttribute("xmlns", "urn:xmpp:sm:" + smVersion); this.setAttribute("xmlns", "urn:xmpp:sm:" + smVersion);
this.setAttribute("h", "" + sequence); this.setAttribute("h", Integer.toString(sequence));
} }
} }

View File

@ -8,7 +8,7 @@ public class ResumePacket extends AbstractStanza {
super("resume"); super("resume");
this.setAttribute("xmlns", "urn:xmpp:sm:" + smVersion); this.setAttribute("xmlns", "urn:xmpp:sm:" + smVersion);
this.setAttribute("previd", id); this.setAttribute("previd", id);
this.setAttribute("h", "" + sequence); this.setAttribute("h", Integer.toString(sequence));
} }
} }