1 28 29 package com.caucho.vfs.i18n; 30 31 import com.caucho.vfs.OutputStreamWithBuffer; 32 33 import java.io.IOException ; 34 35 39 public class JAVAWriter extends EncodingWriter { 40 private static JAVAWriter _writer = new JAVAWriter(); 41 42 45 public JAVAWriter() 46 { 47 } 48 49 52 public String getJavaEncoding() 53 { 54 return "JAVA"; 55 } 56 57 65 public EncodingWriter create(String javaEncoding) 66 { 67 return _writer; 68 } 69 70 75 public void write(OutputStreamWithBuffer os, char ch) 76 throws IOException 77 { 78 if (ch < 0x80) 79 os.write(ch); 80 else { 81 os.write('\\'); 82 os.write('u'); 83 84 int b = (ch >> 12) & 0xf; 85 os.write(b < 10 ? b + '0' : b + 'a' - 10); 86 b = (ch >> 8) & 0xf; 87 os.write(b < 10 ? b + '0' : b + 'a' - 10); 88 b = (ch >> 4) & 0xf; 89 os.write(b < 10 ? b + '0' : b + 'a' - 10); 90 b = ch & 0xf; 91 os.write(b < 10 ? b + '0' : b + 'a' - 10); 92 } 93 } 94 95 102 public void write(OutputStreamWithBuffer os, char []cbuf, int off, int len) 103 throws IOException 104 { 105 for (int i = 0; i < len; i++) { 106 char ch = cbuf[off + i]; 107 108 if (ch < 0x80) 109 os.write(ch); 110 else { 111 os.write('\\'); 112 os.write('u'); 113 114 int b = (ch >> 12) & 0xf; 115 os.write(b < 10 ? b + '0' : b + 'a' - 10); 116 b = (ch >> 8) & 0xf; 117 os.write(b < 10 ? b + '0' : b + 'a' - 10); 118 b = (ch >> 4) & 0xf; 119 os.write(b < 10 ? b + '0' : b + 'a' - 10); 120 b = ch & 0xf; 121 os.write(b < 10 ? b + '0' : b + 'a' - 10); 122 } 123 } 124 } 125 } 126 | Popular Tags |