Java Utililty Methods DataOutputStream Write String

List of utility methods to do DataOutputStream Write String

Description

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

Method

voidwriteString(DataOutputStream output, String s)
write String
try {
    output.writeShort(s.length());
    output.writeChars(s);
} catch (IOException e) {
    e.printStackTrace();
voidwriteString(DataOutputStream outputStream, String string)
write String
outputStream.writeInt(string.getBytes().length);
outputStream.write(string.getBytes());
voidwriteString(final DataOutputStream out, final String str)
Writes a string to the buffer.
int len = str.length();
if (len > MAXLEN) {
    throw new IllegalArgumentException("String too long.");
out.writeShort(len);
for (int i = 0; i < len; ++i) {
    out.writeChar(str.charAt(i));
voidwriteString(final DataOutputStream out, final String value)
write String
out.writeUTF(value == null ? STRING_VALUE_NULL : value);
voidwriteString(String arg, DataOutputStream data)
write String
byte[] abyte = arg.getBytes();
data.writeInt(abyte.length);
for (byte curr : abyte)
    data.writeByte(curr);
voidwriteString(String s, DataOutputStream out)
write String
out.writeInt(s.length());
for (char c : s.toCharArray()) {
    out.writeChar(c);
voidwriteString(String s, DataOutputStream out)
write String
if (s != null) {
    out.write(1);
    out.writeUTF(s);
} else {
    out.write(0);
voidwriteString(String s, DataOutputStream writer)
write String
if (s != null) {
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    DataOutputStream dos = new DataOutputStream(bos);
    byte[] data = s.getBytes("UTF-8");
    dos.writeInt(data.length);
    dos.write(data);
    dos.flush();
    byte[] bs = bos.toByteArray();
...
voidwriteString(String str, DataOutputStream dos)
write String
if (str == null) {
    dos.writeInt(-1);
} else {
    byte[] byteArray = str.getBytes(UTF8);
    dos.writeInt(byteArray.length);
    dos.write(byteArray);
voidwriteString(String str, DataOutputStream os)
write String
if (str == null) {
    os.writeInt(-1);
} else {
    os.writeInt(str.length());
    os.writeChars(str);