Hi,
really stuck here-
below is an excerpt from the orginal code for a servlet that read a UTF-8 file that had been uploaded.
The line of code: "while ((ch = in.read()) > -1) {"
got the utf-8 char's "number". the program has a mapping file to convert it. (This is a char for char mapping used in a translation program.)
I tried changing it to accept a UTF-8 String from a textarea instead of reading from a utf-8 file, but it seems it can not be read the same way. A system.out.println of the string shows that utf-8 chars are stored as '& # 1492;' (spaces added so you don't get an international char) in the string while something like a comma is stored as a comma ','. I have tried putting the string in a string reader and then the string reader in a buffered reader but it returns one char at a time ie insted of returning the number 1492 it returns, &, #, 1, 4, etc
Is there any way to read or convert the string so it returns one integer for each letter sumbited?
Original code:
code for using a String:
I have looked into a class called dataflavor, if it can help me I don't know how.
really stuck here-
below is an excerpt from the orginal code for a servlet that read a UTF-8 file that had been uploaded.
The line of code: "while ((ch = in.read()) > -1) {"
got the utf-8 char's "number". the program has a mapping file to convert it. (This is a char for char mapping used in a translation program.)
I tried changing it to accept a UTF-8 String from a textarea instead of reading from a utf-8 file, but it seems it can not be read the same way. A system.out.println of the string shows that utf-8 chars are stored as '& # 1492;' (spaces added so you don't get an international char) in the string while something like a comma is stored as a comma ','. I have tried putting the string in a string reader and then the string reader in a buffered reader but it returns one char at a time ie insted of returning the number 1492 it returns, &, #, 1, 4, etc
Is there any way to read or convert the string so it returns one integer for each letter sumbited?
Original code:
Code:
int ch; //unicode char read from file - INTEGER
int location; //Location in Mapping array to find Ascii char
String OutputFile= new String();
OutputFile="";
StringBuffer TempOutputFile = new StringBuffer();
Mapping key;
try{//try 1
FileInputStream fis = new FileInputStream(userInputFile);
InputStreamReader isr = new InputStreamReader(fis,"UTF8");
BufferedReader in = new BufferedReader(isr);
while ((ch = in.read()) > -1) {
key = new Mapping();
key.numChar = ch;
location = Arrays.binarySearch(MapArray, key , new Comparator() {
int firstNum, secondNum;
public int compare( Object o1, Object o2) {
firstNum=Integer.parseInt( o1.toString());
secondNum=Integer.parseInt(o2.toString());
if(firstNum<secondNum)
return -1;
if(firstNum>secondNum)
return +1;
return 0;
}
});
if (location>=0)
TempOutputFile.append(MapArray [location].ReplacementChar);
}//while
code for using a String:
Code:
StringReader isr = new StringReader(InputFile);
BufferedReader in = new BufferedReader(isr);
I have looked into a class called dataflavor, if it can help me I don't know how.