Java Utililty Methods OutputStream Write

List of utility methods to do OutputStream Write

Description

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

Method

voidserializeInt(int i, DataOutputStream dout)
serialize Int
dout.writeInt(i);
voidserializeInt(OutputStream out, Integer data)
serialize Int
try {
    int v = ((Integer) data).intValue();
    out.write((byte) ((v >>> 24) & 0xFF));
    out.write((byte) ((v >>> 16) & 0xFF));
    out.write((byte) ((v >>> 8) & 0xFF));
    out.write((byte) ((v >>> 0) & 0xFF));
} catch (IOException ex) {
    ex.printStackTrace();
...
voidserializeNull(DataOutputStream dout)
serialize Null
serializeHeaderString(tagNull, dout);
serializeTrailerString(tagNull, dout);
voidserializeObject(OutputStream out, Object o)
serialize Object
ObjectOutputStream oos = new ObjectOutputStream(out);
oos.writeObject(o);
voidserializeShortLE(short value, OutputStream outStream)
Converts a short to a little-endian byte representation and writes it to the given stream.
outStream.write((byte) (value & 0xFF));
outStream.write((byte) ((value >> 8) & 0xFF));
voidserializeSpecial(OutputStream os, Serializable obj)
serialize Special
ObjectOutputStream oos = new ObjectOutputStream(os);
oos.writeObject(obj);
voidserializeString(OutputStream out, String data)
serialize String
byte[] byteData = data.getBytes();
serializeInt(out, byteData.length);
try {
    out.write(byteData);
} catch (IOException e) {
    e.printStackTrace();
voidserializeString(String str, DataOutputStream dout)
serialize String
if (str == null)
    serializeNull(dout);
else {
    serializeHeaderString(tagString, dout);
    dout.writeUTF(str);
    serializeTrailerString(tagString, dout);
voidserializeTo(OutputStream outputStream, Object obj)
serialize To
String json = GSON.toJson(obj);
try {
    outputStream.write(json.getBytes());
    outputStream.flush();
} finally {
    if (outputStream != null) {
        outputStream.close();
voidserializeToOutputStream(final Serializable ser, final OutputStream os)
Serialize to output stream.
ObjectOutputStream oos = null;
try {
    oos = new ObjectOutputStream(os);
    oos.writeObject(ser);
    oos.flush();
} finally {
    oos.close();