Example usage for java.io StreamCorruptedException getMessage

List of usage examples for java.io StreamCorruptedException getMessage

Introduction

In this page you can find the example usage for java.io StreamCorruptedException getMessage.

Prototype

public String getMessage() 

Source Link

Document

Returns the detail message string of this throwable.

Usage

From source file:fr.eoidb.util.ImageDownloader.java

@SuppressWarnings("unchecked")
public void loadImageCache(Context context) {
    if (BuildConfig.DEBUG)
        Log.v(LOG_TAG, "Loading image cache...");
    File cacheFile = new File(context.getCacheDir(), cacheFileName);

    if (cacheFile.exists() && cacheFile.length() > 0) {
        ObjectInputStream ois = null;
        try {//  w  w w . ja  v  a 2  s. c om
            HashMap<String, String> cacheDescription = new HashMap<String, String>();
            ois = new ObjectInputStream(new FileInputStream(cacheFile));
            cacheDescription = (HashMap<String, String>) ois.readObject();

            for (Entry<String, String> cacheDescEntry : cacheDescription.entrySet()) {
                loadSingleCacheFile(cacheDescEntry.getKey(), context);
            }
        } catch (StreamCorruptedException e) {
            Log.e(LOG_TAG, e.getMessage(), e);
        } catch (FileNotFoundException e) {
            Log.e(LOG_TAG, e.getMessage(), e);
        } catch (EOFException e) {
            //delete the corrupted cache file
            Log.w(LOG_TAG, "Deleting the corrupted cache file.", e);
            cacheFile.delete();
        } catch (IOException e) {
            Log.e(LOG_TAG, e.getMessage(), e);
        } catch (ClassNotFoundException e) {
            Log.e(LOG_TAG, e.getMessage(), e);
        } finally {
            if (ois != null) {
                try {
                    ois.close();
                } catch (IOException e) {
                    Log.e(LOG_TAG, e.getMessage(), e);
                }
            }
        }
    }
}

From source file:net.sf.ehcache.store.DiskStore.java

/**
 * Reads Index to disk on startup./*from   w w  w .j a  va  2  s. c  o  m*/
 * <p/>
 * if the index file does not exist, it creates a new one.
 * <p/>
 * Note that the cache is locked for the entire time that the index is being written
 *
 * @return True if the index was read successfully, false otherwise
 */
private synchronized boolean readIndex() throws IOException {
    ObjectInputStream objectInputStream = null;
    FileInputStream fin = null;
    boolean success = false;
    if (indexFile.exists()) {
        try {
            fin = new FileInputStream(indexFile);
            objectInputStream = new ObjectInputStream(fin);
            diskElements = (Map) objectInputStream.readObject();
            freeSpace = (List) objectInputStream.readObject();
            success = true;
        } catch (StreamCorruptedException e) {
            LOG.error("Corrupt index file. Creating new index.");
        } catch (IOException e) {
            //normal when creating the cache for the first time
            if (LOG.isDebugEnabled()) {
                LOG.debug("IOException reading index. Creating new index. ");
            }
        } catch (ClassNotFoundException e) {
            LOG.error("Class loading problem reading index. Creating new index. Initial cause was "
                    + e.getMessage(), e);
        } finally {
            try {
                if (objectInputStream != null) {
                    objectInputStream.close();
                } else if (fin != null) {
                    fin.close();
                }
            } catch (IOException e) {
                LOG.error("Problem closing the index file.");
            }

            //Always zero out file. That way if there is a dirty shutdown, the file will still be empty
            //the next time we start up and readIndex will automatically fail.
            //If there was a problem reading the index this time we also want to zero it out.
            createNewIndexFile();
        }
    } else {
        createNewIndexFile();
    }

    //Return the success flag
    return success;

}