2020import org .httprpc .kilo .io .JSONDecoder ;
2121import org .httprpc .kilo .io .JSONEncoder ;
2222import org .httprpc .kilo .io .TemplateEncoder ;
23- import org .httprpc .kilo .io .TextDecoder ;
2423import org .httprpc .kilo .io .TextEncoder ;
2524import org .httprpc .kilo .xml .ElementAdapter ;
2625import org .w3c .dom .Document ;
2928import java .io .IOException ;
3029import java .io .InputStreamReader ;
3130import java .net .URI ;
32- import java .nio .file .Files ;
3331import java .util .List ;
3432import java .util .Map ;
3533import java .util .MissingResourceException ;
@@ -47,8 +45,8 @@ public interface Example {
4745 public static void main (String [] args ) {
4846 execute ("Math Service 1" , Examples ::mathService1 );
4947 execute ("Math Service 2" , Examples ::mathService2 );
50- execute ("JSON Encoder" , Examples ::jsonEncoderAndDecoder );
51- execute ("Text Encoder/Decoder " , Examples ::textEncoderAndDecoder );
48+ execute ("JSON Encoder" , Examples ::jsonEncoder );
49+ execute ("Text Encoder" , Examples ::textEncoder );
5250 execute ("CSV Encoder" , Examples ::csvEncoder );
5351 execute ("Template Encoder" , Examples ::templateEncoder );
5452 execute ("Adapt Bean" , Examples ::adaptBean );
@@ -102,10 +100,7 @@ public static void mathService2() throws IOException {
102100 System .out .println (webServiceProxy .invoke ()); // 6.0
103101 }
104102
105- @ SuppressWarnings ("unchecked" )
106- public static void jsonEncoderAndDecoder () throws IOException {
107- var file = Files .createTempFile ("kilo" , ".json" );
108-
103+ public static void jsonEncoder () throws IOException {
109104 var map = mapOf (
110105 entry ("vegetables" , listOf (
111106 "carrots" ,
@@ -119,47 +114,21 @@ public static void jsonEncoderAndDecoder() throws IOException {
119114 ))
120115 );
121116
122- try {
123- try (var outputStream = Files .newOutputStream (file )) {
124- var jsonEncoder = new JSONEncoder ();
125-
126- jsonEncoder .write (map , outputStream );
127- }
117+ var jsonEncoder = new JSONEncoder ();
128118
129- try (var inputStream = Files .newInputStream (file )) {
130- var jsonDecoder = new JSONDecoder ();
119+ jsonEncoder .write (map , System .out );
131120
132- map = (Map <String , List <String >>)jsonDecoder .read (inputStream );
133- }
134-
135- System .out .println (map .get ("vegetables" ).getFirst ()); // carrots
136- } finally {
137- Files .delete (file );
138- }
121+ System .out .println ();
139122 }
140123
141- public static void textEncoderAndDecoder () throws IOException {
142- var file = Files .createTempFile ("kilo" , ".txt" );
143-
124+ public static void textEncoder () throws IOException {
144125 var text = "Hello, World!" ;
145126
146- try {
147- try (var outputStream = Files .newOutputStream (file )) {
148- var textEncoder = new TextEncoder ();
149-
150- textEncoder .write (text , outputStream );
151- }
127+ var textEncoder = new TextEncoder ();
152128
153- try (var inputStream = Files .newInputStream (file )) {
154- var textDecoder = new TextDecoder ();
129+ textEncoder .write (text , System .out );
155130
156- text = textDecoder .read (inputStream );
157- }
158-
159- System .out .println (text ); // Hello, World!
160- } finally {
161- Files .delete (file );
162- }
131+ System .out .println ();
163132 }
164133
165134 public static void csvEncoder () throws IOException {
0 commit comments