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