Debian Codegraph @

src/main/java/io/airlift/slice/SliceStreamUtils.java

raw
1 /*
2 * Licensed under the Apache License, Version 2.0 (the "License");
3 * you may not use this file except in compliance with the License.
4 * You may obtain a copy of the License at
5 *
6 * http://www.apache.org/licenses/LICENSE-2.0
7 *
8 * Unless required by applicable law or agreed to in writing, software
9 * distributed under the License is distributed on an "AS IS" BASIS,
10 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 * See the License for the specific language governing permissions and
12 * limitations under the License.
13 */
14 package io.airlift.slice;
15
16 import java.io.EOFException;
17 import java.io.IOException;
18 import java.io.InputStream;
19 import java.io.OutputStream;
20
21 final class SliceStreamUtils
22 {
23 private SliceStreamUtils()
24 {
25 }
26
27 public static void copyStreamFully(InputStream in, OutputStream out, int length)
28 throws IOException
29 {
30 byte[] bytes = new byte[4096];
31 while (length > 0) {
32 int newBytes = in.read(bytes, 0, Math.min(bytes.length, length));
33 if (newBytes < 0) {
34 throw new EOFException();
35 }
36 out.write(bytes, 0, newBytes);
37 length -= newBytes;
38 }
39 }
40 }