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:com.epam.dlab.backendapi.core.commands.CommandExecutorMockAsync.java

/**
 * Write response file./*from   ww w  .  j  a v  a  2s . c  o m*/
 *
 * @param sourceFileName template file name.
 * @param targetFileName response file name.
 */
private void setResponse(String sourceFileName, String targetFileName) {
    String content;
    URL url = Resources.getResource(sourceFileName);
    try {
        content = Resources.toString(url, Charsets.UTF_8);
    } catch (IOException e) {
        throw new DlabException("Can't read resource " + sourceFileName + ": " + e.getLocalizedMessage(), e);
    }

    for (String key : parser.getVariables().keySet()) {
        String value = parser.getVariables().get(key);
        content = content.replace("${" + key.toUpperCase() + "}", value);
    }

    File fileResponse = new File(responseFileName);
    try (BufferedWriter out = new BufferedWriter(new FileWriter(fileResponse))) {
        Files.createParentDirs(fileResponse);
        out.write(content);
    } catch (IOException e) {
        throw new DlabException("Can't write response file " + targetFileName + ": " + e.getLocalizedMessage(),
                e);
    }
    log.debug("Create response file from {} to {}", sourceFileName, targetFileName);
}

From source file:net.sf.housekeeper.swing.ApplicationPresenter.java

/**
 * Displays this main frame.// www . j av  a2 s  .c  o  m
 */
public void show() {
    view.show();
    try {
        PersistenceController.instance().replaceDomainWithSaved(household);
    } catch (IOException e1) {
        //Nothing wrong about that
    } catch (UnsupportedFileVersionException e1) {
        LOG.error("Unsupported file format: " + e1.getVersion(), e1);
        view.showErrorDialog(e1.getLocalizedMessage());
    }
}

From source file:com.atlassian.jira.web.dispatcher.JiraWebworkActionDispatcher.java

/**
 * Wrap servlet request with the appropriate request. It will check to see if request is a multipart request and
 * wrap in appropriately./*  ww w  . j  av  a 2 s. c o  m*/
 *
 * @param httpServletRequest HttpServletRequest
 * @return wrapped request or original request
 */
private Pair<HttpServletRequest, HttpServletResponse> wrap(HttpServletRequest httpServletRequest,
        HttpServletResponse httpServletResponse) {
    // don't wrap more than once
    if (httpServletRequest instanceof MultiPartRequestWrapper) {
        return Pair.of(httpServletRequest, httpServletResponse);
    }
    //
    // SiteMesh turns itself on when it sees a content type of text/html which an earlier filter sets BUT
    // which SiteMesh misses because it runs later.  So we do a numpty set here.
    // This allows SiteMesh to kick in because until setContentType is called then SiteMesh wont play ball
    //
    httpServletResponse.setContentType(httpServletResponse.getContentType());

    final String disableMultipartGetString = multipartDisableGetString();
    boolean disableMultipartGet = Boolean.valueOf(disableMultipartGetString);

    if (needsMultipartWrapper(httpServletRequest, disableMultipartGet)) {
        try {
            httpServletRequest = new MultiPartRequestWrapper(httpServletRequest, saveDir, getMaxSize());
        } catch (IOException e) {
            httpServletRequest.setAttribute("webwork.action.ResultException",
                    new ResultException(Action.ERROR, e.getLocalizedMessage()));
        }
    }
    return Pair.of(httpServletRequest, httpServletResponse);
}

From source file:com.kylinolap.job.flow.JobFlowListener.java

/**
 * @param jobInstance/* w  w  w  .j  a  va  2s.  c  o  m*/
 */
