This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

refactoring

  • Loading branch information...
kryukov committed Nov 4, 2013
1 parent d161122 commit 8dbd783914f6454176ecd48ab54f6f06eb1cc5e8
@@ -42,6 +42,7 @@
import javax.microedition.rms.RecordStoreNotOpenException;

import org.microemu.RecordStoreManager;
import protocol.net.TcpSocket;


public class RecordStoreImpl extends RecordStore
@@ -56,7 +57,7 @@

private int size = 0;

private Hashtable records = new Hashtable();
private Hashtable<Integer, byte[]> records = new Hashtable<Integer, byte[]>();

private String recordStoreName;

@@ -68,7 +69,7 @@

private transient RecordStoreManager recordStoreManager;

private transient Vector recordListeners = new Vector();
private transient Vector<RecordListener> recordListeners = new Vector<RecordListener>();


public RecordStoreImpl(RecordStoreManager recordStoreManager, String recordStoreName)
@@ -122,7 +123,7 @@ public void readRecord(DataInputStream dis)
}
dis.readInt(); // TODO Tag
byte[] data = new byte[dis.readInt()];
dis.read(data, 0, data.length);
TcpSocket.readFully(dis, data, 0, data.length);
this.records.put(new Integer(recordId), data);
}

@@ -10,6 +10,7 @@
import jimm.history.HistoryStorage;
import jimm.modules.photo.PhotoListener;
import org.microemu.android.util.ActivityResultListener;
import protocol.net.TcpSocket;
import ru.net.jimm.photo.CameraActivity;

