Example usage for java.io IOException getLocalizedMessage

List of usage examples for java.io IOException getLocalizedMessage

Introduction

In this page you can find the example usage for java.io IOException getLocalizedMessage.

Prototype

public String getLocalizedMessage() 

Source Link

Document

Creates a localized description of this throwable.

Usage

From source file:net.sf.logsaw.index.internal.LuceneIndexServiceImpl.java

private Date getLatestEntryDate(ILogResource log) throws CoreException {
    if (!hasDateComponent(log)) {
        return null;
    }/*from  w w  w  . j  a  v a 2  s  . c  om*/

    ARunWithIndexReader<Date> runnable = new ARunWithIndexReader<Date>() {

        /* (non-Javadoc)
         * @see net.sf.logsaw.index.impl.ARunWithIndexReader#doRunWithIndexReader(org.apache.lucene.index.IndexReader, net.sf.logsaw.core.framework.ILogResource)
         */
        @Override
        protected Date doRunWithIndexReader(IndexReader reader, ILogResource log) throws CoreException {
            if (reader == null) {
                // Index does not exist yet
                return null;
            }
            int i = reader.maxDoc();
            if (i > 0) {
                try {
                    Document doc = reader.document(i - 1);
                    String val = doc.get(log.getDialect().getFieldProvider().getTimestampField().getKey());
                    return log.getDialect().getFieldProvider().getTimestampField().fromIndexedValue(val);
                } catch (IOException e) {
                    // Unexpected exception; wrap with CoreException
                    throw new CoreException(new Status(IStatus.ERROR, IndexPlugin.PLUGIN_ID,
                            NLS.bind(Messages.LuceneIndexService_error_failedToReadIndex,
                                    new Object[] { log.getName(), e.getLocalizedMessage() }),
                            e));
                }
            }
            return null;
        }
    };
    return runnable.runWithIndexReader(log);
}

From source file:com.tc.config.schema.setup.StandardXMLFileConfigurationCreator.java

private InputStream trySource(ConfigurationSource[] remainingSources, int i) {
    InputStream out = null;/* w w  w . j a  v  a  2 s  .  c  o  m*/
    InputStream copyIn = null;
    try {
        ByteArrayOutputStream dataCopy = new ByteArrayOutputStream();
        logger.info("Attempting to load configuration from the " + remainingSources[i] + "...");
        out = remainingSources[i].getInputStream(GET_CONFIGURATION_ONE_SOURCE_TIMEOUT);
        try {
            IOUtils.copy(out, dataCopy);
            copyIn = new ByteArrayInputStream(dataCopy.toByteArray());
        } finally {
            out.close();
        }
        directoryLoadedFrom = remainingSources[i].directoryLoadedFrom();
    } catch (ConfigurationSetupException cse) {
        String text = "We couldn't load configuration data from the " + remainingSources[i];
        text += "; this error is permanent, so this source will not be retried.";

        if (remainingSources.length > 1)
            text += " Skipping this source and going to the next one.";

        text += " (Error: " + cse.getLocalizedMessage() + ".)";

        consoleLogger.warn(text);

        remainingSources[i] = null;
    } catch (IOException ioe) {
        String text = "We couldn't load configuration data from the " + remainingSources[i];

        if (remainingSources.length > 1) {
            text += "; this error is temporary, so this source will be retried later if configuration can't be loaded elsewhere. ";
            text += "Skipping this source and going to the next one.";
        } else {
            text += "; retrying.";
        }

        text += " (Error: " + ioe.getLocalizedMessage() + ".)";
        consoleLogger.warn(text);
    }
    return copyIn;
}

From source file:org.killbill.billing.client.KillBillHttpClient.java

