Here you can find the source of readBytes(InputStream in, byte[] b)
Parameter | Description |
---|---|
in | input stream |
b | bytes |
Parameter | Description |
---|
public static int readBytes(InputStream in, byte[] b) throws IOException
//package com.java2s; /*//from w ww. ja v a2s . c o m * Created on 01.02.2005 * * JDBReport Generator * * Copyright (C) 2005-2014 Andrey Kholmanskih * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * */ import java.io.IOException; import java.io.InputStream; public class Main { /** * Fill array from stream * * @param in input stream * @param b bytes * @return count bytes reads from stream * @throws java.io.IOException */ public static int readBytes(InputStream in, byte[] b) throws IOException { int l = b.length; int pos = 0; int n; do { n = in.read(b, pos, l); if (n > 0) { pos += n; l -= n; } } while (n > 0 && l > 0); return pos; } }