import java.io.File;
@@ -106,7 +107,7 @@ public boolean onActivityResult(int requestCode, int resultCode, Intent data) {
jimm.modules.DebugLog.println("pickFile " + uriImage);
InputStream in = activity.getContentResolver().openInputStream(uriImage);
byte[] img = new byte[in.available()];
in.read(img);
TcpSocket.readFully(in, img, 0, img.length);
photoListener.processPhoto(img);

imageUrl = null;
@@ -33,7 +33,7 @@ public static String getContent(String file) {
try {
stream = fs.openInputStream();
byte[] str = new byte[stream.available()];
stream.read(str);
TcpSocket.readFully(stream, str, 0, str.length);
result = StringUtils.utf8beByteArrayToString(str, 0, str.length);
} catch (Exception ignored) {
}
@@ -51,10 +51,7 @@ public static void putContent(String file, String content) {
stream.write(StringUtils.stringToByteArrayUtf8(content));
} catch (Exception ignored) {
}
try {
stream.close();
} catch (Exception ignored) {
}
TcpSocket.close(stream);
fs.close();
}
public static boolean exist(String file) {
@@ -12,6 +12,7 @@
import java.io.InputStream;
import java.util.Vector;
import jimm.util.JLocale;
import protocol.net.TcpSocket;

/**
*
@@ -28,14 +29,11 @@ public static String loadResource(String path) {
try {
stream = jimm.Jimm.getResourceAsStream(path);
byte[] str = new byte[stream.available()];
stream.read(str);
TcpSocket.readFully(stream, str,0, str.length);
res = StringUtils.utf8beByteArrayToString(str, 0, str.length);
} catch (Exception ignored) {
}
try {
if (null != stream) stream.close();
} catch (Exception ignored) {
}
TcpSocket.close(stream);
return res;
}
private String loadLocateResource(String path) {
@@ -105,8 +103,8 @@ private int parseConfig(String content, int index) {
final int PARSER_TO = 4;
final int PARSER_COMMENT = 5;

Vector _keys = new Vector();
Vector _values = new Vector();
Vector<String> _keys = new Vector<String>();
Vector<String> _values = new Vector<String>();

int state = PARSER_LINE;
int beginPos = index;
@@ -223,9 +221,9 @@ public static String getConfigValue(String key, String path) {
String currentKey = null;

String content = loadResource(path);
final int contentLenght = content.length();
for (int i = 0; i <= contentLenght; ++i) {
char ch = (i < contentLenght) ? content.charAt(i) : '\n';
final int contentLength = content.length();
for (int i = 0; i <= contentLength; ++i) {
char ch = (i < contentLength) ? content.charAt(i) : '\n';
switch (state) {
case PARSER_LINE:
if (';' == ch) {
@@ -39,7 +39,7 @@ public static InputStream openJimmFile(String file) {
fs.openFile(getJimmHome() + RES + "/" + file);
InputStream in = fs.openInputStream();
buffer = new byte[in.available()];
in.read(buffer);
TcpSocket.readFully(in, buffer, 0, buffer.length);
TcpSocket.close(in);
} catch (Exception e) {
buffer = null;
@@ -408,12 +408,7 @@ public void onFileSelect(String filename) throws JimmException {
int size = (int)file.fileSize();
if (size <= 30*1024*1024) {
byte[] binAvatar = new byte[size];
int readed = 0;
while (readed < binAvatar.length) {
int read = fis.read(binAvatar, readed, binAvatar.length - readed);
if (-1 == read) break;
readed += read;
}
TcpSocket.readFully(fis, binAvatar, 0, binAvatar.length);
setBinAvatar(binAvatar);
binAvatar = null;
}
@@ -53,7 +53,7 @@ private String getContent(String url) {
int length = (int) httemp.getLength();
if (-1 != length) {
byte[] bytes = new byte[length];
istemp.read(bytes);
TcpSocket.readFully(istemp, bytes, 0, bytes.length);
content = new String(bytes);

} else {
@@ -201,10 +201,9 @@ public void run() {
private void exec() {
if (TYPE_SHADOW == type) {
shadowConnection();
return;
}

// #sijapp cond.if (protocols_MRIM is "true") or (protocols_ICQ is "true") #
if (TYPE_AVATAR == type) {
} else if (TYPE_AVATAR == type) {
try {
userInfo.setAvatar(getAvatar());
if (null != userInfo.avatar) {
@@ -213,12 +212,10 @@ private void exec() {
} catch (OutOfMemoryError e) {
userInfo.setAvatar(null);
}
return;
}

// #sijapp cond.end#
if (TYPE_URL == type) {
} else if (TYPE_URL == type) {
getContent(url);
return;
}
}

@@ -167,6 +167,20 @@ public int available() throws JimmException {
}
}

public void startTls(String host) {
// #sijapp cond.if modules_ANDROID is "true" #
try {
jimm.modules.DebugLog.println("startTls start " + sc + os + is);
((org.microemu.cldc.socket.SocketConnection)sc).startTls(host);
is = sc.openInputStream();
os = sc.openOutputStream();
jimm.modules.DebugLog.println("startTls done " + sc + os + is);
} catch (Exception e) {
jimm.modules.DebugLog.panic("startTls error", e);
}
// #sijapp cond.end #
}

public void close() {
close(is);
close(os);
@@ -191,17 +205,23 @@ public static void close(OutputStream c) {
}
}

public void startTls(String host) {
// #sijapp cond.if modules_ANDROID is "true" #
try {
jimm.modules.DebugLog.println("startTls start " + sc + os + is);
((org.microemu.cldc.socket.SocketConnection)sc).startTls(host);
is = sc.openInputStream();
os = sc.openOutputStream();
jimm.modules.DebugLog.println("startTls done " + sc + os + is);
} catch (Exception e) {
jimm.modules.DebugLog.panic("startTls error", e);
public static int readFully(InputStream in, byte[] data, final int offset, final int length) throws IOException {
if ((null == data) || (0 == data.length)) {
return 0;
}
// #sijapp cond.end #
int bReadSum = 0;
do {
int bRead = in.read(data, offset + bReadSum, length - bReadSum);
if (-1 == bRead) {
throw new IOException("EOF");
} else if (0 == bRead) {
try {
Thread.sleep(100);
} catch (Exception ignored) {
}
}
bReadSum += bRead;
} while (bReadSum < length);
return bReadSum;
}
}
@@ -13,6 +13,7 @@
// #sijapp cond.if modules_FILES is "true"#
import jimm.*;
import jimm.comm.*;
import protocol.net.TcpSocket;


/**
@@ -67,7 +68,7 @@ public String initTransfer() {
}
try {
byte[] data = new byte[size];
ft.getFileIS().read(data);
TcpSocket.readFully(ft.getFileIS(), data, 0, data.length);
return data;
} catch (Exception ex) {
return null;

0 comments on commit 8dbd783

Please sign in to comment.