private <T> T unmarshalResponse(final Response response, final Class<T> clazz) throws KillBillClientException {
    final T result;
    try {/*w  w  w.  j  a v a 2s.  c  o  m*/
        if (DEBUG) {
            final String content = response.getResponseBody();
            log.debug("Received: " + content);
            result = mapper.readValue(content, clazz);
        } else {
            InputStream in = null;
            try {
                in = response.getResponseBodyAsStream();
                result = mapper.readValue(in, clazz);
            } finally {
                if (in != null) {
                    try {
                        in.close();
                    } catch (final IOException e) {
                        log.warn("Failed to close http-client - provided InputStream: {}",
                                e.getLocalizedMessage());
                    }
                }
            }
        }
    } catch (final IOException e) {
        throw new KillBillClientException(e, response);
    }
    return result;
}

From source file:com.microsoft.tfs.core.clients.versioncontrol.engines.internal.workers.GetDownloadWorker.java

/**
 * Download the file for {@link #operation}. If {@link #baselineFolders} and
 * {@link #baselineFileGUID} are non-<code>null</code>, updates the baseline
 * files for the workspace.//from   ww w  . j  a v a 2s .  c  om
 *
 * @param targetSymLink
 *        if not <code>null</code>, the method sets <code>true</code> if the
 *        user wants the target to be a symbolic link, <code>false</code> if
 *        it is a normal file
 * @param targetSymLinkDestinationUnmapped
 *        if not <code>null</code>, the method sets <code>true</code> on
 *        this holder if the target was supposed to be a symbolic link but
 *        was not created because the destination was not mapped, sets
 *        <code>false</code> if it was a successful symbolc link or a normal
 *        (non-link) target item
 * @throws {@link
 *         CanceledException} if the {@link TaskMonitor} was canceled during
 *         execution. This method tries its best to delete partial or
 *         temporary files before throwing this exception.
 * @throws VersionControlException
 *         if the download failed (local file access issue, network issue,
 *         etc.)
 */
