Example usage for java.io FileOutputStream toString

List of usage examples for java.io FileOutputStream toString

Introduction

In this page you can find the example usage for java.io FileOutputStream toString.

Prototype

public String toString() 

Source Link

Document

Returns a string representation of the object.

Usage

From source file:Main.java

public static void putImageInCache(File file, Bitmap bmp) {
    try {//  ww  w  .  j a v  a  2s  .  co  m
        file.createNewFile();
        FileOutputStream out = new FileOutputStream(file);
        bmp.compress(Bitmap.CompressFormat.PNG, 80, out);
        Log.d("CACHE", "FILE : " + out.toString());
        out.flush();
        out.close();
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:org.eclipse.jubula.client.archive.XmlStorage.java

/**
 * Save a project as XML to a file or return the serialized project as
 * string, if fileName == null!/*from ww  w.  ja  v a  2s .  co  m*/
 * 
 * @param proj
 *            proj to be saved
 * @param fileName
 *            name for file to save or null, if wanting to get the project
 *            as serialized string
 * @param includeTestResultSummaries
 *            Whether to save the Test Result Summaries as well.
 * @param monitor
 *            The progress monitor for this potentially long-running
 *            operation.
 * @param writeToSystemTempDir
 *            Indicates whether the project has to be written to the system
 *            temp directory
 * @param listOfProjectFiles
 *            If a project is written into the temp dir then the written
 *            file is added to the list, if the list is not null.
 * @return the serialized project as string, if fileName == null<br>
 *         or<br>
 *         <b>Returns:</b><br>
 *         null otherwise. Always returns <code>null</code> if the save
 *         operation was canceled.
 * @throws PMException
 *             if save failed for any reason
 * @throws ProjectDeletedException
 *             in case of current project is already deleted
 */
public static String save(IProjectPO proj, String fileName, boolean includeTestResultSummaries,
        IProgressMonitor monitor, boolean writeToSystemTempDir, List<File> listOfProjectFiles)
        throws ProjectDeletedException, PMException {

    monitor.beginTask(Messages.XmlStorageSavingProject, getWorkToSave(proj));

    Validate.notNull(proj);
    FileOutputStream fOut = null;
    try {
        String xml = buildXmlHeader() + XmlStorage.save(proj, includeTestResultSummaries, monitor);

        if (fileName == null) {
            return xml;
        }

        if (writeToSystemTempDir) {
            File fileInTempDir = createTempFile(fileName);
            if (listOfProjectFiles != null) {
                listOfProjectFiles.add(fileInTempDir);
            }
            fOut = new FileOutputStream(fileInTempDir);
        } else {
            fOut = new FileOutputStream(fileName);
        }

        IOCanceller canceller = new IOCanceller(monitor, fOut);
        canceller.startTask();
        fOut.write(xml.getBytes(RECOMMENDED_CHAR_ENCODING));
        canceller.taskFinished();
    } catch (FileNotFoundException e) {
        log.debug(Messages.File + StringConstants.SPACE + Messages.NotFound, e);
        throw new PMSaveException(Messages.File + StringConstants.SPACE + fileName + Messages.NotFound
                + StringConstants.COLON + StringConstants.SPACE + e.toString(), MessageIDs.E_FILE_IO);
    } catch (IOException e) {
        // If the operation has been canceled, then this is just
        // a result of cancelling the IO.
        if (!monitor.isCanceled()) {
            log.debug(Messages.GeneralIoExeption, e);
            throw new PMSaveException(Messages.GeneralIoExeption + e.toString(), MessageIDs.E_FILE_IO);
        }
    } catch (PersistenceException e) {
        log.debug(Messages.CouldNotInitializeProxy + StringConstants.DOT, e);
        throw new PMSaveException(e.getMessage(), MessageIDs.E_DATABASE_GENERAL);
    } finally {
        if (fOut != null) {
            try {
                fOut.close();
            } catch (IOException e) {
                // just log, we are already done
                log.error(Messages.CantCloseOOS + fOut.toString(), e);
            }
        }
    }
    return null;
}