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:org.cyclop.test.AbstractTestCase.java

public <T> T deserialize(byte[] serialized, Class<T> clazz) throws IOException, ClassNotFoundException {
    ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(serialized));

    @SuppressWarnings("unchecked")
    T des = (T) in.readObject();/*  www  . j  a  v  a 2 s. c o m*/
    in.close();
    assertNotNull(des);
    return des;
}

From source file:edu.stanford.muse.lens.LensPrefs.java

public LensPrefs(String cacheDir) {
    pathToPrefsFile = cacheDir + File.separatorChar + PREFS_FILENAME;
    String pathToPrefsFileTxt = pathToPrefsFile + ".txt";
    log.info("Trying to load lens prefs from: " + pathToPrefsFileTxt);
    // read serialized state from file
    try {/*w  ww  . ja v a2s. co  m*/
        log.info("Trying to load lens prefs from: " + pathToPrefsFileTxt);
        loadPrefs(pathToPrefsFile + ".txt");
    } catch (IOException ioe) {
        log.info("Unable to load text lens prefs from " + pathToPrefsFileTxt);
        try {
            log.info("Trying to load lens prefs from: " + pathToPrefsFileTxt);
            FileInputStream fis = new FileInputStream(pathToPrefsFile);
            ObjectInputStream ois = new ObjectInputStream(fis);
            prefs = (Map<String, Map<String, Float>>) ois.readObject();
            ois.close();
        } catch (FileNotFoundException e) {
            // hilitePrefs = new ArrayList<BrowserPrefs>();
            log.info("No existing browser preferences file: " + pathToPrefsFile);
        } catch (Exception e) {
            log.warn("exception reading " + pathToPrefsFile + ": " + Util.stackTrace(e));
        }
    }
    log.info(prefs.size() + " terms have user-specified weights");
    if (log.isDebugEnabled())
        log.debug(" User prefs are : " + this);
}

From source file:com.newrelic.agent.deps.org.apache.http.impl.client.BasicAuthCache.java

@Override
public AuthScheme get(final HttpHost host) {
    Args.notNull(host, "HTTP host");
    final byte[] bytes = this.map.get(getKey(host));
    if (bytes != null) {
        try {/*from w  ww  . j av  a2  s.  c  o m*/
            final ByteArrayInputStream buf = new ByteArrayInputStream(bytes);
            final ObjectInputStream in = new ObjectInputStream(buf);
            final AuthScheme authScheme = (AuthScheme) in.readObject();
            in.close();
            return authScheme;
        } catch (IOException ex) {
            if (log.isWarnEnabled()) {
                log.warn("Unexpected I/O error while de-serializing auth scheme", ex);
            }
            return null;
        } catch (ClassNotFoundException ex) {
            if (log.isWarnEnabled()) {
                log.warn("Unexpected error while de-serializing auth scheme", ex);
            }
            return null;
        }
    } else {
        return null;
    }
}

From source file:com.joliciel.talismane.lexicon.LexiconDeserializer.java

public PosTaggerLexicon deserializeLexiconFile(ZipInputStream zis) {
    MONITOR.startTask("deserializeLexiconFile(ZipInputStream)");
    try {/*  w  w  w. j a va 2s  .  c  om*/
        PosTaggerLexicon lexicon = null;
        try {
            ZipEntry zipEntry;
            if ((zipEntry = zis.getNextEntry()) != null) {
                LOG.debug("Scanning zip entry " + zipEntry.getName());

                ObjectInputStream in = new ObjectInputStream(zis);
                lexicon = (PosTaggerLexicon) in.readObject();
                zis.closeEntry();
                in.close();
            } else {
                throw new RuntimeException("No zip entry in input stream");
            }
        } catch (IOException ioe) {
            throw new RuntimeException(ioe);
        } catch (ClassNotFoundException cnfe) {
            throw new RuntimeException(cnfe);
        }

        return lexicon;
    } finally {
        MONITOR.endTask("deserializeLexiconFile(ZipInputStream)");
    }
}

From source file:edu.caltechUcla.sselCassel.projects.jMarkets.server.network.ServletReceiver.java

/** Receive a request object from the client given the HttpServletRequest. If the object
 *  sent is not a request, throw an exception */
protected Request receive(HttpServletRequest r) {
    try {/*from w  w w. j a  va2s .c o m*/
        ObjectInputStream inputFromApplet = new ObjectInputStream(r.getInputStream());
        Request req = (Request) inputFromApplet.readObject();
        inputFromApplet.close();

        return req;
    } catch (IOException e) {
        log.error("Failed to receive request", e);
    } catch (ClassNotFoundException e) {
        log.error("Failed to receive request", e);
    }
    return null;
}

