Java Utililty Methods OutputStream Write String

List of utility methods to do OutputStream Write String

Description

The list of methods to do OutputStream Write String are organized into topic(s).

Method

voidwriteString(String s, OutputStream out)
write String
if (s == null) {
    writeInt(0, out);
    return;
int len = s.length();
writeInt(len, out);
for (int i = 0; i < len; i++)
    writChar(s.charAt(i), out);
...
voidwriteString(String str, ObjectOutputStream dos)
DOC zhao Comment method "writeString".
if (str == null) {
    dos.writeInt(-1);
} else {
    byte[] byteArray = str.getBytes(UTF8);
    dos.writeInt(byteArray.length);
    dos.write(byteArray);
voidwriteString(String value, OutputStream os)
Writes a the provided string in a Hessian string representation to the provided output stream using UTF-8 encoding.
The string will be written with the following syntax:
 S b16 b8 string-value 
If the value is null, it will be written as
 N 
if (value == null) {
    os.write('N');
} else {
    int length = value.length();
    int offset = 0;
    while (length > 0x8000) {
        int sublen = 0x8000;
        char tail = value.charAt(offset + sublen - 1);
...
voidwriteStringAsAsciiBytes(String in, OutputStream out)
Writes the given String string as ASCII bytes (0-127) to the given OutputStream output stream .
final int length = in.length();
for (int i = 0; i < length; i++) {
    out.write(in.charAt(i));
voidwriteStringCompressed(ByteArrayOutputStream baos, String s)
write String Compressed
try {
    writeCompressedData(baos, s.getBytes("UTF-8"));
} catch (UnsupportedEncodingException e) {
    throw new RuntimeException("Cannot write string", e);
voidwriteStringKey(final Object key, final ObjectOutputStream oos)
write String Key
oos.writeObject(key);
voidwriteStringKey(final Object key, final ObjectOutputStream oos)
write String Key
oos.writeObject(key);
voidwriteStringMap(ObjectOutputStream out, Map map)
write String Map
out.writeInt(map.size());
for (String v : map.keySet()) {
    out.writeUTF(v);
    out.writeUTF(map.get(v));
voidwriteStringSmart(ByteArrayOutputStream baos, String s, Map knownStrings)
write String Smart
if (s == null) {
    baos.write(STRING_NULL);
    return;
if (knownStrings.get(s) != null) {
    baos.write(STRING_FROM_LIST);
    writeLength(baos, knownStrings.get(s));
    return;
...
voidwriteStringStringMap(Map map, OutputStream os)
write String String Map
if (map != null) {
    writeInt(os, map.size());
    for (Map.Entry<String, String> entry : map.entrySet()) {
        writeString(os, entry.getKey());
        writeString(os, entry.getValue());
} else {
    writeInt(os, 0);
...