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:edu.stanford.muse.index.IndexUtils.java

public static List<Document> findAllDocs(String prefix) throws ClassNotFoundException, IOException {
    List<Document> allDocs = new ArrayList<Document>();

    // weird: sometimes we get a double-slash or double-backslash which kills the matching...
    // better canonicalize first, which calling new File() and then getAbsolutePath does
    prefix = new File(prefix).getAbsolutePath();
    String dir = ".";
    int x = prefix.lastIndexOf(File.separator);
    if (x >= 0)
        dir = prefix.substring(0, x);/*from  www.j av  a2s .c om*/
    File dirFile = new File(dir);
    // select valid header files
    File files[] = dirFile.listFiles(new Util.MyFilenameFilter(prefix, ".header"));
    for (File f : files) {
        try {
            Document d = null;
            ObjectInputStream headerOIS = new ObjectInputStream(new FileInputStream(f));
            d = (Document) headerOIS.readObject();
            headerOIS.close();
            allDocs.add(d);
        } catch (Exception e) {
            Util.print_exception(e, log);
        }
    }

    System.out.println(allDocs.size() + " documents found with prefix " + prefix);
    return allDocs;
}

From source file:androidGLUESigner.pdf.PDFSignerEngine.java

/**
 * set the state of the SignerEngine (hash, ocsp, calendar from current run)
 * @param in input byte[] holding the information to be stored
 *//*from ww  w. ja  v  a 2s.c  o  m*/
public void setState(byte[] in) {
    ByteArrayInputStream bis = new ByteArrayInputStream(in);
    ObjectInputStream ois;
    try {
        ois = new ObjectInputStream(bis);
        this.hash = (byte[]) ois.readObject();
        this.ocsp = (byte[]) ois.readObject();
        this.calendar = (Calendar) ois.readObject();
        setCertificateChain((Certificate[]) ois.readObject());
        ois.close();
    } catch (Exception e) {
        Logger.toConsole(e);
    }
}

From source file:com.github.kutschkem.Qgen.QuestionRankerByParseProbability.java

/**
 * Load the parser from the given location within the classpath.
 * /*from w ww .j  a v a  2s .  c om*/
 * @param aUrl
 *            URL of the parser file.
 */
// copied from DKPro's StanfordParser
private LexicalizedParser getParserDataFromSerializedFile(URL aUrl) throws IOException {
    ObjectInputStream in;
    InputStream is = null;
    try {
        is = aUrl.openStream();

        if (aUrl.toString().endsWith(".gz")) {
            // it's faster to do the buffering _outside_ the gzipping as
            // here
            in = new ObjectInputStream(new BufferedInputStream(new GZIPInputStream(is)));
        } else {
            in = new ObjectInputStream(new BufferedInputStream(is));
        }
        LexicalizedParser pd = LexicalizedParser.loadModel(in);
        // Numberer.setNumberers(pd.numbs); // will happen later in
        // makeParsers()
        in.close();
        return pd;
    } finally {
        closeQuietly(is);
    }
}

From source file:cn.scujcc.bug.bitcoinplatformandroid.fragment.BuyAndSellFragment.java

public List<String> readOrdersFromCache() {

    try {/*from  w ww  . j  av a2  s .c  o  m*/
        FileInputStream fin = getActivity().openFileInput("orders");
        ObjectInputStream in = new ObjectInputStream(fin);
        List<String> list = (List<String>) in.readObject();
        in.close();

        return list;
    } catch (Exception e) {
        return new ArrayList<String>();

    }
}

From source file:com.activecq.experiments.redis.impl.RedisSessionUtilImpl.java

protected Object deserialize(final byte[] bytes) throws IOException, ClassNotFoundException {
    if (bytes == null) {
        return null;
    }//from   w ww . j a v  a  2  s .co  m

    ByteArrayInputStream in = new ByteArrayInputStream(bytes);
    ObjectInputStream is = new ObjectInputStream(in);
    try {
        return is.readObject();
    } finally {
        in.close();
        is.close();
    }
}

From source file:cai.flow.packets.V5_Packet.java

/**
 * UDPflowsVector//  w ww  .  ja  v a2  s .c  o  m
 *
 * @param RouterIP
 * @param buf
 * @param len
 * @throws DoneException
 */
