1 28 29 package com.caucho.vfs.i18n; 30 31 import java.io.IOException ; 32 import java.io.InputStream ; 33 import java.io.Reader ; 34 35 38 public class UTF16_REVReader extends EncodingReader { 39 private InputStream is; 40 41 44 public UTF16_REVReader() 45 { 46 } 47 48 51 private UTF16_REVReader(InputStream is) 52 { 53 this.is = is; 54 } 55 56 64 public Reader create(InputStream is, String javaEncoding) 65 { 66 return new UTF16_REVReader(is); 67 } 68 69 74 public int read() 75 throws IOException 76 { 77 int ch1 = is.read(); 78 int ch2 = is.read(); 79 80 if (ch2 < 0) 81 return -1; 82 83 return (ch2 << 8) + ch1; 84 } 85 86 95 public int read(char []cbuf, int off, int len) 96 throws IOException 97 { 98 int i = 0; 99 100 for (i = 0; i < len; i++) { 101 int ch1 = is.read(); 102 int ch2 = is.read(); 103 104 if (ch2 < 0) 105 return i == 0 ? -1 : i; 106 107 cbuf[off + i] = (char) ((ch2 << 8) + ch1); 108 } 109 110 return i; 111 } 112 } 113 | Popular Tags |