| 733 | } |
| 734 | |
| 735 | private static String readString(DataInputStream in) throws IOException |
| 736 | { |
| 737 | StringBuilder builder = new StringBuilder(); |
| 738 | byte encoding = in.readByte(); |
| 739 | int bytesToRead = in.readInt(); |
| 740 | |
| 741 | switch(encoding) |
| 742 | { |
| 743 | case STRING_ENCODING_ASCII: |
| 744 | for (int i = 0; i < bytesToRead; i++) |
| 745 | builder.append(Character.toChars(in.readByte())); |
| 746 | return builder.toString(); |
| 747 | case STRING_ENCODING_UTF_16: |
| 748 | byte[] bytes = new byte[bytesToRead]; |
| 749 | in.readFully(bytes); |
| 750 | return new String(bytes, "UTF-16"); |
| 751 | default: |
| 752 | throw new RuntimeException("Unkown string encoding value " + encoding); |
| 753 | } |
| 754 | |
| 755 | } |
| 756 | } |