blob: b85b6acaef14a9f97e17211e2b10f2b445a9b7f0 [file] [log] [blame]
slowr60d4d102017-08-16 18:33:58 -07001/* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
Dimitrios Mavrommatis96b255a2017-12-06 13:09:25 -08004package org.onosproject.xran.asn1lib.ber.internal;
slowr60d4d102017-08-16 18:33:58 -07005
6import java.io.EOFException;
7import java.io.IOException;
8import java.io.InputStream;
9
10public class Util {
11
12 public static void readFully(InputStream is, byte[] buffer) throws IOException {
13 readFully(is, buffer, 0, buffer.length);
14 }
15
16 public static void readFully(InputStream is, byte[] buffer, int off, int len) throws IOException {
17 do {
18 int bytesRead = is.read(buffer, off, len);
19 if (bytesRead == -1) {
20 throw new EOFException("Unexpected end of input stream.");
21 }
22
23 len -= bytesRead;
24 off += bytesRead;
25 } while (len > 0);
26 }
27
28}