01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: *
17: */
18:
19: package org.apache.tools.ant;
20:
21: import java.io.IOException;
22: import java.io.InputStream;
23:
24: /**
25: *
26: * Passes input requests to the project object for demuxing into
27: * individual tasks and threads.
28: *
29: * @since Ant 1.6
30: */
31: public class DemuxInputStream extends InputStream {
32:
33: /**
34: * The project to from which to get input.
35: */
36: private Project project;
37:
38: /**
39: * Create a DemuxInputStream for the given project
40: *
41: * @param project the project instance
42: */
43: public DemuxInputStream(Project project) {
44: this .project = project;
45: }
46:
47: /**
48: * Read a byte from the project's demuxed input.
49: * @return the next byte
50: * @throws IOException on error
51: */
52: public int read() throws IOException {
53: byte[] buffer = new byte[1];
54: if (project.demuxInput(buffer, 0, 1) == -1) {
55: return -1;
56: }
57: return buffer[0];
58: }
59:
60: /**
61: * Read bytes from the project's demuxed input.
62: * @param buffer an array of bytes to read into
63: * @param offset the offset in the array of bytes
64: * @param length the number of bytes in the array
65: * @return the number of bytes read
66: * @throws IOException on error
67: */
68: public int read(byte[] buffer, int offset, int length)
69: throws IOException {
70: return project.demuxInput(buffer, offset, length);
71: }
72:
73: }
|