protected void notifyUsers(JobInstance jobInstance, JobEngineConfig engineConfig) {
    KylinConfig config = engineConfig.getConfig();
    String cubeName = jobInstance.getRelatedCube();
    CubeInstance cubeInstance = CubeManager.getInstance(config).getCube(cubeName);
    String finalStatus = null;
    String content = JobConstants.NOTIFY_EMAIL_TEMPLATE;
    String logMsg = "";

    switch (jobInstance.getStatus()) {
    case FINISHED:
        finalStatus = "SUCCESS";
        break;
    case ERROR:
        for (JobStep step : jobInstance.getSteps()) {
            if (step.getStatus() == JobStepStatusEnum.ERROR) {
                try {
                    logMsg = JobDAO.getInstance(config).getJobOutput(step).getOutput();
                } catch (IOException e) {
                    log.error(e.getLocalizedMessage(), e);
                }
            }
        }
        finalStatus = "FAILED";
        break;
    case DISCARDED:
        finalStatus = "DISCARDED";
    default:
        break;
    }

    if (null == finalStatus) {
        return;
    }

    try {
        InetAddress inetAddress = InetAddress.getLocalHost();
        content = content.replaceAll("\\$\\{job_engine\\}", inetAddress.getCanonicalHostName());
    } catch (UnknownHostException e) {
        log.error(e.getLocalizedMessage(), e);
    }

    content = content.replaceAll("\\$\\{job_name\\}", jobInstance.getName());
    content = content.replaceAll("\\$\\{result\\}", finalStatus);
    content = content.replaceAll("\\$\\{cube_name\\}", cubeName);
    content = content.replaceAll("\\$\\{start_time\\}", new Date(jobInstance.getExecStartTime()).toString());
    content = content.replaceAll("\\$\\{duration\\}", jobInstance.getDuration() / 60 + "mins");
    content = content.replaceAll("\\$\\{mr_waiting\\}", jobInstance.getMrWaiting() / 60 + "mins");
    content = content.replaceAll("\\$\\{last_update_time\\}",
            new Date(jobInstance.getLastModified()).toString());
    content = content.replaceAll("\\$\\{error_log\\}", logMsg);

    MailService mailService = new MailService();
    try {
        List<String> users = new ArrayList<String>();

        if (null != cubeInstance.getDescriptor().getNotifyList()) {
            users.addAll(cubeInstance.getDescriptor().getNotifyList());
        }

        if (null != engineConfig.getAdminDls()) {
            String[] adminDls = engineConfig.getAdminDls().split(",");

            for (String adminDl : adminDls) {
                users.add(adminDl);
            }
        }

        if (users.size() > 0) {
            mailService.sendMail(users, "[Kylin Cube Build Job]-" + cubeName + "-" + finalStatus, content);
        }
    } catch (IOException e) {
        log.error(e.getLocalizedMessage(), e);
    }

}

From source file:org.zaizi.alfresco.publishing.marklogic.MarkLogicChannelType.java

@Override
public void publish(final NodeRef nodeToPublish, final Map<QName, Serializable> channelProperties) {
    LOG.info("publish() invoked...");
    final ContentReader reader = contentService.getReader(nodeToPublish, ContentModel.PROP_CONTENT);
    if (reader.exists()) {
        File contentFile;/*w  w  w  .j a v a2 s  .  c  o  m*/
        boolean deleteContentFileOnCompletion = false;
        if (FileContentReader.class.isAssignableFrom(reader.getClass())) {
            // Grab the content straight from the content store if we can...
            contentFile = ((FileContentReader) reader).getFile();
        } else {
            // ...otherwise copy it to a temp file and use the copy...
            final File tempDir = TempFileProvider.getLongLifeTempDir("marklogic");
            contentFile = TempFileProvider.createTempFile("marklogic", "", tempDir);
            reader.getContent(contentFile);
            deleteContentFileOnCompletion = true;
        }

        HttpClient httpclient = new DefaultHttpClient();
        try {
            final String mimeType = reader.getMimetype();
            if (LOG.isDebugEnabled()) {
                LOG.debug("Publishing node: " + nodeToPublish);
                LOG.debug("ContentFile_MIMETYPE: " + mimeType);
            }

            URI uriPut = publishingHelper.getPutURIFromNodeRefAndChannelProperties(nodeToPublish,
                    channelProperties);

            final HttpPut httpput = new HttpPut(uriPut);
            final FileEntity filenEntity = new FileEntity(contentFile, mimeType);
            httpput.setEntity(filenEntity);

            final HttpResponse response = httpclient.execute(httpput,
                    publishingHelper.getHttpContextFromChannelProperties(channelProperties));

            if (LOG.isDebugEnabled()) {
                LOG.debug("Response Status: " + response.getStatusLine().getStatusCode() + " - Message: "
                        + response.getStatusLine().getReasonPhrase() + " - NodeRef: "
                        + nodeToPublish.toString());
            }
            if (response.getStatusLine().getStatusCode() != STATUS_DOCUMENT_INSERTED) {
                throw new AlfrescoRuntimeException(response.getStatusLine().getReasonPhrase());
            }
        } catch (IllegalStateException illegalEx) {
            if (LOG.isErrorEnabled()) {
                LOG.error("Exception in publish(): ", illegalEx);
            }
            throw new AlfrescoRuntimeException(illegalEx.getLocalizedMessage());
        } catch (IOException ioex) {
            if (LOG.isErrorEnabled()) {
                LOG.error("Exception in publish(): ", ioex);
            }
            throw new AlfrescoRuntimeException(ioex.getLocalizedMessage());
        } catch (URISyntaxException uriSynEx) {
            if (LOG.isErrorEnabled()) {
                LOG.error("Exception in publish(): ", uriSynEx);
            }
            throw new AlfrescoRuntimeException(uriSynEx.getLocalizedMessage());
        } finally {
            httpclient.getConnectionManager().shutdown();
            if (deleteContentFileOnCompletion) {
                contentFile.delete();
            }
        }
    }
}

