Example usage for java.io ObjectOutputStream close

List of usage examples for java.io ObjectOutputStream close

Introduction

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

Prototype

public void close() throws IOException 

Source Link

Document

Closes the stream.

Usage

From source file:com.radicaldynamic.groupinform.services.InformOnlineService.java

private void serializeSession() {
    // Attempt to serialize the session for later use
    if (Collect.getInstance().getInformOnlineState().getSession() instanceof CookieStore) {
        if (Collect.Log.DEBUG)
            Log.d(Collect.LOGTAG, t + "serializing session");

        try {/*w  w  w. j av  a  2  s. c om*/
            InformOnlineSession session = new InformOnlineSession();

            Iterator<Cookie> cookies = Collect.getInstance().getInformOnlineState().getSession().getCookies()
                    .iterator();

            while (cookies.hasNext()) {
                Cookie c = cookies.next();
                session.getCookies().add(new InformOnlineSession(c.getDomain(), c.getExpiryDate(), c.getName(),
                        c.getPath(), c.getValue(), c.getVersion()));
            }

            FileOutputStream fos = new FileOutputStream(
                    new File(getCacheDir(), FileUtilsExtended.SESSION_CACHE_FILE));
            ObjectOutputStream out = new ObjectOutputStream(fos);
            out.writeObject(session);
            out.close();
            fos.close();
        } catch (Exception e) {
            if (Collect.Log.WARN)
                Log.w(Collect.LOGTAG, t + "problem serializing session " + e.toString());
            e.printStackTrace();

            // Make sure that we don't leave a broken file hanging
            new File(getCacheDir(), FileUtilsExtended.SESSION_CACHE_FILE).delete();
        }
    } else {
        if (Collect.Log.DEBUG)
            Log.d(Collect.LOGTAG, t + "no session to serialize");
    }
}

From source file:com.moisespsena.vraptor.javaobjectserialization.JavaObjectSerializerBuilder.java

@Override
public void serialize() {
    ObjectOutputStream out = null;

    try {//from w w w.ja va2s  .com
        if (outputStream instanceof ObjectOutputStream) {
            out = (ObjectOutputStream) outputStream;
        } else {
            out = new ObjectOutputStream(outputStream);
        }

        out.writeObject(source);
        out.flush();
    } catch (final IOException e) {
        throw new SerializationException(e);
    } finally {
        if (out != null) {
            try {
                out.close();
            } catch (final IOException e) {
                throw new SerializationException(e);
            }
        }
    }
}

From source file:com.vkassin.mtrade.Common.java

public static void saveAccountDetails() {

    FileOutputStream fos;//w  ww .  ja v a  2 s  .com
    try {

        fos = app_ctx.openFileOutput(ACCOUNT_FNAME, Context.MODE_PRIVATE);
        ObjectOutputStream os = new ObjectOutputStream(fos);
        os.writeObject(myaccount);
        os.close();
        fos.close();
        Log.i(TAG, "saved username: " + myaccount.get("name") + " password: " + myaccount.get("password")
                + " keypassword: " + myaccount.get("keypassword"));
    } catch (FileNotFoundException e) {

        Toast.makeText(app_ctx, "  ? " + e.toString(), Toast.LENGTH_SHORT).show();
        e.printStackTrace();
    } catch (IOException e) {

        Toast.makeText(app_ctx, "  ?: " + e.toString(), Toast.LENGTH_SHORT).show();
        e.printStackTrace();
    }

}

From source file:com.vkassin.mtrade.Common.java

public static void saveFavrList() {

    Log.i(TAG, "saveFavrList()");
    FileOutputStream fos;// www.  jav  a2s .  c o  m
    try {

        fos = app_ctx.openFileOutput(FLIST_FNAME, Context.MODE_PRIVATE);
        ObjectOutputStream os = new ObjectOutputStream(fos);
        os.writeObject(favrList);
        os.close();
        fos.close();

    } catch (FileNotFoundException e) {

        Toast.makeText(app_ctx, "  ? " + e.toString(), Toast.LENGTH_SHORT).show();
        e.printStackTrace();
    } catch (IOException e) {

        Toast.makeText(app_ctx, "  ?: " + e.toString(), Toast.LENGTH_SHORT).show();
        e.printStackTrace();
    }

    // Toast.makeText(app_ctx, " ?? ?",
    // Toast.LENGTH_SHORT).show();

}

From source file:calendarioSeries.vistas.MainViewController.java

private void rellenarArchivo() {
    try {/*from w w w .java 2s.c  o m*/
        File file = new File("seriesUsuario.json");
        PrintWriter pw = new PrintWriter(file);
        JSONObject array = new JSONObject();
        int count = 0;
        for (Serie serie : series) {
            JSONArray auxi = new JSONArray();
            auxi.put(0, serie.getTitulo());
            auxi.put(1, serie.getLastVisto());
            array.put(serie.getId(), auxi);
        }
        pw.println(array.toString());
        pw.flush();

        File fileSeries = new File("data.db");
        FileOutputStream fos = new FileOutputStream(fileSeries);
        ObjectOutputStream oos;
        try {
            oos = new ObjectOutputStream(fos);
            oos.writeObject(series);
            oos.flush();
            oos.close();
        } catch (IOException ex) {
            ex.printStackTrace();
        }
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    }
}

