Here you can find the source of readUTFByteArrayFromDataInput(final DataInput in)
Parameter | Description |
---|---|
in | the DataInput from which the string will be read |
Parameter | Description |
---|---|
IOException | an IO problem. |
public static String readUTFByteArrayFromDataInput(final DataInput in) throws IOException
//package com.java2s; // Licensed under the terms of the New BSD License. Please see associated LICENSE file for terms. import java.io.DataInput; import java.io.IOException; import java.nio.charset.StandardCharsets; public class Main { /**// w w w . jav a2 s . c om * Reads a string from the given DataInput. This method assumes that the string is stored as an integer, indicating * number of bytes of the string, followed by a byte array which is the string itself, encoded in UTF-8. The method * {@link #writeStringAsUTFByteArrayToDataOutput(DataOutput, String)} writes a string into a DataOutput in this way. * * @param in the DataInput from which the string will be read * @return The string * @throws IOException an IO problem. */ public static String readUTFByteArrayFromDataInput(final DataInput in) throws IOException { int length = in.readInt(); byte[] byteArray = new byte[length]; in.readFully(byteArray); return new String(byteArray, StandardCharsets.UTF_8); } }