1. /*
  2. * Copyright 2002-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. package org.apache.commons.io.output;
  17. import java.io.IOException;
  18. import java.io.FilterWriter;
  19. import java.io.Writer;
  20. /**
  21. *
  22. * A Proxy stream which acts as expected, that is it passes the method
  23. * calls on to the proxied stream and doesn't change which methods are
  24. * being called. It is an alternative base class to FilterWriter
  25. * to increase reusability, because FilterWriter changes the
  26. * methods being called, such as write(char[]) to write(char[], int, int)
  27. * and write(String) to write(String, int, int).
  28. */
  29. public class ProxyWriter extends FilterWriter {
  30. private Writer proxy;
  31. /**
  32. * Constructs a new ProxyWriter.
  33. * @param proxy Writer to delegate to
  34. */
  35. public ProxyWriter(Writer proxy) {
  36. super(proxy);
  37. this.proxy = proxy;
  38. }
  39. /** @see java.io.Writer#write(int) */
  40. public void write(int idx) throws IOException {
  41. this.proxy.write(idx);
  42. }
  43. /** @see java.io.Writer#write(char[]) */
  44. public void write(char[] chr) throws IOException {
  45. this.proxy.write(chr);
  46. }
  47. /** @see java.io.Writer#write(char[], int, int) */
  48. public void write(char[] chr, int st, int end) throws IOException {
  49. this.proxy.write(chr, st, end);
  50. }
  51. /** @see java.io.Writer#write(String) */
  52. public void write(String str) throws IOException {
  53. this.proxy.write(str);
  54. }
  55. /** @see java.io.Writer#write(String, int, int) */
  56. public void write(String str, int st, int end) throws IOException {
  57. this.proxy.write(str, st, end);
  58. }
  59. /** @see java.io.Writer#flush() */
  60. public void flush() throws IOException {
  61. this.proxy.flush();
  62. }
  63. /** @see java.io.Writer#close() */
  64. public void close() throws IOException {
  65. this.proxy.close();
  66. }
  67. }