From source file:com.farhad.ngram.lang.detector.profile.LanguageProfile.java

public Map<String, Double> loadProfile(String profilePath) {

    Map<String, Double> mapInFile = new HashMap<>();
    try {/* w  w  w. j  a va2 s.c o m*/
        File toRead = new File(profilePath);
        FileInputStream fis = new FileInputStream(toRead);
        ObjectInputStream ois = new ObjectInputStream(fis);

        mapInFile = (HashMap<String, Double>) ois.readObject();

        ois.close();
        fis.close();

    } catch (Exception e) {
    }
    return mapInFile;
}

From source file:com.gargoylesoftware.htmlunit.WebDriverOldTestsTest.java

/**
 * @param expectedFile the expected file
 * @throws Exception if the test fails/*from   w w w  .  ja  v  a2  s  .c o m*/
 */
@SuppressWarnings("unchecked")
public WebDriverOldTestsTest(final File expectedFile) throws Exception {
    final FileInputStream fis = new FileInputStream(expectedFile);
    final ObjectInputStream oos = new ObjectInputStream(fis);
    final List<String> list = (List<String>) oos.readObject();
    for (final String s : list) {
        expectedLog_.add(s.trim());
    }
    oos.close();

    final String testFileName = expectedFile.getName().replaceFirst("\\.html\\..*", ".html");
    testFile_ = new File(expectedFile.getParentFile(), testFileName).toURI().toURL();
}

From source file:cs.register.abrirefeichar.java

@Override
public void lerd() {
    ObjectInputStream objectIn = null;
    try {/*from w  w w  .j  a va 2  s  .  co m*/
        objectIn = new ObjectInputStream(new BufferedInputStream(new FileInputStream("save")));

        setList1((List<partida>) objectIn.readObject());

        objectIn.close();
    } catch (IOException ex) {
        salvaresair(1);
        lerd();
        return;

    } catch (ClassNotFoundException ex) {
        salvaresair(1);
        lerd();
        return;
    } finally {
        try {
            objectIn.close();
        } catch (IOException ex) {
            salvaresair(1);
            lerd();
            return;

        }
    }

}

From source file:com.healthmarketscience.rmiio.RemoteStreamServerTest.java

/**
 * Returns the result of serializing and deserializing the given, exported
 * RemoteStub./*from w  ww  .ja  v  a 2  s  .  c o m*/
 * <p>
 * Note, i'm leaving the paragraph below because i believe it is related to
 * the problem, however, adding the serialization cycle did <b>not</b> solve
 * the hard ref problem (hence that code is still in place).
 * <p>
 * Evidently, something special happens to a RemoteStub when it is
 * serialized.  There were previously issues during testing where
 * RemoteStubs were throwing NoSuchObjectException on the first remote call.
 * In these cases, the server objects were being garbage collected before
 * ever being used.  Eventually, I realized that this was because the
 * RemoteStubs were not being serialized in the test code (because both the
 * client and server are in the same VM).  There was initially a hack in the
 * RemoteStreamServer to get around this problem by temporarily maintaining
 * a hard reference to the server object until the client makes the first
 * successful call (which could cause leaks if the client dies before making
 * the first call).  After determining that the issue was due to
 * serialization, I was able to make the problem disappear by forcing a
 * serialize/deserialize cycle on the RemoteStub in the test code before
 * handing it to the client thread.
 *
 * @param obj RMI stub to force into "remote" mode
 */
@SuppressWarnings("unchecked")
public static <T> T simulateRemote(T obj) throws IOException {
    PipeBuffer.InputStreamAdapter istream = new PipeBuffer.InputStreamAdapter();
    PipeBuffer.OutputStreamAdapter ostream = new PipeBuffer.OutputStreamAdapter();
    istream.connect(ostream);
    ObjectOutputStream objOstream = new ObjectOutputStream(ostream);
    objOstream.writeObject(obj);
    objOstream.close();

    ObjectInputStream objIstream = new ObjectInputStream(istream);
    try {
        obj = (T) objIstream.readObject();
    } catch (ClassNotFoundException e) {
        throw (IOException) ((new IOException()).initCause(e));
    }
    objIstream.close();

    return obj;
}

From source file:com.timesoft.kaitoo.ws.hibernate.AbstractPojo.java

/**
 * DOCUMENT ME!/*from ww w.  jav  a 2s . co  m*/
 *
 * @param stream DOCUMENT ME!
 *
 * @return DOCUMENT ME!
 *
 * @throws Exception DOCUMENT ME!
 */
public AbstractPojo deserialize(final byte[] stream) throws Exception {
    ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(stream));

    try {
        return (AbstractPojo) ois.readObject();
    } finally {
        ois.close();
    }
}