From source file:com.vkassin.mtrade.Common.java

public static void saveArcDeals() {

    Log.i(TAG, "saveArcDeals()");
    FileOutputStream fos;/*from w w w  . j  av  a2 s .com*/
    try {

        fos = app_ctx.openFileOutput(ARCDEAL_FNAME, Context.MODE_PRIVATE);
        ObjectOutputStream os = new ObjectOutputStream(fos);
        os.writeObject(arcdealMap);
        os.close();
        fos.close();

    } catch (FileNotFoundException e) {

        Toast.makeText(app_ctx, "  ?  ? " + e.toString(),
                Toast.LENGTH_SHORT).show();
        e.printStackTrace();
    } catch (IOException e) {

        Toast.makeText(app_ctx, "  ?  ?: " + e.toString(),
                Toast.LENGTH_SHORT).show();
        e.printStackTrace();
    }

}

From source file:com.zetcheck.SlidingStationActivity.java

License:asdf

private void setGlobalDisplay() {
    ID = getIntent().getExtras().getInt(AppData.EXTRA_MESSAGE_STATION);
    station = AppData.stations.Map.get(AppData.stations.Keys.get(AppData.stations.idToSearch.indexOf(ID)));

    findViewById(R.id.station_thumbnail).setBackgroundColor(AppData.getStationTypeColor(station.IsTram));
    ((TextView) findViewById(R.id.station_type)).setText(AppData.getStationTypeName(station.IsTram));
    ((TextView) findViewById(R.id.station_name)).setText(station.Name);
    findViewById(R.id.station_pager_title_strip)
            .setBackgroundColor(AppData.getStationTypeColor(!station.IsTram));
    refreshTextView = ((TextView) findViewById(R.id.station_refresh_info));
    favoritesStar = (ImageView) findViewById(R.id.station_star);

    if (AppData.settingsData.favoriteIds.contains(ID)) {
        isFavorite = true;//from  w w  w  .ja  v  a  2  s. c o m
        favoritesStar.setBackgroundResource(android.R.drawable.star_big_on);
    } else {
        isFavorite = false;
        favoritesStar.setBackgroundResource(android.R.drawable.star_big_off);
    }

    favoritesStar.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            try {
                if (isFavorite) {
                    favoritesStar.setBackgroundResource(android.R.drawable.star_big_off);
                    AppData.settingsData.favoriteIds.remove((Object) ID);
                } else {
                    favoritesStar.setBackgroundResource(android.R.drawable.star_big_on);
                    AppData.settingsData.favoriteIds.add(ID);
                }
                isFavorite = !isFavorite;
                FileOutputStream fos = getApplicationContext()
                        .openFileOutput(MainActivity.SETTINGS_DATA_FILE_NAME, Context.MODE_PRIVATE);
                ObjectOutputStream os = new ObjectOutputStream(fos);
                os.writeObject(AppData.settingsData);
                os.close();
            } catch (Exception e) {

            }

        }
    });
}

From source file:io.hops.experiments.controller.Master.java

private void generateResultsFile() throws FileNotFoundException, IOException {

    String filePath = config.getResultsDir();
    if (!filePath.endsWith("/")) {
        filePath += "/";
    }//w w  w  .ja  v  a  2  s.com
    filePath += ConfigKeys.BINARY_RESULT_FILE_NAME;
    printMasterLogMessages("Writing results to " + filePath);
    FileOutputStream fout = new FileOutputStream(filePath);
    ObjectOutputStream oos = new ObjectOutputStream(fout);
    for (BMResult result : results) {
        oos.writeObject(result);
    }
    oos.close();

    filePath = config.getResultsDir();
    if (!filePath.endsWith("/")) {
        filePath += "/";
    }
    filePath += ConfigKeys.TEXT_RESULT_FILE_NAME;
    printMasterLogMessages("Writing results to " + filePath);
    FileWriter out = new FileWriter(filePath, false);
    for (BMResult result : results) {
        out.write(result.toString() + "\n");
    }
    out.close();
}

From source file:com.baidu.terminator.storage.file.FileStorage.java

@Override
public synchronized void putRecordData(String key, RequestResponseBundle bundles) {
    int linkId = this.link.getId();
    File dataFile = new File(filePath);

    Date addtime = new Date();
    Long offset = dataFile.length();

    // write to file
    FileOutputStream fos = null;//from  w ww .j ava2  s  . c  o m
    ObjectOutputStream oos = null;
    try {
        fos = new FileOutputStream(dataFile, true);
        oos = new ObjectOutputStream(fos);
        oos.writeObject(bundles);
    } catch (IOException e) {
        logger.error("[PUT] data record storage in file fail!", e);
    } finally {
        try {
            if (oos != null) {
                oos.close();
            }
            if (fos != null) {
                fos.close();
            }
        } catch (IOException e) {
            logger.error("[PUT]   close file output stream error!", e);
        }
    }

    // write record offset to database
    DataIndex dataIndex = new DataIndex();
    dataIndex.setLinkId(linkId);
    dataIndex.setOffset(offset);
    dataIndex.setSignature((String) key);
    dataIndex.setAddTime(addtime);
    dataIndexMapper.insertDataIndex(dataIndex);
    logger.info("[PUT] data record storage in file success!");
}