/*
|
* 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();
|
}
|
|
}
|