Java DataOutputStream Write String writeStringOrNull(DataOutputStream out, String string)

Here you can find the source of writeStringOrNull(DataOutputStream out, String string)

Description

write String Or Null

License

Open Source License

Declaration

public static void writeStringOrNull(DataOutputStream out, String string) throws IOException 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2005, 2010 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:/* www  . j  a va 2 s .c o  m*/
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/

import java.io.*;

public class Main {
    /** The NULL tag used in bundle storage */
    public static final byte NULL = 0;
    /** The OBJECT tag used in bundle storage */
    public static final byte OBJECT = 1;

    public static void writeStringOrNull(DataOutputStream out, String string) throws IOException {
        if (string == null)
            out.writeByte(NULL);
        else {
            out.writeByte(OBJECT);
            out.writeUTF(string);
        }
    }
}

Related

  1. writeString(String str, DataOutputStream os)
  2. writeString(String stringToWrite, DataOutputStream data)
  3. writeStringAsBytes(DataOutputStream out, byte[] byteArray)
  4. writeStringAsBytes(DataOutputStream out, byte[] byteArray)
  5. writeStringList(List list, DataOutputStream os)