Example usage for java.io ObjectInputStream close

List of usage examples for java.io ObjectInputStream close

Introduction

In this page you can find the example usage for java.io ObjectInputStream close.

Prototype

public void close() throws IOException 

Source Link

Document

Closes the input stream.

Usage

From source file:com.qut.middleware.crypto.impl.CryptoProcessorImpl.java

public PublicKey convertByteArrayPublicKey(byte[] rawKey) throws CryptoException {
    ByteArrayInputStream inputStream = null;
    ObjectInputStream objectInputStream = null;
    PublicKey key;//  w  w  w .j  ava 2  s. co  m

    try {
        inputStream = new ByteArrayInputStream(rawKey);
        objectInputStream = new ObjectInputStream(inputStream);
        key = (PublicKey) objectInputStream.readObject();

        return key;
    } catch (IOException e) {
        throw new CryptoException("Exception when attempting to unserialize PublicKey", e);
    } catch (ClassNotFoundException e) {
        throw new CryptoException("Exception when attempting to unserialize PublicKey", e);
    } finally {
        try {
            if (objectInputStream != null)
                objectInputStream.close();

            if (inputStream != null)
                inputStream.close();
        } catch (IOException e) {
            throw new CryptoException(
                    "Exception when attempting to unserialize PublicKey (stream close failed)", e);
        }
    }
}

From source file:es.mityc.firmaJava.libreria.utilidades.Base64.java

/**
 * Attempts to decode Base64 data and deserialize a Java
 * Object within. Returns <tt>null</tt> if there was an error.
 *
 * @param encodedObject The Base64 data to decode
 * @return The decoded and deserialized object
 * @since 1.5//from  ww  w . j a  v  a2  s. c o  m
 */
public static Object decodeToObject(String encodedObject) {
    // Decode and gunzip if necessary
    byte[] objBytes = decode(encodedObject);

    ByteArrayInputStream bais = null;
    ObjectInputStream ois = null;
    Object obj = null;

    try {
        bais = new ByteArrayInputStream(objBytes);
        ois = new ObjectInputStream(bais);

        obj = ois.readObject();
    } // end try
    catch (IOException e) {
        log.error(e);
        obj = null;
    } // end catch
    catch (ClassNotFoundException e) {
        log.error(e);
        obj = null;
    } // end catch
    finally {
        try {
            bais.close();
        } catch (Exception e) {
            log.error(e);
        }
        try {
            ois.close();
        } catch (Exception e) {
            log.error(e);
        }
    } // end finally

    return obj;
}

From source file:vitkin.sfdc.mojo.wsdl.WsdlDownloadlMojo.java

/**
 * Load cookies from the previous instance execution.
 *
 * @param env Salesforce environment. Either 'sandbox' or 'dev-prod'.
 *
 * @return The loaded cookie store or null if it can't load it.
 */// w  w w  . j  a  va2  s  .  c  o m
private CookieStore loadCookies(final String env) {
    final Log logger = getLog();
    final File cookieStorePath = new File(cookiesDirectory, env);

    CookieStore cookieStore = null;

    if (cookieStorePath.exists()) {
        final File cookieStoreFile = new File(cookieStorePath, username + COOKIES_SUFFIX);

        if (cookieStoreFile.exists()) {
            logger.info("Found cookies from previous execution. Loading from '" + cookieStoreFile + "'...");

            ObjectInputStream ois = null;

            try {
                ois = xstream
                        .createObjectInputStream(new BufferedInputStream(new FileInputStream(cookieStoreFile)));

                cookieStore = (BasicCookieStore) ois.readObject();
            } catch (IOException ex) {
                logger.warn("Failed reading cookies from previous run!", ex);
            } catch (ClassNotFoundException ex) {
                logger.warn("Failed loading cookies from previous run!", ex);
            } finally {
                if (ois != null) {
                    try {
                        ois.close();
                    } catch (IOException ex) {
                        logger.warn(ex.getMessage(), ex);
                    }
                }
            }
        }
    }

    return cookieStore;
}

From source file:com.moscona.dataSpace.persistence.DirectoryDataStore.java

