use of java.io.StreamCorruptedException in project mailim by zengsn.
the class InputUtil method readObjectFromLocal.
/**
* 读取本地对象
* @param context
* @param fielName 文件名
* @return
*/
@SuppressWarnings("unchecked")
public T readObjectFromLocal(Context context, String fielName) {
T bean;
try {
// 获得输入流
FileInputStream fis = context.openFileInput(fielName);
ObjectInputStream ois = new ObjectInputStream(fis);
bean = (T) ois.readObject();
fis.close();
ois.close();
return bean;
} catch (StreamCorruptedException e) {
// Toast.makeText(ShareTencentActivity.this,"出现异常3",Toast.LENGTH_LONG).show();//弹出Toast消息
e.printStackTrace();
return null;
} catch (OptionalDataException e) {
// Toast.makeText(ShareTencentActivity.this,"出现异常4",Toast.LENGTH_LONG).show();//弹出Toast消息
e.printStackTrace();
return null;
} catch (FileNotFoundException e) {
// Toast.makeText(ShareTencentActivity.this,"出现异常5",Toast.LENGTH_LONG).show();//弹出Toast消息
e.printStackTrace();
return null;
} catch (IOException e) {
e.printStackTrace();
return null;
} catch (ClassNotFoundException e) {
// Toast.makeText(ShareTencentActivity.this,"出现异常6",Toast.LENGTH_LONG).show();//弹出Toast消息
e.printStackTrace();
return null;
}
}
use of java.io.StreamCorruptedException in project mailim by zengsn.
the class InputUtil method readObjectFromSdCard.
/**
* 读取sd卡对象
* @param fileName 文件名
* @return
*/
@SuppressWarnings("unchecked")
public T readObjectFromSdCard(String fileName) {
if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
// 检测sd卡是否存在
T bean;
File sdCardDir = Environment.getExternalStorageDirectory();
File sdFile = new File(sdCardDir, fileName);
try {
FileInputStream fis = new FileInputStream(sdFile);
ObjectInputStream ois = new ObjectInputStream(fis);
bean = (T) ois.readObject();
fis.close();
ois.close();
return bean;
} catch (StreamCorruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return null;
} catch (OptionalDataException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return null;
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return null;
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return null;
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return null;
}
} else {
return null;
}
}
use of java.io.StreamCorruptedException in project carat by amplab.
the class CaratSampleDB method fillSample.
/*
* Read a sample from the current position of the cursor. TODO: Needs to be
* updated when fields update.
*/
private Sample fillSample(Cursor cursor) {
Sample s = null;
byte[] sampleB = cursor.getBlob(cursor.getColumnIndex(CaratSampleDB.COLUMN_SAMPLE));
if (sampleB != null) {
ObjectInputStream oi;
try {
oi = new ObjectInputStream(new ByteArrayInputStream(sampleB));
Object o = oi.readObject();
if (o != null)
s = SampleReader.readSample(o);
} catch (StreamCorruptedException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}
return s;
}
Aggregations