Advertisement
Guest User

Untitled

a guest
Jan 29th, 2020
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.96 KB | None | 0 0
  1. public class CaesarWriter extends Writer {
  2. private Writer writer;
  3. private int steps;
  4.  
  5. public CaesarWriter(Writer writer, int steps) {
  6. this.writer = writer;
  7. this.steps = steps;
  8. }
  9.  
  10. @Override
  11. public void write(String str) throws IOException {
  12. String erg = "";
  13.  
  14. for (int i = 0; i < str.length(); i++) {
  15. char current = str.charAt(i);
  16.  
  17. if (current >= 'a' && current <= 'z') {
  18. current += steps;
  19. if (current > 'z') {
  20. current -= 26;
  21. }
  22. }
  23.  
  24. if (current >= 'A' && current <= 'Z') {
  25. current += steps;
  26. if (current > 'Z') {
  27. current -= 26;
  28. }
  29. }
  30.  
  31. erg += current;
  32. }
  33.  
  34. this.writer.write(erg);
  35. }
  36.  
  37. @Override
  38. public void write(int c) throws IOException {
  39. this.writer.write(c);
  40. }
  41.  
  42. @Override
  43. public void write(char[] cbuf) throws IOException {
  44. this.writer.write(cbuf);
  45. }
  46.  
  47. @Override
  48. public void write(String str, int off, int len) throws IOException {
  49. this.writer.write(str, off, len);
  50. }
  51.  
  52. @Override
  53. public Writer append(CharSequence csq) throws IOException {
  54. return this.writer.append(csq);
  55. }
  56.  
  57. @Override
  58. public Writer append(CharSequence csq, int start, int end) throws IOException {
  59. return this.writer.append(csq, start, end);
  60. }
  61.  
  62. @Override
  63. public Writer append(char c) throws IOException {
  64. return this.writer.append(c);
  65. }
  66.  
  67. @Override
  68. public void write(char[] cbuf, int off, int len) throws IOException {
  69. this.writer.write(cbuf, off, len);
  70. }
  71.  
  72. @Override
  73. public void flush() throws IOException {
  74. this.writer.flush();
  75. }
  76.  
  77. @Override
  78. public void close() throws IOException {
  79. this.writer.close();
  80. }
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement