String charsetName)
throws TDHSException {
ByteArrayOutputStream retData = new ByteArrayOutputStream();
try {
while (true) {
BasePacket ret = null;
ret = queue.poll(timeOut, TimeUnit.MILLISECONDS);
if (ret == null) {
throw new TDHSTimeoutException("TimeOut");
} else {
if (TDHSResponseEnum.ClientStatus.ACCEPT.equals(ret.getClientStatus())) {
retData.write(ret.getData());
} else if (TDHSResponseEnum.ClientStatus.OK.equals(ret.getClientStatus())) {
retData.write(ret.getData());
return new TDHSResponse(ret.getClientStatus(), metaData, retData.toByteArray(),
charsetName);
} else if (ret.getClientStatus() != null && ret.getClientStatus().getStatus() >= 400 &&
ret.getClientStatus().getStatus() < 600) {
return new TDHSResponse(ret.getClientStatus(), metaData, ret.getData(), charsetName);
} else {
throw new TDHSException("unknown response code! [" + (ret.getClientStatus() != null ?
String.valueOf(ret.getClientStatus().getStatus()) : "") + "]");
}
}
}
} catch (InterruptedException e) {
throw new TDHSException(e);