(String s, DataOutputStream out)
| 710 | } |
| 711 | |
| 712 | private static void writeString(String s, DataOutputStream out) throws IOException |
| 713 | { |
| 714 | boolean isAscii = true; |
| 715 | for(int i = 0; i < s.length() && isAscii; i++) |
| 716 | if(s.charAt(i) >= 256 || s.charAt(i) <= 0) |
| 717 | isAscii = false; |
| 718 | |
| 719 | if(isAscii) |
| 720 | { |
| 721 | out.writeByte(STRING_ENCODING_ASCII); |
| 722 | out.writeInt(s.length());//number of bytes of the string |
| 723 | for(int i = 0; i < s.length(); i++) |
| 724 | out.writeByte(s.charAt(i)); |
| 725 | } |
| 726 | else//write as UTF-8 |
| 727 | { |
| 728 | byte[] bytes = s.getBytes("UTF-16"); |
| 729 | out.writeByte(STRING_ENCODING_UTF_16); |
| 730 | out.writeInt(bytes.length);//number of bytes of the string |
| 731 | out.write(bytes); |
| 732 | } |
| 733 | } |
| 734 | |
| 735 | private static String readString(DataInputStream in) throws IOException |
| 736 | { |
no test coverage detected