use of com.jph.takephoto.model.TException in project TakePhoto by crazycodeboy.
the class TImageFiles method inputStreamToFile.
/**
* InputStream 转File
* */
public static void inputStreamToFile(InputStream is, File file) throws TException {
if (file == null) {
Log.i(TAG, "inputStreamToFile:file not be null");
throw new TException(TExceptionType.TYPE_WRITE_FAIL);
}
FileOutputStream fos = null;
try {
fos = new FileOutputStream(file);
byte[] buffer = new byte[1024 * 10];
int i;
while ((i = is.read(buffer)) != -1) {
fos.write(buffer, 0, i);
}
} catch (IOException e) {
Log.e(TAG, "InputStream 写入文件出错:" + e.toString());
throw new TException(TExceptionType.TYPE_WRITE_FAIL);
} finally {
try {
fos.flush();
fos.close();
is.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
use of com.jph.takephoto.model.TException in project TakePhoto by crazycodeboy.
the class TUtils method sendIntentBySafely.
/**
* 安全地发送Intent
* @param contextWrap
* @param intentWapList 要发送的Intent以及候选Intent
* @param defaultIndex 默认发送的Intent
* @param isCrop 是否为裁切照片的Intent
* @throws TException
*/
public static void sendIntentBySafely(TContextWrap contextWrap, List<TIntentWap> intentWapList, int defaultIndex, boolean isCrop) throws TException {
if (defaultIndex + 1 > intentWapList.size())
throw new TException(isCrop ? TExceptionType.TYPE_NO_MATCH_PICK_INTENT : TExceptionType.TYPE_NO_MATCH_CROP_INTENT);
TIntentWap intentWap = intentWapList.get(defaultIndex);
List result = contextWrap.getActivity().getPackageManager().queryIntentActivities(intentWap.getIntent(), PackageManager.MATCH_ALL);
if (result.isEmpty()) {
sendIntentBySafely(contextWrap, intentWapList, ++defaultIndex, isCrop);
} else {
startActivityForResult(contextWrap, intentWap);
}
}
Aggregations