use of java.io.StreamCorruptedException in project midpoint by Evolveum.
the class SearchFilterType method copyOf.
/**
* Creates and returns a deep copy of a given {@code Serializable}.
*
* @param serializable
* The instance to copy or {@code null}.
* @return
* A deep copy of {@code serializable} or {@code null} if {@code serializable} is {@code null}.
*/
private static Serializable copyOf(final Serializable serializable) {
// CC-XJC Version 2.0 Build 2011-09-16T18:27:24+0000
if (serializable != null) {
try {
final ByteArrayOutputStream byteArrayOutput = new ByteArrayOutputStream();
final ObjectOutputStream out = new ObjectOutputStream(byteArrayOutput);
out.writeObject(serializable);
out.close();
final ByteArrayInputStream byteArrayInput = new ByteArrayInputStream(byteArrayOutput.toByteArray());
final ObjectInputStream in = new ObjectInputStream(byteArrayInput);
final Serializable copy = ((Serializable) in.readObject());
in.close();
return copy;
} catch (SecurityException e) {
throw ((AssertionError) new AssertionError((("Unexpected instance during copying object '" + serializable) + "'.")).initCause(e));
} catch (ClassNotFoundException e) {
throw ((AssertionError) new AssertionError((("Unexpected instance during copying object '" + serializable) + "'.")).initCause(e));
} catch (InvalidClassException e) {
throw ((AssertionError) new AssertionError((("Unexpected instance during copying object '" + serializable) + "'.")).initCause(e));
} catch (NotSerializableException e) {
throw ((AssertionError) new AssertionError((("Unexpected instance during copying object '" + serializable) + "'.")).initCause(e));
} catch (StreamCorruptedException e) {
throw ((AssertionError) new AssertionError((("Unexpected instance during copying object '" + serializable) + "'.")).initCause(e));
} catch (OptionalDataException e) {
throw ((AssertionError) new AssertionError((("Unexpected instance during copying object '" + serializable) + "'.")).initCause(e));
} catch (IOException e) {
throw ((AssertionError) new AssertionError((("Unexpected instance during copying object '" + serializable) + "'.")).initCause(e));
}
}
return null;
}
use of java.io.StreamCorruptedException in project jdk8u_jdk by JetBrains.
the class Test4067824 method main.
public static void main(String[] args) throws Exception {
ClassLoader cl = Test4067824.class.getClassLoader();
try {
Beans.instantiate(cl, "Test4067824");
} catch (ClassNotFoundException exception) {
// This is expected. Make sure there is the right detail message:
if (exception.toString().indexOf("IllegalAccessException") < 0)
throw new Error("unexpected exception", exception);
}
FileOutputStream fout = new FileOutputStream("foo.ser");
fout.write(new byte[] { 1, 2, 3, 4, 5 });
fout.close();
try {
// trying to instantiate corrupt foo.ser
Beans.instantiate(cl, "foo");
throw new Error("Instantiated corrupt .ser file OK!!??");
} catch (ClassNotFoundException exception) {
// expected exception
} catch (StreamCorruptedException exception) {
// expected exception
}
}
use of java.io.StreamCorruptedException in project SeaStar by 13120241790.
the class CacheManager method readObject.
/**
* 根据key获取缓存对象
*
* @param key
* @return
*/
@SuppressWarnings("unchecked")
public static <T> T readObject(String key) {
T obj = null;
try {
String cachePath = getCachePath(key);
File file = new File(cachePath);
if (file.exists()) {
FileInputStream fis = new FileInputStream(cachePath);
ObjectInputStream ois = new ObjectInputStream(fis);
obj = (T) ois.readObject();
ois.close();
}
} catch (StreamCorruptedException e) {
e.printStackTrace();
} catch (OptionalDataException e) {
e.printStackTrace();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
return obj;
}
use of java.io.StreamCorruptedException in project LeafPic by HoraApps.
the class HandlingAlbums method restoreBackup.
public void restoreBackup(Context context) {
FileInputStream inStream;
try {
File f = new File(context.getCacheDir(), backupFile);
inStream = new FileInputStream(f);
ObjectInputStream objectInStream = new ObjectInputStream(inStream);
dispAlbums = (ArrayList<Album>) objectInStream.readObject();
objectInStream.close();
} catch (FileNotFoundException e1) {
e1.printStackTrace();
} catch (ClassNotFoundException e1) {
e1.printStackTrace();
} catch (OptionalDataException e1) {
e1.printStackTrace();
} catch (StreamCorruptedException e1) {
e1.printStackTrace();
} catch (IOException e1) {
e1.printStackTrace();
}
}
use of java.io.StreamCorruptedException in project SunDay by iQuick.
the class FileUtil method readObjsFromFile.
/**
* 从序列化文件中读取对象列表
*
* @param fileName
* @return
*/
public static Object readObjsFromFile(String fileName) {
if (fileName == null)
return null;
Object obj = null;
FileInputStream fis = null;
ObjectInputStream ois = null;
try {
fileName = URLEncoder.encode(fileName, "UTF-8");
if (App.getContext().getFileStreamPath(fileName).exists()) {
fis = App.getContext().openFileInput(fileName);
ois = new ObjectInputStream(fis);
obj = ois.readObject();
}
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (StreamCorruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
try {
if (ois != null) {
ois.close();
}
if (fis != null) {
fis.close();
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return obj;
}
Aggregations