MCPcopy Create free account
hub / github.com/ReadyTalk/avian / read

Method read

classpath/java/io/InputStreamReader.java:34–87  ·  view source on GitHub ↗
(char[] b, int offset, int length)

Source from the content-addressed store, hash-verified

32 }
33
34 public int read(char[] b, int offset, int length) throws IOException {
35 if (length == 0) {
36 return 0;
37 }
38
39 byte[] buffer = new byte[length + MultibytePadding];
40 int bufferLength = length;
41 int bufferOffset = 0;
42 while (true) {
43 int c = in.read(buffer, bufferOffset, bufferLength);
44
45 if (c <= 0) {
46 if (bufferOffset > 0) {
47 // if we've reached the end of the stream while trying to
48 // read a multibyte character, we still need to return any
49 // competely-decoded characters, plus \ufffd to indicate an
50 // unknown character
51 c = 1;
52 while (bufferOffset > 0) {
53 char[] buffer16 = Utf8.decode16(buffer, 0, bufferOffset);
54
55 if (buffer16 != null) {
56 System.arraycopy(buffer16, 0, b, offset, buffer16.length);
57
58 c = buffer16.length + 1;
59 break;
60 } else {
61 -- bufferOffset;
62 }
63 }
64
65 b[offset + c - 1] = '\ufffd';
66 }
67
68 return c;
69 }
70
71 bufferOffset += c;
72
73 char[] buffer16 = Utf8.decode16(buffer, 0, bufferOffset);
74
75 if (buffer16 != null) {
76 bufferOffset = 0;
77
78 System.arraycopy(buffer16, 0, b, offset, buffer16.length);
79
80 return buffer16.length;
81 } else {
82 // the buffer ended in an incomplete multibyte character, so
83 // we try to read a another byte at a time until it's complete
84 bufferLength = 1;
85 }
86 }
87 }
88
89 public void close() throws IOException {
90 in.close();

Callers 1

testDecodeMethod · 0.95

Calls 3

decode16Method · 0.95
arraycopyMethod · 0.95
readMethod · 0.65

Tested by 1

testDecodeMethod · 0.76