/media/sda-magnetic/david/Extern-Magnetic-2022-06-29/Extern01/Dokumente-2021-05-8/disk10-ab-2020-01-10/02-debian-pc2-work/informatik/java-new/2020-11-23/StreamProg3.java


import java.io.*;

1:  interface CharEingabeStrom {
2:    int read() throws IOException;
3:  }

4:  class StringLeser implements CharEingabeStrom {
5:    private char[] dieZeichen;
6:    private int index = 0;

7:    public StringLeser(String s) { dieZeichen = s.toCharArray(); }

8:    public int read() {
9:      if(index == dieZeichen.length) return -1;
10:     else return dieZeichen[index++];
11:   }
12: }

13: class GrossBuchstabenFilter implements CharEingabeStrom {
14:   private CharEingabeStrom eingabeStrom;

15:   public GrossBuchstabenFilter(CharEingabeStrom cs) { eingabeStrom = cs; }

16:   public int read() throws IOException {
17:     int z = eingabeStrom.read();
18:     if(z == -1) return -1;
19:     else return Character.toUpperCase((char)z);
20:   }
21: }

22: class UmlautSzFilter implements CharEingabeStrom {
23:   private CharEingabeStrom eingabeStrom;
24:   private int naechstesZ = -1;

25:   public UmlautSzFilter(CharEingabeStrom cs) { eingabeStrom = cs; }

26:   public int read() throws IOException {
27:     if(naechstesZ != -1) {
28:       int z = naechstesZ;
29:       naechstesZ = -1;
30:       return z;
31:     } else {
32:       int z = eingabeStrom.read();
33:       if(z == -1)  return -1;
34:       switch((char)z) {
35:         case '\u00C4':  naechstesZ = 'e'; return 'A';
36:         case '\u00D6':  naechstesZ = 'e'; return 'O';
37:         case '\u00DC':  naechstesZ = 'e'; return 'U';
38:         case '\u00E4':  naechstesZ = 'e'; return 'a';
39:         case '\u00F6':  naechstesZ = 'e'; return 'o';
40:         case '\u00FC':  naechstesZ = 'e'; return 'u';
41:         case '\u00DF':  naechstesZ = 's'; return 's';
42:         default:        return z;
43:       }
44:     }
45:   }
46: }

47: public class Main {
48:   public static void main(String[] args) throws IOException {
49:     String s = new String("f\u00DF\u00D6");

50:     CharEingabeStrom cs;
51:     cs = new StringLeser( s );
52:     cs = new UmlautSzFilter( cs );
53:     cs = new GrossBuchstabenFilter( cs );

54:     int z = cs.read();
55:     while(z != -1) {
56:       System.out.print((char)z);
57:       z = cs.read();
58:     }
59:     System.out.println("");
60:   }
61: }