use of org.openhab.binding.ihc.ws.datatypes.WSFile in project openhab1-addons by openhab.
the class IhcClient method LoadProjectFileFromController.
private Document LoadProjectFileFromController() throws IhcExecption {
try {
WSProjectInfo projectInfo = getProjectInfo();
int numberOfSegments = controllerService.getProjectNumberOfSegments();
int segmentationSize = controllerService.getProjectSegmentationSize();
logger.debug("Number of segments: {}", numberOfSegments);
logger.debug("Segmentation size: {}", segmentationSize);
ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
for (int i = 0; i < numberOfSegments; i++) {
logger.debug("Downloading segment {}", i);
WSFile data = controllerService.getProjectSegment(i, projectInfo.getProjectMajorRevision(), projectInfo.getProjectMinorRevision());
byteStream.write(data.getData());
}
logger.debug("File size before base64 encoding: {} bytes", byteStream.size());
byte[] decodedBytes = javax.xml.bind.DatatypeConverter.parseBase64Binary(byteStream.toString());
logger.debug("File size after base64 encoding: {} bytes", decodedBytes.length);
GZIPInputStream gzis = new GZIPInputStream(new ByteArrayInputStream(decodedBytes));
InputStreamReader in = new InputStreamReader(gzis, "ISO-8859-1");
InputSource reader = new InputSource(in);
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
return db.parse(reader);
} catch (Exception e) {
throw new IhcExecption(e);
}
}
use of org.openhab.binding.ihc.ws.datatypes.WSFile in project openhab1-addons by openhab.
the class IhcControllerService method getProjectSegment.
/**
* Query project segment data.
*
* @param index
* segments index.
* @param major
* project major revision number.
* @param minor
* project minor revision number.
* @return segments data.
*/
public synchronized WSFile getProjectSegment(int index, int major, int minor) throws IhcExecption {
final String soapQuery = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + "<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">" + "<soap:Body>" + " <ns1:getIHCProjectSegment1 xmlns:ns1=\"utcs\" xsi:type=\"xsd:int\">%s</ns1:getIHCProjectSegment1>" + " <ns2:getIHCProjectSegment2 xmlns:ns2=\"utcs\" xsi:type=\"xsd:int\">%s</ns2:getIHCProjectSegment2>" + " <ns3:getIHCProjectSegment3 xmlns:ns3=\"utcs\" xsi:type=\"xsd:int\">%s</ns3:getIHCProjectSegment3>" + "</soap:Body>" + "</soap:Envelope>";
String query = String.format(soapQuery, index, major, minor);
openConnection(url);
setRequestProperty("SOAPAction", "getIHCProjectSegment");
String response = sendQuery(query, timeout);
closeConnection();
WSFile file = new WSFile();
file.encodeData(response);
return file;
}
Aggregations