Here you can find the source of read(InputStream is, ByteBuffer buf, int bytes)
public static void read(InputStream is, ByteBuffer buf, int bytes) throws IOException
//package com.java2s; /******************************************************************************* * Copyright (c) 2010 Association for Decentralized Information Management in * Industry THTH ry.//from w w w .ja v a 2 s. c o m * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: * VTT Technical Research Centre of Finland - initial API and implementation *******************************************************************************/ import java.io.EOFException; import java.io.IOException; import java.io.InputStream; import java.nio.ByteBuffer; public class Main { public static void read(InputStream is, ByteBuffer buf, int bytes) throws IOException { while (bytes > 0 & buf.hasRemaining()) { int n = is.read(buf.array(), buf.position(), bytes); if (n < 0) throw new EOFException(); buf.position(buf.position() + n); bytes -= n; } } }