()
| 74 | // readString() reads a string - a U32 length followed by the data. |
| 75 | |
| 76 | public final String readString() { |
| 77 | int len = readU32(); |
| 78 | if (len > maxStringLength) |
| 79 | throw new Exception("InStream max string length exceeded"); |
| 80 | |
| 81 | ByteBuffer str = ByteBuffer.allocate(len); |
| 82 | readBytes(str, len); |
| 83 | String utf8string = new String(); |
| 84 | try { |
| 85 | utf8string = new String(str.array(),"UTF8"); |
| 86 | } catch(java.io.UnsupportedEncodingException e) { |
| 87 | e.printStackTrace(); |
| 88 | } |
| 89 | return utf8string; |
| 90 | } |
| 91 | |
| 92 | // maxStringLength protects against allocating a huge buffer. Set it |
| 93 | // higher if you need longer strings. |
no test coverage detected