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(ByteArrayOutputStream baos, String s)
write String
try {
    writeData(baos, s.getBytes("UTF-8"));
} catch (UnsupportedEncodingException e) {
    throw new RuntimeException("Cannot write string", e);
voidwriteString(final OutputStream output, final String s)
write String
final int length = s.length();
int strIdx = 0;
while (strIdx < length) {
    writeChar(output, s.charAt(strIdx++));
voidwriteString(ObjectOutputStream stream, String string)
Writes a String to an ObjectOutputStream
stream.writeShort((short) string.length());
for (int i = 0; i < string.length(); i++) {
    stream.writeChar(string.charAt(i));
voidwriteString(OutputStream os, String request, String charsetName)
write String
OutputStreamWriter writer = new OutputStreamWriter(os, charsetName);
BufferedWriter bw = new BufferedWriter(writer);
bw.write(request);
bw.write("\r\n");
bw.flush();
voidwriteString(OutputStream os, String s)
write String
byte[] b = s.getBytes("UTF-8");
writeLong(os, b.length);
os.write(b, 0, b.length);
voidwriteString(OutputStream os, String s)
write String
int n = s.length();
for (int i = 0; i < n; i++) {
    char c = s.charAt(i);
    if (c < 0x80) {
        os.write(c);
    } else if (c < 0x800) {
        os.write(0xc0 + (c >> 6));
        os.write(0x80 + (c & 0x3f));
...
voidwriteString(OutputStream os, String s)
write String
byte[] b = s.getBytes("UTF-8");
writeLong(os, b.length);
os.write(b, 0, b.length);
voidwriteString(OutputStream os, String str)
Writes a string to the specified output stream.
for (char c : str.toCharArray()) {
    os.write(c);
os.write('\0');
voidwriteString(OutputStream os, String text)
write String
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(os, "UTF-8"));
writer.write(text);
writer.flush();
writer.close();
voidwriteString(OutputStream out, String s)
write String
byte[] buf = s.getBytes("UTF8");
short len = (short) buf.length;
out.write((len >> 8) & 0xFF);
out.write(len & 0xFF);
out.write(buf);