Java OutputStream Write String writeString(ObjectOutputStream stream, String string)

Here you can find the source of writeString(ObjectOutputStream stream, String string)

Description

Writes a String to an ObjectOutputStream

License

Open Source License

Parameter

Parameter Description
stream Stream to write to
string String to write

Exception

Parameter Description
IOException If there was an error writing the String

Declaration

public static void writeString(ObjectOutputStream stream, String string) throws IOException 

Method Source Code

//package com.java2s;
/*/*from   w ww.ja va  2 s .  co  m*/
 * This file is part of SpaceModule (http://spacebukkit.xereo.net/).
 *
 * SpaceModule is free software: you can redistribute it and/or modify it under the terms of the
 * Attribution-NonCommercial-ShareAlike Unported (CC BY-NC-SA) license as published by the Creative
 * Common organization, either version 3.0 of the license, or (at your option) any later version.
 *
 * SpaceBukkit is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
 * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * Attribution-NonCommercial-ShareAlike Unported (CC BY-NC-SA) license for more details.
 *
 * You should have received a copy of the Attribution-NonCommercial-ShareAlike Unported (CC BY-NC-SA)
 * license along with this program. If not, see <http://creativecommons.org/licenses/by-nc-sa/3.0/>.
 */

import java.io.IOException;

import java.io.ObjectOutputStream;

public class Main {
    /**
     * Writes a String to an ObjectOutputStream
     * @param stream Stream to write to
     * @param string String to write
     * @throws IOException If there was an error writing the String
     */
    public static void writeString(ObjectOutputStream stream, String string) throws IOException {
        stream.writeShort((short) string.length());
        for (int i = 0; i < string.length(); i++) {
            stream.writeChar(string.charAt(i));
        }
    }
}

Related

  1. writeString(ByteArrayOutputStream baos, String s)
  2. writeString(final OutputStream output, final String s)
  3. writeString(OutputStream os, String request, String charsetName)
  4. writeString(OutputStream os, String s)
  5. writeString(OutputStream os, String s)
  6. writeString(OutputStream os, String s)