1/*
2 * Copyright 2008 the original author or authors.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16package org.mockftpserver.core.util
17
18/**
19 * Contains static I/O-related utility methods.
20 *
21 * @version $Revision: $ - $Date: $
22 *
23 * @author Chris Mair
24 */
25class IoUtil {
26
27    /**
28     * Read the contents of the InputStream and return as a byte[].
29     *
30     * @param in - the InputStream to read
31     * @return the contents of the InputStream as a byte[]
32     *
33     * @throws AssertionError - if the InputStream is null
34     * @throws IOException
35     */
36     static byte[] readBytes(InputStream input) {
37        assert input != null
38        ByteArrayOutputStream outBytes = new ByteArrayOutputStream()
39
40        try {
41            while (true) {
42                int b = input.read()
43                if (b == -1) {
44                    break
45                }
46                outBytes.write(b)
47            }
48        }
49        finally {
50            input.close()
51        }
52        return outBytes.toByteArray()
53    }
54
55    /**
56     * Private constructor to prevent instantiation. All members are static.
57     */
58    private IoUtil() {
59    }
60
61}
62