Here you can find the source of writeStringAsUTFByteArrayToDataOutput(final DataOutput out, final String str)
Parameter | Description |
---|---|
out | The DataOutput into which the string will be written. |
str | The string to write. |
Parameter | Description |
---|---|
IOException | an IO problem. |
public static void writeStringAsUTFByteArrayToDataOutput(final DataOutput out, final String str) throws IOException
//package com.java2s; // Licensed under the terms of the New BSD License. Please see associated LICENSE file for terms. import java.io.DataOutput; import java.io.IOException; import java.nio.charset.StandardCharsets; public class Main { /**//from ww w .j a va 2 s . c o m * Writes a string into a DataOutput. This method writes an integer, which indicates the size of a byte-array that * represents the string, followed by that byte array. The byte-array is the string, encoded in UTF-8. The method * {@link #readUTFByteArrayFromDataInput(DataInput)} can be used to read such a string from a DataInput. * * @param out The DataOutput into which the string will be written. * @param str The string to write. * @throws IOException an IO problem. */ public static void writeStringAsUTFByteArrayToDataOutput(final DataOutput out, final String str) throws IOException { byte[] byteArray = str.getBytes(StandardCharsets.UTF_8); out.writeInt(byteArray.length); out.write(byteArray); } }