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 { |
cfa858
|
24 |
Ablageort ablage = new Ablageort(); |
d86ba2
|
25 |
ablage.setName("Katalog"); |
U |
26 |
ablage.setOrt("/home/ulrich/Videos"); |
|
27 |
|
|
28 |
Gson gson = new Gson(); |
|
29 |
File mediaOrdner = new File(ablage.getOrt()); |
|
30 |
File[] files = mediaOrdner.listFiles(); |
|
31 |
String json = gson.toJson(files); |
|
32 |
|
|
33 |
StringBuilder sb = new StringBuilder(); |
|
34 |
sb.append(json); |
|
35 |
|
|
36 |
json = gson.toJson(ablage); |
|
37 |
sb.append(json); |
|
38 |
|
|
39 |
byte[] b = sb.toString().getBytes(); |
|
40 |
|
|
41 |
//String response = getResponseString(map, cmd, antwort); |
|
42 |
e.sendResponseHeaders(200, b.length); |
|
43 |
OutputStream os = e.getResponseBody(); |
|
44 |
os.write(b); |
|
45 |
os.close(); |
|
46 |
} |
|
47 |
|
|
48 |
} |