From source file:jfs.sync.vfs.JFSVFSFile.java

/**
 * @see JFSFile#closeInputStream()//from   w ww . java2s.c o  m
 */
protected void closeInputStream() {
    if (file != null) {
        try {
            file.getContent().close();
        } catch (IOException e) {
            JFSLog.getErr().getStream().println(e.getLocalizedMessage());
        }
    }
}

From source file:jfs.sync.vfs.JFSVFSFile.java

/**
 * @see JFSFile#closeOutputStream()/* w  ww  .  j ava 2 s. c  om*/
 */
protected void closeOutputStream() {
    if (file != null) {
        try {
            file.getContent().close();
        } catch (IOException e) {
            JFSLog.getErr().getStream().println(e.getLocalizedMessage());
        }
    }
}

From source file:fr.sanofi.fcl4transmart.controllers.listeners.clinicalData.SelectClinicalRawFileListener.java

@Override
public void handleEvent(Event event) {
    this.selectRawFilesUI.openLoadingShell();
    new Thread() {
        public void run() {
            String[] paths = selectRawFilesUI.getPath().split(File.pathSeparator, -1);
            for (int i = 0; i < paths.length; i++) {
                String path = paths[i];
                if (path == null) {
                    selectRawFilesUI.setIsLoading(false);
                    return;
                }/*www.  j av  a 2  s  .  c  o  m*/
                File rawFile = new File(path);
                if (rawFile.exists()) {
                    if (rawFile.isFile()) {
                        if (path.contains("%")) {
                            selectRawFilesUI.setMessage("File name can not contain percent ('%') symbol.");
                            selectRawFilesUI.setIsLoading(false);
                            return;
                        }
                        String newPath = dataType.getPath().getAbsolutePath() + File.separator
                                + rawFile.getName();
                        if (selectRawFilesUI.getFormat().compareTo("Tab delimited raw file") != 0
                                && selectRawFilesUI.getFormat().compareTo("SOFT") != 0) {
                            selectRawFilesUI.setMessage("File format does not exist");
                            selectRawFilesUI.setIsLoading(false);
                            return;
                        }
                        if (selectRawFilesUI.getFormat().compareTo("SOFT") == 0) {
                            File newFile = new File(newPath);
                            if (newFile.exists()) {
                                selectRawFilesUI.setMessage("File has already been added");
                                selectRawFilesUI.setIsLoading(false);
                                return;
                            } else {
                                if (createTabFileFromSoft(rawFile, newFile)) {
                                    ((ClinicalData) dataType).addRawFile(newFile);
                                    selectRawFilesUI.setMessage("File has been added");
                                }
                            }
                        } else if (selectRawFilesUI.getFormat().compareTo("Tab delimited raw file") == 0) {
                            if (!checkTabFormat(rawFile)) {
                                selectRawFilesUI.setIsLoading(false);
                                return;
                            }

                            File copiedRawFile = new File(newPath);
                            if (!copiedRawFile.exists()) {
                                try {
                                    FileUtils.copyFile(rawFile, copiedRawFile);
                                    ((ClinicalData) dataType).addRawFile(copiedRawFile);
                                    selectRawFilesUI.setMessage("File has been added");
                                } catch (IOException e) {
                                    // TODO Auto-generated catch block
                                    e.printStackTrace();
                                    selectRawFilesUI.setMessage("File error: " + e.getLocalizedMessage());
                                    selectRawFilesUI.setIsLoading(false);
                                    return;
                                }
                            } else {
                                selectRawFilesUI.setMessage("File has already been added");
                                selectRawFilesUI.setIsLoading(false);
                                return;
                            }
                        }

                    } else {
                        selectRawFilesUI.setMessage("File is a directory");
                        selectRawFilesUI.setIsLoading(false);
                        return;
                    }
                } else {
                    selectRawFilesUI.setMessage("Path does no exist");
                    selectRawFilesUI.setIsLoading(false);
                    return;
                }
            }
            selectRawFilesUI.setIsLoading(false);
        }
    }.start();
    this.selectRawFilesUI.waitForThread();
    selectRawFilesUI.updateViewer();
    WorkPart.updateSteps();
    UsedFilesPart.sendFilesChanged(dataType);
}

From source file:com.ecyrd.jspwiki.auth.authorize.XMLGroupDatabase.java