@SuppressWarnings("unchecked")
public V5_Packet(String RouterIP, byte[] buf, int len) throws DoneException {
    if (false) {//(Params.DEBUG) {
        // 
        File tmpFile = new File(Params.path + File.separator + "cache.tmp");
        if (tmpFile.exists()) {
            try {
                ObjectInputStream fIn = new ObjectInputStream(new FileInputStream(tmpFile));
                try {
                    buf = (byte[]) fIn.readObject();
                    len = ((Integer) fIn.readObject()).intValue();
                } catch (ClassNotFoundException e) {
                    e.printStackTrace();
                }
                fIn.close();
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }
        } else {
            try {
                ObjectOutputStream fOut;
                fOut = new ObjectOutputStream(new FileOutputStream(tmpFile));
                fOut.writeObject(buf);
                fOut.writeObject(new Integer(len));
                fOut.flush();
                fOut.close();
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            } catch (IOException e1) {
                e1.printStackTrace();
            }
        }
        // 
    }
    if (len < V5_Header_Size)
        throw new DoneException("    * incomplete header *");

    this.RouterIP = RouterIP;
    count = Util.to_number(buf, 2, 2);

    if (count <= 0 || len != V5_Header_Size + count * V5_Flow_Size)
        throw new DoneException("    * corrupted packet " + len + "/" + count + "/"
                + (V5_Header_Size + count * V5_Flow_Size) + " *");

    SysUptime = Util.to_number(buf, 4, 4);
    unix_secs = Util.to_number(buf, 8, 4);
    unix_nsecs = Util.to_number(buf, 12, 4);
    flow_sequence = Util.to_number(buf, 16, 4);
    engine_type = buf[20];
    engine_id = buf[21];

    logger.debug("    uptime: " + Util.uptime(SysUptime / 1000) + ", date: " + unix_secs + "." + unix_nsecs);
    logger.debug("    sequence: " + flow_sequence + ", count: " + count + ", engine: " + engine_type + "/"
            + engine_id);

    flows = new Vector((int) count);

    for (int i = 0, p = V5_Header_Size; i < count; i++, p += V5_Flow_Size) {
        V5_Flow f;
        try {
            f = new V5_Flow(RouterIP, buf, p);
            if (Params.DEBUG) {
                if (!f.equals(
                        new V5_Flow(RouterIP, buf, p, TemplateManager.getTemplateManager().getV5Template()))) {
                    logger.error("ERROR: Data inconsistency with different algorithm");
                }
            }
            if (f.srcaddr != null && f.dstaddr != null) {
                flows.add(f);
            } else {
                if (Params.DEBUG) {
                    logger.error(f.srcaddr + "  " + f.dstaddr + "    ");
                }
            }
        } catch (DoneException e) {
            if (Params.DEBUG) {
                logger.debug("", e);
            }
            if (e.getMessage() != null && (!e.getMessage().equals(""))) {
                logger.debug("", e);
            }
        }
    }
}

From source file:com.mongodb.hadoop.mapred.input.MongoInputSplit.java

public void readFields(DataInput in) throws IOException {
    final ObjectInputStream objIn = new ObjectInputStream((InputStream) in);

    _mongoURI = new MongoURI(in.readUTF());
    _querySpec = (DBObject) JSON.parse(in.readUTF());
    _fieldSpec = (DBObject) JSON.parse(in.readUTF());
    _sortSpec = (DBObject) JSON.parse(in.readUTF());
    _limit = in.readInt();//from ww w .j  a v  a  2  s .  c  o m
    _skip = in.readInt();

    log.info("Deserialized MongoInputSplit ... { length = " + getLength() + ", locations = "
            + java.util.Arrays.toString(getLocations()) + ", query = " + _querySpec + ", fields = " + _fieldSpec
            + ", sort = " + _sortSpec + ", limit = " + _limit + ", skip = " + _skip + "}");

    objIn.close();
}

From source file:com.izforge.izpack.event.AntActionUninstallerListener.java

private String getBuildResource() {
    String buildResource = null;/*from   w  w w  .ja v  a 2s  .c  o  m*/
    try {
        // See if we have an embedded build_resource.  If so, it will be stored
        //  under the /build_resource stream
        InputStream is = getClass().getResourceAsStream("/build_resource");
        if (is != null) {
            // There is an embedded build_resource.  The stream will contain a byte array
            //  of the contents of the embedded build_resouce.
            ObjectInputStream ois = new ObjectInputStream(is);
            byte[] content = (byte[]) ois.readObject();
            if (null != content) {
                // Save it to a temporary file
                ByteArrayInputStream bin = new ByteArrayInputStream(content);
                File buildFile = File.createTempFile("izpack_io", "xml");
                buildFile.deleteOnExit();
                IOUtils.copy(is, new FileOutputStream(buildFile));
                buildResource = buildFile.getAbsolutePath();
            }
            ois.close();
            is.close();
        }
    } catch (Exception exception) {
        throw new IzPackException(exception);
    }
    return buildResource;
}

From source file:com.gs.jrpip.client.FastServletProxyInvocationHandler.java

protected Object getResult(Method method, Object[] args, InputStream is)
        throws IOException, ClassNotFoundException {
    FixedInflaterInputStream zipped = new FixedInflaterInputStream(is);
    ObjectInputStream in = null;
    try {//from  w  ww .  jav a  2 s  .  c o m
        in = new ObjectInputStream(zipped);
        //if (CAUSE_RANDOM_ERROR) if (Math.random() > ERROR_RATE) throw new IOException("Random error, for testing only!");
        return in.readObject();
    } finally {
        zipped.finish(); // deallocate memory

        if (in != null) {
            try {
                in.close();
            } catch (IOException e) {
                LOGGER.debug("Could not close stream. See previous exception for cause", e);
            }
        }
    }
}

From source file:finale.year.stage.utility.Util.java

public static void rememberLogin() {
    ObjectInputStream reader = null;
    userFile = new File("config.txt");
    //User already has a file on the System with Credentials
    //Check for Existance of config.txt
    try {/* w w w  .  jav a2  s .  c  o m*/
        //Open File
        reader = new ObjectInputStream(new FileInputStream(userFile));
        String email_Object = (String) reader.readObject();
        String passw_Object = (String) reader.readObject();
        if (!email_Object.equals("")) {
            //Login in Directly
            System.out.println("email :" + email_Object);
            try {
                Authentification.handleResponse(login(email_Object, passw_Object));
            } catch (Exception e) {
                Authentification.updateStatus("No Internet : Server Connnection failed " + e.getMessage());
            }
        } else {
            openLogin();
        }

    } catch (FileNotFoundException ex) {
        //Call AUthentification

        System.out.println("Config.txt Missing");
        openLogin();
        return;
    } catch (IOException ex) {

    } catch (ClassNotFoundException ex) {

    } finally {
        if (reader != null) {
            try {
                reader.close(); //Close the Reader
            } catch (IOException ex) {
                ex.printStackTrace();
            }
        }
    }
}