Here you can find the source of readBytesIntoSocket(Socket socket)
public static byte[] readBytesIntoSocket(Socket socket) throws IOException, InterruptedException
//package com.java2s; //License from project: Apache License import java.io.ByteArrayOutputStream; import java.io.DataInputStream; import java.io.IOException; import java.net.Socket; public class Main { private static final int DEFAULT_BUFFER_SIZE = 10; public static byte[] readBytesIntoSocket(Socket socket) throws IOException, InterruptedException { DataInputStream dis = new DataInputStream(socket.getInputStream()); ByteArrayOutputStream out = new ByteArrayOutputStream(); int count = 0; byte[] buffer = new byte[DEFAULT_BUFFER_SIZE]; while (dis.available() == 0) { Thread.sleep(1);/*from w w w .j a v a2 s.co m*/ } while ((count = dis.read(buffer)) > 0) { out.write(buffer, 0, count); if (count < DEFAULT_BUFFER_SIZE) break; } return out.toByteArray(); } }