@Override
@SuppressWarnings({ "unchecked" }) // setting the backing array without checking type compatibility
public void restoreSegment(IVectorSegment segment) throws DataSpaceException, InvalidStateException {
    AbstractVectorSegment abstractSegment = (AbstractVectorSegment) segment;
    SegmentFileInfo fileInfo = new SegmentFileInfo(segment);
    IVectorSegmentBackingArray backingArray = null;
    stats.startTimerFor(TIMING_RESTORE_SEGMENT);
    try {//from   w  w w  .ja v  a 2 s  . co m
        InputStream in = new FileInputStream(fileInfo.filePath);
        try {
            ObjectInputStream objIn = new ObjectInputStream(new GZIPInputStream(in));
            try {
                backingArray = (IVectorSegmentBackingArray) objIn.readObject();
                abstractSegment.setBackingArray(backingArray); // unchecked call
                markSwappedIn(abstractSegment);
            } finally {
                objIn.close();
            }
        } finally {
            in.close();
        }
    } catch (Exception e) {
        throw new DataSpaceException(
                "Exception while restoring backing array from " + fileInfo.filePath + ": " + e, e);
    } finally {
        stopTimerFor(TIMING_RESTORE_SEGMENT);
    }
}

From source file:com.wabacus.util.DesEncryptTools.java

