Here you can find the source of readString(ByteArrayInputStream bin)
public static String readString(ByteArrayInputStream bin) throws IOException
//package com.java2s; //License from project: Open Source License import java.io.ByteArrayInputStream; import java.io.IOException; import java.nio.ByteBuffer; public class Main { private final static String ENCODING = "UTF-8"; public static String readString(ByteArrayInputStream bin) throws IOException { int length = readInt(bin); if (length == -1) return null; if (length == 0) return ""; byte[] buffer = new byte[length]; bin.read(buffer);// w w w.jav a2s. c o m return new String(buffer, ENCODING); } /** * Reads the next 4 bytes from the stream as integer. */ public static int readInt(ByteArrayInputStream bin) throws IOException { byte[] buffer = new byte[4]; bin.read(buffer); return ByteBuffer.wrap(buffer).getInt(); } }