Java ByteBuffer Put read(InputStream is, ByteBuffer buf, int bytes)

Here you can find the source of read(InputStream is, ByteBuffer buf, int bytes)

Description

read

License

Open Source License

Declaration

public static void read(InputStream is, ByteBuffer buf, int bytes) throws IOException 

Method Source Code

//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;
        }
    }
}

Related

  1. putUUID(ByteBuffer bytes, UUID uuid)
  2. putVarint(ByteBuffer buffer, long number, int byteSize)
  3. putVInt(ByteBuffer b, int i)
  4. putWhatFits(ByteBuffer dest, ByteBuffer src)
  5. putWithChecksum(ByteBuffer buffer, int value, Adler32 checksum)
  6. readAsByteBuffer(final InputStream source)
  7. readBER32(ByteBuffer input)
  8. readByteBuffer(DataInputStream is)
  9. readByteBufferList(DataInputStream is)