Here you can find the source of writeString(DataOutputStream os, String str)
Parameter | Description |
---|---|
os | a parameter |
str | a parameter |
Parameter | Description |
---|---|
IOException | an exception |
public static void writeString(DataOutputStream os, String str) throws IOException
//package com.java2s; /**//from w w w . j a v a 2s.c o m * JHeroes CRPG Engine and Game * Copyright (C) 2014 Tuomo Untinen * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program 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 * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, see http://www.gnu.org/licenses/ * * * Utilities for handling streams */ import java.io.DataOutputStream; import java.io.IOException; public class Main { /** * Writes string into DataOutputStream. First 4 octets tell string length * then each characger is written with 2 octets * @param os * @param str * @throws IOException */ public static void writeString(DataOutputStream os, String str) throws IOException { if (str != null) { os.writeInt(str.length()); os.writeChars(str); } else { os.writeInt(0); } } }