protected void downloadFile(final AtomicBoolean targetSymLink,
        final AtomicBoolean targetSymLinkDestinationUnmapped) throws CanceledException {
    int readLockToken = BaselineFolderCollection.UNINITIALIZED_READ_LOCK_TOKEN;
    final boolean updateBaseline = baselineFolders != null && baselineFileGUID != null;

    File baselineTempFile = null;
    File workingFolderTempFile = null;

    final List<DownloadOutput> outputs = new ArrayList<DownloadOutput>(2);

    try {
        /*
         * This method differs from the VS code because of our different
         * download implementation in VersionControlClient. If using a local
         * workspace, TEE downloads the baseline and working folder files at
         * the same time (baseline file stays gzip if the server gave us
         * that, working folder file always uncompressed).
         */

        // Configure the baseline output (if needed)
        BaselineFileDownloadOutput baselineOutput = null;
        if (updateBaseline) {
            // Lock the baseline folder collection from change until this
            // file download is finished.
            readLockToken = baselineFolders.lockForRead();

            // Gets the name, but doesn't create anything on disk
            final String baselineFileNoSuffix = baselineFolders.getNewBaselineLocation(baselineFileGUID,
                    operation.getTargetLocalItem(), readLockToken);

            // Never gunzip this one
            baselineOutput = new BaselineFileDownloadOutput(new File(baselineFileNoSuffix), false);
            outputs.add(baselineOutput);
        }

        // Configure the working folder file output (in a block for
        // aesthetics)
        FileDownloadOutput workingFolderOutput = null;
        if (true) {
            final File targetLocalItemDirectory = new File(operation.getTargetLocalItem()).getParentFile();

            // Make sure a file isn't taking our dir name
            if (targetLocalItemDirectory.exists() && !targetLocalItemDirectory.isDirectory()) {
                throw new VersionControlException(MessageFormat.format(
                        //@formatter:off
                        Messages.getString(
                                "GetEngineDownloadWorker.CannotCreateDirectoryBecauseFileAlreadyExistsFormat"), //$NON-NLS-1$
                        //@formatter:on
                        targetLocalItemDirectory));
            }

            if (!targetLocalItemDirectory.exists()) {
                if (!targetLocalItemDirectory.mkdirs()) {
                    // We can use the same generic message as above if
                    // mkdirs
                    // fails because Java doesn't give us many details
                    if (!targetLocalItemDirectory.isDirectory()) {
                        throw new VersionControlException(MessageFormat.format(
                                //@formatter:off
                                Messages.getString(
                                        "GetEngineDownloadWorker.CannotCreateDirectoryBecauseFileAlreadyExistsFormat"), //$NON-NLS-1$
                                //@formatter:on
                                targetLocalItemDirectory));
                    }
                }
            }

            try {
                workingFolderTempFile = File.createTempFile("teamexplorer", ".tmp", targetLocalItemDirectory); //$NON-NLS-1$ //$NON-NLS-2$
                log.trace(MessageFormat.format("Using temp file {0} for download", workingFolderTempFile)); //$NON-NLS-1$
            } catch (final IOException e) {
                throw new VersionControlException(MessageFormat.format(
                        Messages.getString(
                                "GetEngineDownloadWorker.CouldNotCreateTemporaryFileInDirectoryFormat"), //$NON-NLS-1$
                        targetLocalItemDirectory, e.getLocalizedMessage()), e);
            }

            // Always gunzip this one
            workingFolderOutput = new FileDownloadOutput(workingFolderTempFile, true);
            outputs.add(workingFolderOutput);
        }

        getClient().downloadFileToStreams(operation.createDownloadSpec(),
                outputs.toArray(new DownloadOutput[outputs.size()]), getEventSource(), getCancelMonitor());

        /*
         * Pull the baseline's actual file from the output. We only know
         * this after a download because the file extension depends on the
         * MIME type the server returned.
         */
        if (baselineOutput != null) {
            // If BaselineFolderCollection gave us a temp file, make sure it
            // gets cleaned up in this method.
            if (baselineOutput.isTempFileCreatedInsteadOfBaseline()) {
                baselineTempFile = baselineOutput.getOutputStreamFile();
            } else {
                // Real baseline file; no temp cleanup
                baselineTempFile = null;
            }
        }

        // Close the outputs so we can use them.
        closeDownloadOutputStreamsSafely(outputs);

        // Renames the temp file to the operation's target local item.
        moveTempFileToTargetFile(workingFolderTempFile, targetSymLink, targetSymLinkDestinationUnmapped);

        // After rename there's no working folder temp file to clean up
        workingFolderTempFile = null;
    } catch (final CanceledException e) {
        // The finally block closes streams, deletes temps
        throw e;
    } finally {
        if (updateBaseline) {
            if (readLockToken != BaselineFolderCollection.UNINITIALIZED_READ_LOCK_TOKEN) {
                baselineFolders.unlockForRead(readLockToken);
            }
        }

        closeDownloadOutputStreamsSafely(outputs);

        if (baselineTempFile != null) {
            baselineTempFile.delete();
        }

        if (workingFolderTempFile != null) {
            workingFolderTempFile.delete();
        }
    }
}

From source file:nf.frex.android.FrexActivity.java

private boolean writeFrexDoc(File paramFile) {
    try {//  w  w w.  j av a2  s .com
        FileOutputStream stream = new FileOutputStream(paramFile);
        try {
            writeFrexDoc(stream);
        } finally {
            stream.close();
        }
        return true;
    } catch (IOException e) {
        Toast.makeText(this, getString(R.string.error_msg, e.getLocalizedMessage()), Toast.LENGTH_SHORT).show();
        return false;
    }
}

From source file:nf.frex.android.FrexActivity.java

private boolean writeFrexImage(File imageFile) {
    try {//  www  .  j  a  v  a2  s  .  c  o m
        FileOutputStream out = new FileOutputStream(imageFile);
        try {
            view.captureBitmap().compress(FrexIO.IMAGE_FILE_FORMAT, 100, out);
        } finally {
            out.close();
        }
        return true;
    } catch (IOException e) {
        Toast.makeText(this, getString(R.string.error_msg, e.getLocalizedMessage()), Toast.LENGTH_SHORT).show();
        return false;
    }
}

