use of com.bonree.brfs.disknode.server.handler.data.WriteData in project BRFS by zhangnianli.
the class HttpDiskNodeClient method writeDatas.
@Override
public WriteResult[] writeDatas(String path, List<byte[]> dataList) throws IOException {
WriteDataList datas = new WriteDataList();
WriteData[] dataArray = new WriteData[dataList.size()];
for (int i = 0; i < dataArray.length; i++) {
WriteData data = new WriteData();
data.setBytes(dataList.get(i));
dataArray[i] = data;
}
datas.setDatas(dataArray);
URI uri = new URIBuilder().setScheme(DEFAULT_SCHEME).setHost(host).setPort(port).setPath(DiskContext.URI_DISK_NODE_ROOT + path).build();
try {
LOG.info("write file[{}] with {} datas to {}:{}", path, dataList.size(), host, port);
HttpResponse response = client.executePost(uri, ProtoStuffUtils.serialize(datas));
LOG.debug("write file[{}] response[{}]", path, response.getStatusCode());
if (response.isReponseOK()) {
WriteResultList resultList = ProtoStuffUtils.deserialize(response.getResponseBody(), WriteResultList.class);
return resultList.getWriteResults();
}
} catch (Exception e) {
LOG.error("write file[{}] to {}:{} error", path, host, port, e);
}
return null;
}
Aggregations