Persoenliche Mediazentrale
ulrich
2021-04-05 2b5c60f130bf5d6e0ad4521d327b81947cd2eab7
commit | author | age
d86ba2 1 /*
U 2  * To change this license header, choose License Headers in Project Properties.
3  * To change this template file, choose Tools | Templates
4  * and open the template in the editor.
5  */
6 package de.uhilger.mediaz.api;
7
8 import com.google.gson.Gson;
9 import com.sun.net.httpserver.HttpExchange;
10 import com.sun.net.httpserver.HttpHandler;
cfa858 11 import de.uhilger.mediaz.entity.Ablageort;
d86ba2 12 import java.io.File;
U 13 import java.io.IOException;
14 import java.io.OutputStream;
15
16 /**
17  *
18  * @author ulrich
19  */
20 public class AblageTestHandler implements HttpHandler {
21
22   @Override
23   public void handle(HttpExchange e) throws IOException {
b379f5 24     Ablageort ablageort = new Ablageort();
U 25     ablageort.setName("Katalog");
26     ablageort.setOrt("/home/ulrich/Videos");
27     ablageort.setUrl("/media/test");
d86ba2 28     
U 29     Gson gson = new Gson();
b379f5 30     File mediaOrdner = new File(ablageort.getOrt());
d86ba2 31     File[] files = mediaOrdner.listFiles();
U 32     String json = gson.toJson(files);
33     
34     StringBuilder sb = new StringBuilder();
35     sb.append(json);
36     
b379f5 37     json = gson.toJson(ablageort);
d86ba2 38     sb.append(json);
U 39     
40     byte[] b = sb.toString().getBytes();
41     
42     //String response = getResponseString(map, cmd, antwort);
43     e.sendResponseHeaders(200, b.length);
44     OutputStream os = e.getResponseBody();
45     os.write(b);
46     os.close();        
47   }
48   
49 }