Java OutputStream Write serializeString(String str, DataOutputStream dout)

Here you can find the source of serializeString(String str, DataOutputStream dout)

Description

serialize String

License

Open Source License

Declaration

public static void serializeString(String str, DataOutputStream dout) throws IOException 

Method Source Code


//package com.java2s;
import java.io.*;

public class Main {
    private static String tagNull = "Null";
    private static String tagString = "String";

    public static void serializeString(String str, DataOutputStream dout) throws IOException {
        if (str == null)
            serializeNull(dout);//from   w  w w . j a va2  s .  c om
        else {
            serializeHeaderString(tagString, dout);
            dout.writeUTF(str);
            serializeTrailerString(tagString, dout);
        }
    }

    private static void serializeNull(DataOutputStream dout) throws IOException {
        serializeHeaderString(tagNull, dout);
        serializeTrailerString(tagNull, dout);
    }

    private static void serializeHeaderString(String str, DataOutputStream dout) throws IOException {
        dout.writeUTF("[" + str);
    }

    private static void serializeTrailerString(String str, DataOutputStream dout) throws IOException {
        // dout.writeUTF( str + "]" );
        dout.writeUTF("]");
    }
}

Related

  1. serializeNull(DataOutputStream dout)
  2. serializeObject(OutputStream out, Object o)
  3. serializeShortLE(short value, OutputStream outStream)
  4. serializeSpecial(OutputStream os, Serializable obj)
  5. serializeString(OutputStream out, String data)
  6. serializeTo(OutputStream outputStream, Object obj)
  7. serializeToOutputStream(final Serializable ser, final OutputStream os)
  8. serializeUUID(OutputStream out, UUID id)
  9. writeStream(byte[] data, OutputStream os)