public static void initEncryptKey() throws IOException {
    KEY_OBJ = null;//  w  w w  .  jav  a  2 s .  c  o m
    IS_NEWKEY = false;
    String filepath = Config.getInstance().getSystemConfigValue("3des-keyfilepath", "");
    if (filepath.equals("")) {
        log.warn("wabacus.cfg.xml?3des-keyfilepath?3des");
        return;
    }
    InputStream istream = null;
    File file = null;
    ObjectInputStream ois = null;
    try {
        if (Tools.isDefineKey("classpath", filepath)) {
            filepath = Tools.getRealKeyByDefine("classpath", filepath);
            filepath = Tools.replaceAll(filepath, "\\", "/");
            filepath = Tools.replaceAll(filepath, "//", "/");
            while (filepath.startsWith("/"))
                filepath = filepath.substring(1);
            istream = ConfigLoadManager.currentDynClassLoader.getResourceAsStream(filepath);
            if (istream == null) {
                int idx = filepath.lastIndexOf("/");
                String filename = null;
                if (idx > 0) {
                    filename = filepath.substring(idx + 1);
                    filepath = filepath.substring(0, idx);
                } else {
                    filename = filepath;
                    filepath = "";
                }
                file = WabacusAssistant.getInstance().getFileObjByPathInClasspath(filepath, filename);
            }
        } else {
            file = new File(
                    WabacusAssistant.getInstance().parseConfigPathToRealPath(filepath, Config.webroot_abspath));
            if (file.exists()) {
                istream = new FileInputStream(file);
            }
        }
        if (istream == null && file != null) {
            log.info("" + file.getPath() + "");
            createEncryptKey(file);
            istream = new FileInputStream(file);
            IS_NEWKEY = true;
        }
        ois = new ObjectInputStream(istream);
        KEY_OBJ = (SecretKey) ois.readObject();
    } catch (Exception e) {
        throw new WabacusConfigLoadingException("?3DES", e);
    } finally {
        try {
            if (istream != null)
                istream.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
        try {
            if (ois != null)
                ois.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

From source file:com.sec.ose.osi.thread.job.identify.data.IdentifyErrorQueue.java

private void init(String userID) {
    identifyQueueErrorFileName = DAT_FILE_DIRECTORY + "/error_" + userID + ".dat";

    File dir = new File(DAT_FILE_DIRECTORY);
    if (!dir.exists()) {
        if (dir.mkdirs() == false) {
            System.err.println("Can not create folder");
        }/* w  w w .  ja  v a 2  s . c om*/
    }
    File file = new File(identifyQueueErrorFileName);
    FileInputStream fis = null;
    ObjectInputStream oisReader = null;
    try {
        if (!file.exists()) {
            file.createNewFile();
        } else {
            fis = new FileInputStream(identifyQueueErrorFileName);
            if (fis != null && fis.available() > 0) {
                oisReader = new ObjectInputStream(fis);

                IdentifyData tmpIdentifiedData;

                while ((tmpIdentifiedData = (IdentifyData) oisReader.readObject()) != null) {

                    log.debug("read from File : \n" + tmpIdentifiedData + "\n - queueSize: " + size());
                    identifyDataQueueError.add(tmpIdentifiedData);
                    log.debug("add - queueSize: " + size());

                }
            }
        }
    } catch (IOException e) {
        log.debug("The end of the stream/block data has been reached");
    } catch (Exception e) {
        log.warn(e);
    } finally {
        try {
            if (oisReader != null) {
                try {
                    oisReader.close();
                } catch (Exception e) {
                    log.debug(e);
                }
            }
            if (fis != null) {
                try {
                    fis.close();
                } catch (Exception e) {
                    log.debug(e);
                }
            }
        } catch (Exception e) {
            log.warn(e);
        }
    }

    updateDatFileByIdentifyErrorQueue();
}

From source file:com.visural.stereotyped.ui.service.StereotypeServiceImpl.java

public Component readPublished(String uuid) {
    ObjectInputStream ois = null;
    try {/* ww w. j  av a2 s . com*/
        File in = new File(getPublishedPath() + File.separator + uuid);
        if (!in.exists()) {
            return null;
        }
        return IOUtil.readObject(Component.class, Thread.currentThread().getContextClassLoader(),
                new FileInputStream(in));
    } catch (Exception ex) {
        Logger.getLogger(StereotypeServiceImpl.class.getName()).log(Level.SEVERE, null, ex);
        throw new IllegalStateException("An error occurred while reading the stereotype data.", ex);
    } finally {
        try {
            if (ois != null) {
                ois.close();
            }
        } catch (IOException ex) {
            Logger.getLogger(StereotypeServiceImpl.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}

From source file:org.apache.cxf.cwiki.SiteExporter.java

public void loadCache() throws Exception {
    File file = new File(rootOutputDir, pageCacheFile);
    if (file.exists()) {
        try {/* ww  w  .  j  ava  2  s.c o  m*/
            FileInputStream fin = new FileInputStream(file);
            ObjectInputStream oin = new ObjectInputStream(fin);
            pages = CastUtils.cast((Map<?, ?>) oin.readObject());
            blog = CastUtils.cast((Map<?, ?>) oin.readObject());
            oin.close();

            for (Page p : pages.values()) {
                p.setExporter(this);
            }
        } catch (Throwable t) {
            //invalid cache, punt
            pages.clear();
            blog.clear();
        }
    }
}

From source file:org.mortbay.ijetty.IJetty.java

License:asdf

protected int getStoredJettyVersion() {
    File jettyDir = __JETTY_DIR;//w  ww .j  a va2  s. c  o  m
    if (!jettyDir.exists()) {
        return -1;
    }
    File versionFile = new File(jettyDir, "version.code");
    if (!versionFile.exists()) {
        return -1;
    }
    int val = -1;
    ObjectInputStream ois = null;
    try {
        ois = new ObjectInputStream(new FileInputStream(versionFile));
        val = ois.readInt();
        return val;
    } catch (Exception e) {
        Log.e(TAG, "Problem reading version.code", e);
        return -1;
    } finally {
        if (ois != null) {
            try {
                ois.close();
            } catch (Exception e) {
                Log.d(TAG, "Error closing version.code input stream", e);
            }
        }
    }
}

From source file:com.example.administrator.terrificweather.common.ACache.java

/**
 * ? Serializable?/*from  w  w  w.j  a  va2  s .  co  m*/
 *
 * @return Serializable ?
 */
public Object getAsObject(String key) {
    byte[] data = getAsBinary(key);
    if (data != null) {
        ByteArrayInputStream bais = null;
        ObjectInputStream ois = null;
        try {
            bais = new ByteArrayInputStream(data);
            ois = new ObjectInputStream(bais);
            Object reObject = ois.readObject();
            return reObject;
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        } finally {
            try {
                if (bais != null)
                    bais.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
            try {
                if (ois != null)
                    ois.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
    return null;
}