PageRenderTime 77ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/core/src/main/java/com/google/code/twiddling/core/io/SystemIO.java

http://twiddling.googlecode.com/
Java | 76 lines | 40 code | 13 blank | 23 comment | 0 complexity | accd48e46c54b13eedf7267595128e4c MD5 | raw file
Possible License(s): Apache-2.0
  1. /*
  2. * Licensed to the Apache Software Foundation (ASF) under one
  3. * or more contributor license agreements. See the NOTICE file
  4. * distributed with this work for additional information
  5. * regarding copyright ownership. The ASF licenses this file
  6. * to you under the Apache License, Version 2.0 (the
  7. * "License"); you may not use this file except in compliance
  8. * with the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing,
  13. * software distributed under the License is distributed on an
  14. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  15. * KIND, either express or implied. See the License for the
  16. * specific language governing permissions and limitations
  17. * under the License.
  18. */
  19. package com.google.code.twiddling.core.io;
  20. import java.io.InputStream;
  21. import java.io.PrintWriter;
  22. /**
  23. *
  24. * @author <a href="mailto:jeff.yuchang@gmail.com">Jeff Yu</a>
  25. *
  26. */
  27. public class SystemIO implements IO{
  28. protected InputStream inputStream;
  29. protected PrintWriter out;
  30. protected PrintWriter err;
  31. public SystemIO() {
  32. this(System.in, new PrintWriter(System.out), new PrintWriter(System.err));
  33. }
  34. public SystemIO(InputStream is, PrintWriter pout, PrintWriter perr) {
  35. this.inputStream = is;
  36. this.out = pout;
  37. this.err = perr;
  38. }
  39. public InputStream getInputStream() {
  40. return inputStream;
  41. }
  42. public PrintWriter getOut() {
  43. return out;
  44. }
  45. public PrintWriter getErr() {
  46. return err;
  47. }
  48. public InputStream redirectIn(InputStream in) {
  49. InputStream temp = this.inputStream;
  50. this.inputStream = in;
  51. return temp;
  52. }
  53. public PrintWriter redirectOut(PrintWriter out) {
  54. PrintWriter temp = this.out;
  55. this.out = out;
  56. return temp;
  57. }
  58. public PrintWriter redirectErr(PrintWriter err) {
  59. PrintWriter temp = this.err;
  60. this.err = err;
  61. return temp;
  62. }
  63. }