use charset object instead of string where possible

This commit is contained in:
honfika@gmail.com
2016-04-06 21:19:22 +02:00
parent 04cf130a07
commit 7b0f034cbc
4 changed files with 22 additions and 37 deletions

View File

@@ -7,7 +7,6 @@ import com.jpexs.decompiler.flash.abc.avm2.instructions.InstructionDefinition;
import com.jpexs.helpers.Cache;
import com.jpexs.helpers.Helper;
import com.jpexs.helpers.utf8.Utf8Helper;
import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.text.DateFormat;
@@ -17,7 +16,6 @@ import java.util.Date;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import java.util.Properties;
import java.util.ResourceBundle;
import java.util.Set;
import java.util.TimeZone;
@@ -33,9 +31,11 @@ import java.util.logging.Logger;
public class As3PCodeDocs {
private static ResourceBundle prop;
private static Map<AVM2InstructionFlag, String> flagDescriptions = new HashMap<>();
private static Cache<String, String> docsCache = Cache.getInstance(false, true, "as3DocsCache");
private static Map<String, InstructionDefinition> nameToDef = new HashMap<>();
static final String NEWLINE = "\r\n";
@@ -273,16 +273,13 @@ public class As3PCodeDocs {
return cached;
}
String style = "";
try {
InputStream is = As3PCodeDocs.class.getResourceAsStream("/com/jpexs/decompiler/flash/docs/docs.css");
if (is == null) {
Logger.getLogger(As3PCodeDocs.class.getName()).log(Level.SEVERE, "docs.css needed for documentation not found");
} else {
style = new String(Helper.readStream(is), "UTF-8");
}
} catch (UnsupportedEncodingException ex) {
//ignore
InputStream is = As3PCodeDocs.class.getResourceAsStream("/com/jpexs/decompiler/flash/docs/docs.css");
if (is == null) {
Logger.getLogger(As3PCodeDocs.class.getName()).log(Level.SEVERE, "docs.css needed for documentation not found");
} else {
style = new String(Helper.readStream(is), Utf8Helper.charset);
}
docsCache.put("__style", style);
return style;
}
@@ -293,16 +290,13 @@ public class As3PCodeDocs {
return cached;
}
String js = "";
try {
InputStream is = As3PCodeDocs.class.getResourceAsStream("/com/jpexs/decompiler/flash/docs/docs.js");
if (is == null) {
Logger.getLogger(As3PCodeDocs.class.getName()).log(Level.SEVERE, "docs.js needed for documentation not found");
} else {
js = new String(Helper.readStream(is), "UTF-8");
}
} catch (UnsupportedEncodingException ex) {
//ignore
InputStream is = As3PCodeDocs.class.getResourceAsStream("/com/jpexs/decompiler/flash/docs/docs.js");
if (is == null) {
Logger.getLogger(As3PCodeDocs.class.getName()).log(Level.SEVERE, "docs.js needed for documentation not found");
} else {
js = new String(Helper.readStream(is), Utf8Helper.charset);
}
docsCache.put("__js", js);
return js;
}

View File

@@ -23,8 +23,6 @@ import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
*
@@ -116,7 +114,7 @@ public class EcmaScript {
//TODO: logic similar to 8.12.8
return o.call("toString", new ArrayList<>());
case "Number":
//TODO: logic similar to 8.12.8
//TODO: logic similar to 8.12.8
return o.call("valueOf", new ArrayList<>());
default:
return o.toPrimitive();

View File

@@ -29,8 +29,8 @@ import com.jpexs.decompiler.flash.types.annotations.SWFType;
import com.jpexs.decompiler.flash.types.annotations.SWFVersion;
import com.jpexs.helpers.ByteArrayRange;
import com.jpexs.helpers.Helper;
import com.jpexs.helpers.utf8.Utf8Helper;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.logging.Level;
@@ -109,9 +109,9 @@ public class EnableTelemetryTag extends Tag implements PasswordTag {
try {
md = MessageDigest.getInstance("SHA-256");
md.update(password.getBytes("UTF-8"));
md.update(password.getBytes(Utf8Helper.charset));
return Helper.byteArrayToHex(md.digest());
} catch (NoSuchAlgorithmException | UnsupportedEncodingException ex) {
} catch (NoSuchAlgorithmException ex) {
}
return null;

View File

@@ -16,7 +16,7 @@
*/
package com.jpexs.helpers;
import java.io.UnsupportedEncodingException;
import com.jpexs.helpers.utf8.Utf8Helper;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Random;
@@ -93,16 +93,9 @@ public class MD5Crypt {
salt = salt.substring(0, 8);
}
byte[] passwordBytes = new byte[0];
byte[] constBytes = new byte[0];
byte[] saltBytes = new byte[0];
try {
passwordBytes = password.getBytes("UTF-8");
saltBytes = salt.getBytes("UTF-8");
constBytes = magic.getBytes("UTF-8");
} catch (UnsupportedEncodingException ex) {
//ignore
}
byte[] passwordBytes = password.getBytes(Utf8Helper.charset);
byte[] saltBytes = salt.getBytes(Utf8Helper.charset);
byte[] constBytes = magic.getBytes(Utf8Helper.charset);
MessageDigest b;
try {