/**
* Interprets in according to encIn, and converts it to encOut,
* writing to out. Allocates buffer for the buffer size.
*
* @param encIn The input encoding.
* @param encOut The output encoding.
* @param in The data to convert.
* @param out Where to send the converted data.
* @param buffer The size of the buffer or 0 for the default.
*
* @throws IOException
*/
public void run(String encIn, String encOut, InputStream in, OutputStream out, int buffer) throws IOException {
Reader r = null;
Writer w = null;
int len;
char[] b;
try {
if (buffer > 0) {
r = new BufferedReader(new InputStreamReader(in, encIn), buffer);
w = new BufferedWriter(new OutputStreamWriter(out, encOut), buffer);
} else {
r = new BufferedReader(new InputStreamReader(in, encIn));
w = new BufferedWriter(new OutputStreamWriter(out, encOut));
buffer = DEFAULT_BUFFER_SIZE;
}
b = new char[buffer];
while ((len = r.read(b, 0, buffer)) != -1) {
w.write(b, 0, len);
}
} finally {
try {
if (r != null) r.close();
} finally {
if (w != null) w.close();
}
}
}
Btw, none of this has anything to do with Postgres. :-)
Paul
On Wed, Dec 12, 2012 at 10:19 AM, Emi Lu <emilu@xxxxxxxxxxxxxxxxx> wrote:
JAVA codes work for most of characters, but not "-È". Someone knows why the following codes cannot load "-È" to mysql@latin1?
Is there a simple way to load UTF8 data in psql to mysql(with latin1
encoding) through JDBC?
Thanks a lot!
--
public static String utf8_to_latin1(String str)
throws Exception
{
try
{
String stringToConvert = str;
byte[] convertStringToByte = stringToConvert.getBytes("UTF-8");
return new String(convertStringToByte, "ISO-8859-1");
}catch(Exception e)
{
log.error("utf8_to_latin1 Error: " + e.getMessage());
log.error(e);
throw e;
}
}
--
Sent via pgsql-general mailing list (pgsql-general@xxxxxxxxxxxxxx)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general
--
_________________________________
Pulchritudo splendor veritatis.