private void saveDOM() throws WikiSecurityException {
    if (m_dom == null) {
        log.fatal("Group database doesn't exist in memory.");
    }//w  w  w . j av a2s  .c  om

    File newFile = new File(m_file.getAbsolutePath() + ".new");
    try {
        BufferedWriter io = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(newFile), "UTF-8"));

        // Write the file header and document root
        io.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
        io.write("<groups>\n");

        // Write each profile as a <group> node
        for (Group group : m_groups.values()) {
            io.write("  <" + GROUP_TAG + " ");
            io.write(GROUP_NAME);
            io.write("=\"" + StringEscapeUtils.escapeXml(group.getName()) + "\" ");
            io.write(CREATOR);
            io.write("=\"" + StringEscapeUtils.escapeXml(group.getCreator()) + "\" ");
            io.write(CREATED);
            io.write("=\"" + m_format.format(group.getCreated()) + "\" ");
            io.write(MODIFIER);
            io.write("=\"" + group.getModifier() + "\" ");
            io.write(LAST_MODIFIED);
            io.write("=\"" + m_format.format(group.getLastModified()) + "\"");
            io.write(">\n");

            // Write each member as a <member> node
            for (Principal member : group.members()) {
                io.write("    <" + MEMBER_TAG + " ");
                io.write(PRINCIPAL);
                io.write("=\"" + StringEscapeUtils.escapeXml(member.getName()) + "\" ");
                io.write("/>\n");
            }

            // Close tag
            io.write("  </" + GROUP_TAG + ">\n");
        }
        io.write("</groups>");
        io.close();
    } catch (IOException e) {
        throw new WikiSecurityException(e.getLocalizedMessage(), e);
    }

    // Copy new file over old version
    File backup = new File(m_file.getAbsolutePath() + ".old");
    if (backup.exists()) {
        if (!backup.delete()) {
            log.error("Could not delete old group database backup: " + backup);
        }
    }
    if (!m_file.renameTo(backup)) {
        log.error("Could not create group database backup: " + backup);
    }
    if (!newFile.renameTo(m_file)) {
        log.error("Could not save database: " + backup + " restoring backup.");
        if (!backup.renameTo(m_file)) {
            log.error("Restore failed. Check the file permissions.");
        }
        log.error("Could not save database: " + m_file + ". Check the file permissions");
    }
}

From source file:com.wooki.test.unit.ConversionsTest.java

@Test(enabled = true)
public void docbookConversion() {
    String result = "<book>     <bookinfo>       <title>An Example Book</title>              <author>         <firstname>Your first name</firstname>         <surname>Your surname</surname>         <affiliation>           <address><email>foo@example.com</email></address>         </affiliation>       </author>          <copyright>         <year>2000</year>         <holder>Copyright string here</holder>       </copyright>          <abstract>         <para>If your book has an abstract then it should go here.</para>       </abstract>     </bookinfo>        <preface>       <title>Preface</title>          <para>Your book may have a preface, in which case it should be placed         here.</para>     </preface>              <chapter>       <title>My First Chapter</title>          <para>This is the first chapter in my book.</para>          <sect1>         <title>My First Section</title>            <para>This is the first section in my book.</para>       </sect1>     </chapter>   </book>";
    Resource resource = new ByteArrayResource(result.getBytes());
    InputStream xhtml = fromDocbookConvertor.performTransformation(resource);
    File htmlFile = null;/*from w w w.j a  va2s. c  om*/
    try {
        htmlFile = File.createTempFile("wooki", ".html");
        FileOutputStream fos = new FileOutputStream(htmlFile);
        logger.debug("HTML File is " + htmlFile.getAbsolutePath());
        byte[] content = null;
        int available = 0;
        while ((available = xhtml.available()) > 0) {
            content = new byte[available];
            xhtml.read(content);
            fos.write(content);
        }
        fos.flush();
        fos.close();
    } catch (IOException e) {
        e.printStackTrace();
        logger.error(e.getLocalizedMessage());
        return;
    }
    logger.debug("Docbook to xhtml ok");
    SAXParserFactory factory = SAXParserFactory.newInstance();

    // cration d'un parseur SAX
    SAXParser parser;
    try {
        parser = factory.newSAXParser();
        parser.parse(new InputSource(new FileInputStream(htmlFile)), htmlParser);
    } catch (ParserConfigurationException e) {
        e.printStackTrace();
        logger.error(e.getLocalizedMessage());
    } catch (SAXException e) {
        e.printStackTrace();
        logger.error(e.getLocalizedMessage());
    } catch (IOException e) {
        e.printStackTrace();
        logger.error(e.getLocalizedMessage());
    }

    Book book = htmlParser.getBook();
    logger.debug("The book title is " + book.getTitle());

}