MCPcopy Create free account
hub / github.com/EdwardRaff/JSAT / writeString

Method writeString

JSAT/src/jsat/io/JSATData.java:712–733  ·  view source on GitHub ↗
(String s, DataOutputStream out)

Source from the content-addressed store, hash-verified

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 {

Callers 1

writeHeaderMethod · 0.95

Calls 2

lengthMethod · 0.45
writeMethod · 0.45

Tested by

no test coverage detected