slowr | 60d4d10 | 2017-08-16 18:33:58 -0700 | [diff] [blame] | 1 | /* 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 Mavrommatis | 96b255a | 2017-12-06 13:09:25 -0800 | [diff] [blame] | 4 | package org.onosproject.xran.asn1lib.ber.internal; |
slowr | 60d4d10 | 2017-08-16 18:33:58 -0700 | [diff] [blame] | 5 | |
| 6 | import java.io.EOFException; |
| 7 | import java.io.IOException; |
| 8 | import java.io.InputStream; |
| 9 | |
| 10 | public 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 | } |