use of cn.jeesoft.qa.error.QAIOException in project QuickAndroid by ImKarl.
the class QAFileHttpHandler method handlerResponse.
@Override
public File handlerResponse(Response response) throws Exception {
if (targetFile == null) {
throw new QANoFoundException(QAException.CODE_IO_FILE, "'targetFile'不能为空");
}
File parentFile = targetFile.getParentFile();
if (parentFile != null && !parentFile.exists()) {
parentFile.mkdirs();
}
Exception exception = null;
InputStream stream = null;
byte[] buf = new byte[2048];
int len = 0;
FileOutputStream fos = null;
try {
ResponseBody responseBody = response.body();
stream = responseBody.byteStream();
fos = new FileOutputStream(targetFile);
while ((len = stream.read(buf)) != -1) {
fos.write(buf, 0, len);
}
fos.flush();
} catch (Exception e) {
exception = e;
} finally {
try {
if (stream != null)
stream.close();
} catch (IOException e) {
}
try {
if (fos != null)
fos.close();
} catch (IOException e) {
}
}
if (exception == null) {
return targetFile;
}
throw new QAIOException(QAException.CODE_IO_FILE, exception);
}
use of cn.jeesoft.qa.error.QAIOException in project QuickAndroid by ImKarl.
the class QABimtapHttpHandler method handlerResponse.
@Override
public Bitmap handlerResponse(Response response) throws Exception {
Exception exception = null;
Bitmap bitmap = null;
InputStream stream = null;
try {
stream = response.body().byteStream();
bitmap = BitmapFactory.decodeStream(stream);
} catch (Exception e) {
exception = e;
} finally {
if (stream != null) {
try {
stream.close();
} catch (IOException e) {
}
}
}
if (exception == null) {
return bitmap;
}
throw new QAIOException(QAException.CODE_IO_FILE, exception);
}
Aggregations