1. /*
  2. * Copyright 2003-2004 The Apache Software Foundation
  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. *
  16. */
  17. package org.apache.tools.ant;
  18. import java.io.IOException;
  19. import java.io.InputStream;
  20. /**
  21. *
  22. * Passes input requests tot he project object for demuxing into
  23. * individual tasks and threads.
  24. *
  25. * @since Ant 1.6
  26. */
  27. public class DemuxInputStream extends InputStream {
  28. /**
  29. * The project to from which to get input.
  30. */
  31. private Project project;
  32. /**
  33. * Create a DemuxInputStream for the given project
  34. *
  35. * @param project the project instance
  36. */
  37. public DemuxInputStream(Project project) {
  38. this.project = project;
  39. }
  40. public int read() throws IOException {
  41. byte[] buffer = new byte[1];
  42. if (project.demuxInput(buffer, 0, 1) == -1) {
  43. return -1;
  44. }
  45. return buffer[0];
  46. }
  47. public int read(byte[] buffer, int offset, int length) throws IOException {
  48. return project.demuxInput(buffer, offset, length);
  49. }
  50. }