Here you can find the source of writeString(DataOutputStream out, String str)
Parameter | Description |
---|---|
buf | The buffer. |
str | The string. |
Parameter | Description |
---|---|
IllegalArgumentException | if the string is too long<em>after</em> it is encoded. |
public static void writeString(DataOutputStream out, String str) throws IOException
//package com.java2s; //License from project: Open Source License import java.io.DataOutputStream; import java.io.IOException; public class Main { /**/*from w w w.j a v a 2 s . c o m*/ * Writes a string to the buffer. * @param buf The buffer. * @param str The string. * @throws IllegalArgumentException if the string is too long * <em>after</em> it is encoded. */ public static void writeString(DataOutputStream out, String str) throws IOException { int len = str.length(); if (len >= 65536) { throw new IllegalArgumentException("String too long."); } out.writeShort(len); for (int i = 0; i < len; ++i) { out.writeChar(str.charAt(i)); } } }