Compare commits

...

4 Commits

View File

@ -2,6 +2,11 @@ package tctable;
//import android.util.Log; //import android.util.Log;
//import org.ccalm.dbms.AcceptJSON;
import org.json.JSONException;
import org.json.JSONObject;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.DataInputStream; import java.io.DataInputStream;
@ -12,14 +17,32 @@ import java.net.InetAddress;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.security.MessageDigest; import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException; import java.security.NoSuchAlgorithmException;
import java.util.Arrays;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
import java.util.Calendar; import java.util.Calendar;
import java.util.TimeZone; import java.util.TimeZone;
import logging.Logger;
public class Tools { public class Tools {
private static final Logger logger = Logger.getLogger(Tools.class);
public static JSONObject createJSONError(int code, String message, String setting, String marker) {
JSONObject json = new JSONObject();
try {
json.put("error_code", code);
json.put("error_message", Arrays.asList(message));
json.put("error_setting", Arrays.asList(setting));
json.put("error_marker", marker);
} catch (JSONException e) {
logger.error(e.getMessage());
}
return json;
}
public static String readStringFromInputStream(InputStream inputStream) { public static String readStringFromInputStream(InputStream inputStream) {
ByteArrayOutputStream result = new ByteArrayOutputStream(); ByteArrayOutputStream result = new ByteArrayOutputStream();
byte[] buffer = new byte[1024]; byte[] buffer = new byte[1024];
@ -398,7 +421,7 @@ public class Tools {
//Из руского DOC в юникод //Из руского DOC в юникод
public static String fromDOStoASCII(byte[] str) public static String fromDOStoASCII(byte[] str)
{ {
StringBuilder rez = new StringBuilder(); StringBuilder rez = new StringBuilder(1024);
for(int i=0; i <str.length; i++) for(int i=0; i <str.length; i++)
{ {
switch ((char)str[i]) switch ((char)str[i])
@ -1012,7 +1035,7 @@ public class Tools {
{ {
if(cutInt) if(cutInt)
{ {
StringBuilder val= new StringBuilder(); StringBuilder val= new StringBuilder(1024);
for(int i=0;i<str.length();i++) for(int i=0;i<str.length();i++)
{ {
if((str.charAt(i)=='-' && (val.length()==0 || val.charAt(0)!='-')) || str.charAt(i)=='0' || str.charAt(i)=='1' || str.charAt(i)=='2' || str.charAt(i)=='3' || str.charAt(i)=='4' || str.charAt(i)=='5' || str.charAt(i)=='6' || str.charAt(i)=='7' || str.charAt(i)=='8' || str.charAt(i)=='9') if((str.charAt(i)=='-' && (val.length()==0 || val.charAt(0)!='-')) || str.charAt(i)=='0' || str.charAt(i)=='1' || str.charAt(i)=='2' || str.charAt(i)=='3' || str.charAt(i)=='4' || str.charAt(i)=='5' || str.charAt(i)=='6' || str.charAt(i)=='7' || str.charAt(i)=='8' || str.charAt(i)=='9')
@ -1037,7 +1060,7 @@ public class Tools {
//Из казахского ASCII в юникод см: http://foxtools.ru/ASCII#1251 //Из казахского ASCII в юникод см: http://foxtools.ru/ASCII#1251
public static String fromKAZASCII(byte[] str) public static String fromKAZASCII(byte[] str)
{ {
StringBuilder rez = new StringBuilder(); StringBuilder rez = new StringBuilder(1024);
for (int i = 0; i < str.length; i++) for (int i = 0; i < str.length; i++)
{ {
switch ((char) str[i]) switch ((char) str[i])