Author: jflesch
Date: 2006-07-21 20:40:08 +0000 (Fri, 21 Jul 2006)
New Revision: 9703
Modified:
trunk/apps/Thaw/src/thaw/core/Logger.java
trunk/apps/Thaw/src/thaw/fcp/FCPBufferedStream.java
trunk/apps/Thaw/src/thaw/fcp/FCPConnection.java
trunk/apps/Thaw/src/thaw/plugins/Console.java
Log:
UTf-8 on the socket is now correctly supported
Modified: trunk/apps/Thaw/src/thaw/core/Logger.java
===================================================================
--- trunk/apps/Thaw/src/thaw/core/Logger.java 2006-07-21 19:09:14 UTC (rev
9702)
+++ trunk/apps/Thaw/src/thaw/core/Logger.java 2006-07-21 20:40:08 UTC (rev
9703)
@@ -94,10 +94,10 @@
* As it. Similar to verbose()
*/
public static void asIt(Object o, String msg) {
- if(LOG_LEVEL >= 5) {
+ //if(LOG_LEVEL >= 5) {
System.out.println(msg);
notifyLogListeners(msg);
- }
+ //}
}
Modified: trunk/apps/Thaw/src/thaw/fcp/FCPBufferedStream.java
===================================================================
--- trunk/apps/Thaw/src/thaw/fcp/FCPBufferedStream.java 2006-07-21 19:09:14 UTC
(rev 9702)
+++ trunk/apps/Thaw/src/thaw/fcp/FCPBufferedStream.java 2006-07-21 20:40:08 UTC
(rev 9703)
@@ -74,7 +74,12 @@
* @see write(byte[])
*/
public boolean write(String data) {
- return write(data.getBytes());
+ try {
+ return write(data.getBytes("UTF-8"));
+ } catch(java.io.UnsupportedEncodingException e) {
+ Logger.error(this, "UNSUPPORTED ENCODING EXCEPTION :
UTF-8");
+ return write(data.getBytes());
+ }
}
/**
Modified: trunk/apps/Thaw/src/thaw/fcp/FCPConnection.java
===================================================================
--- trunk/apps/Thaw/src/thaw/fcp/FCPConnection.java 2006-07-21 19:09:14 UTC
(rev 9702)
+++ trunk/apps/Thaw/src/thaw/fcp/FCPConnection.java 2006-07-21 20:40:08 UTC
(rev 9703)
@@ -5,7 +5,6 @@
import java.io.OutputStream;
/* import java.io.BufferedReader; */
import java.io.BufferedInputStream;
-import java.io.InputStreamReader;
import java.util.Observable;
/* Should be the only real dep of the FCP package */
@@ -26,6 +25,7 @@
* all fcp input / output.
*/
private final static boolean DEBUG_MODE = true;
+ private final static int MAX_RECV = 1024;
private FCPBufferedStream bufferedOut = null;
private int maxUploadSpeed = 0;
@@ -283,7 +283,12 @@
if(out != null && socket != null && socket.isConnected()) {
- bufferedOut.write(toWrite.getBytes());
+ try {
+ bufferedOut.write(toWrite.getBytes("UTF-8"));
+ } catch(java.io.UnsupportedEncodingException e) {
+ Logger.error(this, "UNSUPPORTED ENCODING
EXCEPTION : UTF-8");
+ bufferedOut.write(toWrite.getBytes());
+ }
} else {
Logger.warning(this, "Cannot write if disconnected
!\n");
return false;
@@ -333,7 +338,9 @@
* @return null if disconnected or error
*/
public String readLine() {
+
+
/* SECURITY */
if(rawBytesWaiting > 0) {
Logger.error(this, "RAW BYTES STILL WAITING ON SOCKET.
THIS IS ABNORMAL.");
@@ -359,11 +366,17 @@
if(in != null && reader != null && socket != null &&
socket.isConnected()) {
try {
+ byte[] recvBytes = new byte[MAX_RECV];
+
+ for(int i = 0; i < recvBytes.length ; i++)
+ recvBytes[i] = 0;
+
result = "";
int c = 0;
+ int i = 0; /* position in recvBytes */
- while(c != '\n') {
+ while(c != '\n' && i < recvBytes.length) {
c = reader.read();
if(c == -1) {
@@ -378,10 +391,14 @@
if(c == '\n')
break;
- result = result + new String(new byte[]
{ (byte)c });
-
+ //result = result + new String(new
byte[] { (byte)c });
+
+ recvBytes[i] = (byte)c;
+ i++;
}
+ result = new String(recvBytes, 0, i, "UTF-8");
+
if(DEBUG_MODE) {
if(result.matches("[\\-\\
\\?.a-zA-Z0-9\\,~%@/_=\\[\\]\\(\\)]*"))
Logger.asIt(this, "Thaw <<<
Node : "+result);
Modified: trunk/apps/Thaw/src/thaw/plugins/Console.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/Console.java 2006-07-21 19:09:14 UTC
(rev 9702)
+++ trunk/apps/Thaw/src/thaw/plugins/Console.java 2006-07-21 20:40:08 UTC
(rev 9703)
@@ -127,7 +127,7 @@
}
try {
- output.write(logArea.getText().getBytes());
+ output.write(logArea.getText().getBytes("UTF-8"));
} catch(java.io.IOException e) {
Logger.error(this, "IOException while writing logs ...
out of space ?");
return;