From source file:br.com.nordestefomento.jrimum.bopepo.view.ViewerPDF.java

/**
 * @throws JRimumException//  ww  w  .j a v  a2s.c  om
 * 
 * @return
 */
protected ByteArrayOutputStream getStream() {

    ByteArrayOutputStream baos = null;

    try {

        processarPdf();

        baos = FileUtil.bytes2Stream(outputStream.toByteArray());

    } catch (IOException e) {

        log.error("Erro durante a criao do stream. " + e.getLocalizedMessage(), e);
        throw new JRimumException(
                "Erro durante a criao do stream. " + "Causado por " + e.getLocalizedMessage(), e);

    } catch (DocumentException e) {

        log.error("Erro durante a criao do stream. " + e.getLocalizedMessage(), e);
        throw new JRimumException(
                "Erro durante a criao do stream. " + "Causado por " + e.getLocalizedMessage(), e);
    }

    return baos;
}

From source file:br.com.nordestefomento.jrimum.bopepo.view.ViewerPDF.java

/**
 * @throws JRimumException//from  ww w . j a  v a2  s .  co m
 * 
 * @return
 */
protected byte[] getBytes() {

    byte[] bytes = null;

    try {

        processarPdf();

        bytes = outputStream.toByteArray();

    } catch (IOException e) {

        log.error("Erro durante a criao do stream. " + e.getLocalizedMessage(), e);
        throw new JRimumException(
                "Erro durante a criao do stream. " + "Causado por " + e.getLocalizedMessage(), e);

    } catch (DocumentException e) {

        log.error("Erro durante a criao do stream. " + e.getLocalizedMessage(), e);
        throw new JRimumException(
                "Erro durante a criao do stream. " + "Causado por " + e.getLocalizedMessage(), e);
    }

    return bytes;
}

From source file:com.adobe.phonegap.contentsync.Sync.java

private File createDownloadFileLocation(final String id) {
    File file = null;/*ww w  . jav  a  2s . c  o  m*/
    try {
        String tempId = (id.lastIndexOf("/") > -1) ? id.substring(id.lastIndexOf("/") + 1, id.length()) : id;
        file = File.createTempFile(("cdv_" + tempId), ".tmp", cordova.getActivity().getCacheDir());
    } catch (IOException e1) {
        Log.e(LOG_TAG, e1.getLocalizedMessage(), e1);
    }
    return file;
}

From source file:es.juntadeandalucia.panelGestion.presentacion.controlador.impl.GIController.java

public void getRAFile(Service service) {
    String errorMessage = null;/* w w w .j ava  2s.  c  o  m*/

    ServletOutputStream os = null;

    try {
        // configures the response
        String fileNameWithExtension = racontroller.getFileNameWithExtension(service);
        HttpServletResponse response = (HttpServletResponse) externalCtx.getResponse();
        response.setContentType("text/xml");
        response.addHeader("Content-disposition",
                "attachment; filename=\"".concat(fileNameWithExtension).concat("\""));

        // gets the configuration file
        InputStream is = racontroller.getConfigurationFile(service);

        os = response.getOutputStream();

        IOUtils.copy(is, os);

        os.flush();
        os.close();

        is.close();

        facesContext.responseComplete();
    } catch (IOException e) {
        errorMessage = "Error al comprimir los archivos de configuracin: " + e.getLocalizedMessage();
    } catch (Exception e) {
        errorMessage = "Error en la descarga de la configuracin: " + e.getLocalizedMessage();
    } finally {
        try {
            if (os != null) {
                os.flush();
                os.close();
            }
        } catch (IOException e) {
            errorMessage = "Error al comprimir los archivos de configuracin: " + e.getLocalizedMessage();
        }
    }

    if (errorMessage != null) {
        StatusMessages.instance().add(Severity.ERROR, errorMessage);
        log.error(errorMessage);
    }
}