From 33613a85afc4b1481367fbe92a17ee59c240250b Mon Sep 17 00:00:00 2001 From: Sven Eisenhauer Date: Fri, 10 Nov 2023 15:11:48 +0100 Subject: add new repo --- .../hjp5/examples/Listing1805.java | 65 ++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 Master/Reference Architectures and Patterns/hjp5/examples/Listing1805.java (limited to 'Master/Reference Architectures and Patterns/hjp5/examples/Listing1805.java') diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing1805.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing1805.java new file mode 100644 index 0000000..f7de539 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing1805.java @@ -0,0 +1,65 @@ +/* Listing1805.java */ + +import java.io.*; + +class UpCaseWriter +extends FilterWriter +{ + public UpCaseWriter(Writer out) + { + super(out); + } + + public void write(int c) + throws IOException + { + super.write(Character.toUpperCase((char)c)); + } + + public void write(char[] cbuf, int off, int len) + throws IOException + { + for (int i = 0; i < len; ++i) { + write(cbuf[off + i]); + } + } + + public void write(String str, int off, int len) + throws IOException + { + write(str.toCharArray(), off, len); + } +} + +public class Listing1805 +{ + public static void main(String[] args) + { + PrintWriter f; + String s = "und dieser String auch"; + + try { + f = new PrintWriter( + new UpCaseWriter( + new FileWriter("upcase.txt"))); + //Aufruf von außen + f.println("Diese Zeile wird schön groß geschrieben"); + //Test von write(int) + f.write('a'); + f.println(); + //Test von write(String) + f.write(s); + f.println(); + //Test von write(String, int, int) + f.write(s,0,17); + f.println(); + //Test von write(char[], int, int) + f.write(s.toCharArray(),0,10); + f.println(); + //--- + f.close(); + } catch (IOException e) { + System.out.println("Fehler beim Erstellen der Datei"); + } + } +} \ No newline at end of file -- cgit v1.2.3