Here you can find the source of readUtf8String(DataInputStream in)
Parameter | Description |
---|---|
buf | The buffer. |
public static String readUtf8String(DataInputStream in) throws IOException
//package com.java2s; //License from project: Open Source License import java.io.DataInputStream; import java.io.IOException; import java.nio.charset.Charset; public class Main { /**/* w ww. j av a 2s . co m*/ * The UTF-8 character set. */ private static final Charset CHARSET_UTF8 = Charset.forName("UTF-8"); /** * Reads a UTF-8 encoded string from the buffer. * @param buf The buffer. * @return The string. */ public static String readUtf8String(DataInputStream in) throws IOException { int len = in.readUnsignedShort(); byte[] bytes = new byte[len]; in.readFully(bytes); return new String(bytes, CHARSET_UTF8); } }