KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tools > ant > DemuxInputStream


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * 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 JavaDoc;
22 import java.io.InputStream JavaDoc;
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 JavaDoc {
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 JavaDoc {
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     /**
62      * Read bytes from the project's demuxed input.
63      * @param buffer an array of bytes to read into
64      * @param offset the offset in the array of bytes
65      * @param length the number of bytes in the array
66      * @return the number of bytes read
67      * @throws IOException on error
68      */

69     public int read(byte[] buffer, int offset, int length) throws IOException JavaDoc {
70         return project.demuxInput(buffer, offset, length);
71     }
72
73 }
74
Popular Tags