package ai.suanzi.rtmpclient;
-import android.content.Context;
-import android.util.Log;
import android.widget.Toast;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
-import java.io.InputStream;
+
import org.json.JSONException;
import org.json.JSONObject;
+import org.apache.log4j.Logger;
public class UserInfo {
public String macAddr = "";
public String cameraId = "";
private static String configPath;
+ private static Logger gLogger = Logger.getLogger("UserInfo");
+
private static UserInfo instance = null;
private UserInfo () {}
public static void setConfigPath(String fname){
configPath = fname;
+ File file = new File(configPath);
+ if(!file.exists()) {
+ gLogger.error("Config file: " + configPath + " not exists! Create it");
+ try {
+ file.createNewFile();
+ }catch (IOException e){
+ gLogger.error("Create file error: " + e.getMessage());
+ e.printStackTrace();
+ }
+ }
}
public static UserInfo getConfig() {
if (instance != null) return instance;
File file = new File(configPath);
- if (!file.exists()) return new UserInfo();
+ if (!file.exists()){
+ gLogger.error("getConfig - file configpath: " + configPath + " not exists");
+ return new UserInfo();
+ }
StringBuilder text = new StringBuilder();
try {
info.macAddr = jobj.getString("macAddr");
info.cameraId = jobj.getString("cameraId");
} catch (JSONException e){
+ gLogger.error("getConfig - error: " + e.getMessage());
e.printStackTrace();
}
instance = info;
String jstring = toString();
- Log.e("Config", "xxxxxxxxx " + jstring);
-
File file = new File(configPath);
try{
BufferedWriter bw = new BufferedWriter(new FileWriter(file));
bw.write(jstring);
bw.close();
} catch (IOException e){
+ gLogger.error("saveConfig - error: " + e.getMessage());
e.printStackTrace();
return false;
}
public String toString () {
JSONObject obj = toJsonObj();
- if (obj.equals(null)) return "";
- return obj.toString();
+ String str = "";
+ if (!obj.equals(null)) {
+ try {
+ str = obj.toString(4);
+ }catch (JSONException e){
+ gLogger.error("toString - error: " + e.getMessage());
+ e.printStackTrace();
+ }
+ }
+ return str;
}
private JSONObject toJsonObj () {
return null;
}
}
+
+ public String toUrl () {
+ //rtmp://gpussh.suanzi.ai:1935/myapp/suanzi_ac83f34ead90_cameraid
+ return server + "/" + user + "_" + macAddr + "_" + cameraId;
+ }
}