From 08f3ab61ca0003072cd592383c4325a824e24a98 Mon Sep 17 00:00:00 2001 From: "Brian P. Hinz" Date: Sun, 1 Mar 2015 14:40:03 -0500 Subject: [PATCH] Don't violate RFB spec by sending UTF-8 Java viewer was violating the RFB specification by sending UTF-8 encoded clipboard text rather than ISO-8859-1. --- java/com/tigervnc/rfb/CMsgWriter.java | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/java/com/tigervnc/rfb/CMsgWriter.java b/java/com/tigervnc/rfb/CMsgWriter.java index 3b226b16..0d3dccf9 100644 --- a/java/com/tigervnc/rfb/CMsgWriter.java +++ b/java/com/tigervnc/rfb/CMsgWriter.java @@ -20,6 +20,8 @@ package com.tigervnc.rfb; +import java.nio.ByteBuffer; +import java.nio.charset.Charset; import com.tigervnc.rdr.*; abstract public class CMsgWriter { @@ -155,12 +157,9 @@ abstract public class CMsgWriter { startMsg(MsgTypes.msgTypeClientCutText); os.pad(3); os.writeU32(len); - try { - byte[] utf8str = str.getBytes("UTF8"); - os.writeBytes(utf8str, 0, len); - } catch(java.io.UnsupportedEncodingException e) { - e.printStackTrace(); - } + Charset latin1 = Charset.forName("ISO-8859-1"); + ByteBuffer bytes = latin1.encode(str); + os.writeBytes(bytes.array(), 0, len); endMsg(); } -- 2.39.5