Skip to content

Commit

Permalink
Tuning character encoding of Waiana/Maiana.
Browse files Browse the repository at this point in the history
  • Loading branch information
akivela committed Aug 18, 2014
1 parent 25289a6 commit bfbc5c9
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1185,21 +1185,6 @@ public void run() {

// -------------------------------------------------------------------------

/*
public void setSelectedWebApp(ModulesWebApp webapp) {
if(webapp == null) {
selectedWebApp = null;
urlTextField.setBackground(Color.WHITE);
}
else {
selectedWebApp = webapp;
urlTextField.setBackground(new Color(243,243,243));
}
}
public ModulesWebApp getSelectedWebApp() {
return selectedWebApp;
}
*/


}
11 changes: 6 additions & 5 deletions src/org/wandora/application/modulesserver/WaianaService.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
Expand Down Expand Up @@ -453,7 +454,7 @@ public void setTopicMapsPath(String l) {

public void loadData() {
try {
String inStr = readFile(basePath+"/"+storageFilename, "UTF-8");
String inStr = readFile(basePath+"/"+storageFilename);
if(inStr != null) {
JSONArray dataArray = new JSONArray(inStr);
for(int i=0; i<dataArray.length(); i++) {
Expand Down Expand Up @@ -570,7 +571,7 @@ public JSONObject getTopicMap(User user, String shortName) {
try {
reply.put("code", 0);
try {
String topicMapData = readFile(basePath+"/"+topicMapsPath+"/"+shortName+".xtm", "UTF-8");
String topicMapData = readFile(basePath+"/"+topicMapsPath+"/"+shortName+".xtm");

// System.out.println(topicMapData);

Expand Down Expand Up @@ -833,7 +834,7 @@ protected static void writeFile(String fname, String data) throws IOException {
System.out.println("Deleting previously existing file '" + fname + "' before save file operation!");
}

BufferedWriter writer = new BufferedWriter(new FileWriter(fname));
PrintWriter writer=new PrintWriter(new OutputStreamWriter(new FileOutputStream(fname), "UTF-8"));
writer.write(data);
writer.flush();
writer.close();
Expand All @@ -842,9 +843,9 @@ protected static void writeFile(String fname, String data) throws IOException {



static String readFile(String path, String encoding) throws IOException {
static String readFile(String path) throws IOException {
byte[] encoded = Files.readAllBytes(Paths.get(path));
return new String(encoded, encoding);
return new String(encoded, "UTF-8");
}


Expand Down
17 changes: 10 additions & 7 deletions src/org/wandora/application/tools/maiana/MaianaUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
*
* @author akivela
*/

public class MaianaUtils {

private static String apiKey = "";
Expand Down Expand Up @@ -213,7 +214,7 @@ public static String makeJSON(String string) {
return "";
}

char c = 0;
int c = 0;
int i;
int len = string.length();
StringBuilder sb = new StringBuilder(len + 4);
Expand All @@ -225,13 +226,13 @@ public static String makeJSON(String string) {
case '\\':
case '"':
sb.append('\\');
sb.append(c);
sb.append((char) c);
break;
case '/':
// if (b == '<') {
sb.append('\\');
// }
sb.append(c);
sb.append((char) c);
break;
case '\b':
sb.append("\\b");
Expand All @@ -252,8 +253,9 @@ public static String makeJSON(String string) {
if (c < ' ') {
t = "000" + Integer.toHexString(c);
sb.append("\\u" + t.substring(t.length() - 4));
} else {
sb.append(c);
}
else {
sb.append((char) c);
}
}
}
Expand Down Expand Up @@ -298,15 +300,16 @@ public static String doUrl(URL url, String data, String ctype) throws IOExceptio
con.setDoInput(true);
con.setUseCaches(false);


if(ctype != null) {
con.setRequestProperty("Content-type", ctype);
}

if(data != null && data.length() > 0) {
con.setRequestProperty("Content-length", data.length() + "");
// con.setRequestProperty("Accept-Charset", "UTF-8");
con.setDoOutput(true);
PrintWriter out = new PrintWriter(new OutputStreamWriter(con.getOutputStream(), StandardCharsets.UTF_8));
//PrintWriter out = new PrintWriter(new OutputStreamWriter(con.getOutputStream(), StandardCharsets.UTF_8));
PrintWriter out = new PrintWriter(new OutputStreamWriter(con.getOutputStream()));
out.print(data);
out.flush();
out.close();
Expand Down

0 comments on commit bfbc5c9

Please sign in to comment.