blob: c2d64cc7596de833cde7a4d5dcb0e864e092203f [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/. */
4package org.onosproject.xran.codecs.ber.internal;
5
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}