Search in sources :

Example 1 with OptionalDataException

use of java.io.OptionalDataException in project midpoint by Evolveum.

the class PropertySimpleValueFilterType 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;
}
Also used : Serializable(java.io.Serializable) InvalidClassException(java.io.InvalidClassException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) ObjectOutputStream(java.io.ObjectOutputStream) OptionalDataException(java.io.OptionalDataException) NotSerializableException(java.io.NotSerializableException) ByteArrayInputStream(java.io.ByteArrayInputStream) StreamCorruptedException(java.io.StreamCorruptedException) ObjectInputStream(java.io.ObjectInputStream)

Example 2 with OptionalDataException

use of java.io.OptionalDataException 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;
}
Also used : Serializable(java.io.Serializable) InvalidClassException(java.io.InvalidClassException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) ObjectOutputStream(java.io.ObjectOutputStream) OptionalDataException(java.io.OptionalDataException) NotSerializableException(java.io.NotSerializableException) ByteArrayInputStream(java.io.ByteArrayInputStream) StreamCorruptedException(java.io.StreamCorruptedException) ObjectInputStream(java.io.ObjectInputStream)

Example 3 with OptionalDataException

use of java.io.OptionalDataException 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;
}
Also used : FileNotFoundException(java.io.FileNotFoundException) StreamCorruptedException(java.io.StreamCorruptedException) IOException(java.io.IOException) File(java.io.File) OptionalDataException(java.io.OptionalDataException) FileInputStream(java.io.FileInputStream) ObjectInputStream(java.io.ObjectInputStream)

Example 4 with OptionalDataException

use of java.io.OptionalDataException 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();
    }
}
Also used : FileNotFoundException(java.io.FileNotFoundException) StreamCorruptedException(java.io.StreamCorruptedException) IOException(java.io.IOException) File(java.io.File) OptionalDataException(java.io.OptionalDataException) FileInputStream(java.io.FileInputStream) ObjectInputStream(java.io.ObjectInputStream)

Example 5 with OptionalDataException

use of java.io.OptionalDataException in project meatspace-android by RomainPiel.

the class CacheManager method readFile.

public Object readFile(String folderName, String fileName, Object def) {
    FileInputStream input = null;
    ObjectInputStream stream = null;
    String filePath = cachePath;
    if (folderName != null && !folderName.equals("")) {
        filePath += "/" + CACHE_PREFIX + folderName + "/";
    }
    File file = new File(filePath, CACHE_PREFIX + fileName);
    try {
        input = new FileInputStream(file);
        stream = new ObjectInputStream(input);
        Object data = stream.readObject();
        stream.close();
        input.close();
        if (data == null) {
            return def;
        }
        return data;
    } catch (OptionalDataException e) {
        System.err.println(file.getAbsolutePath());
        file.delete();
        return def;
    } catch (OutOfMemoryError e) {
        e.printStackTrace();
        return def;
    } catch (Exception e) {
        return def;
    }
}
Also used : File(java.io.File) OptionalDataException(java.io.OptionalDataException) FileInputStream(java.io.FileInputStream) OptionalDataException(java.io.OptionalDataException) ObjectInputStream(java.io.ObjectInputStream)

Aggregations

OptionalDataException (java.io.OptionalDataException)9 ObjectInputStream (java.io.ObjectInputStream)8 IOException (java.io.IOException)7 StreamCorruptedException (java.io.StreamCorruptedException)6 ByteArrayInputStream (java.io.ByteArrayInputStream)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4 InvalidClassException (java.io.InvalidClassException)4 NotSerializableException (java.io.NotSerializableException)4 ObjectOutputStream (java.io.ObjectOutputStream)4 Serializable (java.io.Serializable)4 File (java.io.File)3 FileInputStream (java.io.FileInputStream)3 FileNotFoundException (java.io.FileNotFoundException)2 PrivilegedActionException (java.security.PrivilegedActionException)1 PrivilegedExceptionAction (java.security.PrivilegedExceptionAction)1 Test (org.testng.annotations.Test)1 ZoneInfo (sun.util.calendar.ZoneInfo)1