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:fr.sanofi.fcl4transmart.controllers.listeners.geneExpression.LoadGeneExpressionDataListener.java

public void writeLog(String text) {
    File log = new File(dataType.getPath() + File.separator + "kettle.log");
    try {//from   ww  w  . j a  v  a 2 s  .  c  o  m
        FileWriter fw = new FileWriter(log);
        BufferedWriter output = new BufferedWriter(fw);
        output.write(text);
        output.close();
        ((GeneExpressionData) dataType).setLogFile(log);
    } catch (IOException ioe) {
        loadDataUI.setMessage("File error: " + ioe.getLocalizedMessage());
        ioe.printStackTrace();
    }
}

From source file:org.opentaps.common.reporting.ChartViewHandler.java

public void render(String name, String page, String info, String contentType, String encoding,
        HttpServletRequest request, HttpServletResponse response) throws ViewHandlerException {

    /*/*www .  j  ava  2 s  . c  o  m*/
     * Looks for parameter "chart" first. Send this temporary image files
     * to client if it exists and return.
     */
    String chartFileName = UtilCommon.getParameter(request, "chart");
    if (UtilValidate.isNotEmpty(chartFileName)) {
        try {
            ServletUtilities.sendTempFile(chartFileName, response);
            if (chartFileName.indexOf(ServletUtilities.getTempOneTimeFilePrefix()) != -1) {
                // delete temporary file
                File file = new File(System.getProperty("java.io.tmpdir"), chartFileName);
                file.delete();
            }
        } catch (IOException ioe) {
            Debug.logError(ioe.getLocalizedMessage(), module);
        }
        return;
    }

    /*
     * Next option eliminate need to store chart in file system. Some event handler
     * included in request chain prior to this view handler can prepare ready to use
     * instance of JFreeChart and place it to request attribute chartContext.
     * Currently chartContext should be Map<String, Object> and we expect to see in it:
     *   "charObject"       : JFreeChart
     *   "width"            : positive Integer
     *   "height"           : positive Integer
     *   "encodeAlpha"      : Boolean (optional)
     *   "compressRatio"    : Integer in range 0-9 (optional)
     */
    Map<String, Object> chartContext = (Map<String, Object>) request.getAttribute("chartContext");
    if (UtilValidate.isNotEmpty(chartContext)) {
        try {
            sendChart(chartContext, response);
        } catch (IOException ioe) {
            Debug.logError(ioe.getLocalizedMessage(), module);
        }
        return;
    }

    /*
     * Prepare context for next options
     */
    Map<String, Object> callContext = FastMap.newInstance();
    callContext.put("parameters", UtilHttp.getParameterMap(request));
    callContext.put("delegator", request.getAttribute("delegator"));
    callContext.put("dispatcher", request.getAttribute("dispatcher"));
    callContext.put("userLogin", request.getSession().getAttribute("userLogin"));
    callContext.put("locale", UtilHttp.getLocale(request));

    /*
     * view-map attribute "page" may contain BeanShell script in component
     * URL format that should return chartContext map.
     */
    if (UtilValidate.isNotEmpty(page) && UtilValidate.isUrl(page) && page.endsWith(".bsh")) {
        try {
            chartContext = (Map<String, Object>) BshUtil.runBshAtLocation(page, callContext);
            if (UtilValidate.isNotEmpty(chartContext)) {
                sendChart(chartContext, response);
            }
        } catch (GeneralException ge) {
            Debug.logError(ge.getLocalizedMessage(), module);
        } catch (IOException ioe) {
            Debug.logError(ioe.getLocalizedMessage(), module);
        }
        return;
    }

    /*
     * As last resort we can decide that "page" attribute contains class name and "info"
     * contains method Map<String, Object> getSomeChart(Map<String, Object> context).
     * There are parameters, delegator, dispatcher, userLogin and locale in the context.
     * Should return chartContext.
     */
    if (UtilValidate.isNotEmpty(page) && UtilValidate.isNotEmpty(info)) {
        Class handler = null;
        synchronized (this) {
            ClassLoader loader = Thread.currentThread().getContextClassLoader();
            try {
                handler = loader.loadClass(page);
                if (handler != null) {
                    Method runMethod = handler.getMethod(info, new Class[] { Map.class });
                    chartContext = (Map<String, Object>) runMethod.invoke(null, callContext);
                    if (UtilValidate.isNotEmpty(chartContext)) {
                        sendChart(chartContext, response);
                    }
                }
            } catch (ClassNotFoundException cnfe) {
                Debug.logError(cnfe.getLocalizedMessage(), module);
            } catch (SecurityException se) {
                Debug.logError(se.getLocalizedMessage(), module);
            } catch (NoSuchMethodException nsme) {
                Debug.logError(nsme.getLocalizedMessage(), module);
            } catch (IllegalArgumentException iae) {
                Debug.logError(iae.getLocalizedMessage(), module);
            } catch (IllegalAccessException iace) {
                Debug.logError(iace.getLocalizedMessage(), module);
            } catch (InvocationTargetException ite) {
                Debug.logError(ite.getLocalizedMessage(), module);
            } catch (IOException ioe) {
                Debug.logError(ioe.getLocalizedMessage(), module);
            }
        }
    }

    // Why you disturb me?
    throw new ViewHandlerException(
            "In order to generate chart you have to provide chart object or file name. There are no such data in request. Please read comments to ChartViewHandler class.");
}

From source file:com.thalesgroup.hudson.plugins.cppcheck.CppcheckSource.java

/**
 * Builds the file content.// w w w.j a v a  2  s  . co m
 */
private void buildFileContent() {
    InputStream is = null;
    try {
        File tempFile = new File(cppcheckWorkspaceFile.getTempName(owner));
        if (tempFile.exists()) {
            is = new FileInputStream(tempFile);
        } else {
            // Reading real workspace file is more incorrect than correct,
            // but the code is left here for backward compatibility with
            // plugin version 1.14 and less
            if (cppcheckWorkspaceFile.getFileName() == null) {
                throw new IOException("The file doesn't exist.");
            }

            File file = new File(cppcheckWorkspaceFile.getFileName());
            if (!file.exists()) {
                throw new IOException("Can't access the file: " + file.toURI());
            }
            is = new FileInputStream(file);
        }

        splitSourceFile(highlightSource(is));
    } catch (IOException exception) {
        sourceCode = "Can't read file: " + exception.getLocalizedMessage();
    } catch (RuntimeException re) {
        sourceCode = "Problem for display the source code content: " + re.getLocalizedMessage();
    } finally {
        IOUtils.closeQuietly(is);
    }
}

From source file:fr.sanofi.fcl4transmart.controllers.listeners.geneExpression.LoadGeneExpressionDataListener.java

public void write(String text) {
    FileDialog fd = new FileDialog(new Shell());
    fd.setText("Choose a log file");
    String filePath = fd.open();/*from   w w w .j  a va2  s . co  m*/
    try {
        FileWriter fw = new FileWriter(filePath, true);
        BufferedWriter output = new BufferedWriter(fw);
        output.write(text);
        output.flush();
        output.close();
    } catch (IOException ioe) {
        loadDataUI.displayMessage("File error: " + ioe.getLocalizedMessage());
        ioe.printStackTrace();
    }
}

From source file:me.crime.loader.DataBaseLoader.java

public void loadURCTable() throws SQLException, ClassNotFoundException {
    URCCatagoriesDAO dao = URCCatagoriesDAO.class
            .cast(DaoBeanFactory.create().getDaoBean(URCCatagoriesDAO.class));

    // Read in the URC Codes.
    InputStream s = ClassLoader.getSystemResourceAsStream("me/crime/loader/CrimeData.txt");
    if (s == null) {
        log_.error("unable to find me/crime/loader/CrimeData.txt");
    } else {/*from  w ww .  ja  v  a2  s  . c o m*/

        try {
            BufferedReader bf = new BufferedReader(new InputStreamReader(s));

            while (bf.ready()) {
                String word = bf.readLine().trim().toUpperCase();
                if (!word.startsWith("#")) {
                    if (word.length() > 0) {
                        String[] info = word.split(",");
                        URCCatagories urc = dao.findURCbyCatagory(info[0]);
                        if (urc == null) {

                            urc = new URCCatagories();

                            int rank = Integer.parseInt(info[1].trim());

                            if (rank == 1) {
                                urc.setCatagorie(info[0].trim());
                                urc.setCrimeGroup(info[3].trim());
                                dao.save(urc);
                            }
                        }
                    }
                }

            }
            bf.close();

        } catch (IOException e) {
            log_.error(e.getLocalizedMessage(), e);
        }

    }

}

From source file:es.urjc.mctwp.image.impl.analyze.AnalyzeImagePlugin.java

@Override
public Image loadImage(File file) throws ImageException {
    Image result = null;/*from  ww  w .  ja  v  a2 s .  c  o m*/

    if (file != null) {
        try {
            String name = ImageUtils.getFileName(file);

            if (file.isDirectory()) {
                File header = null;
                File data = null;

                //Get header and data files into directory
                File[] list = file.listFiles();
                if (list != null)
                    for (File auxFile : list) {
                        String ext = ImageUtils.getFileExtension(auxFile);
                        if (ComplexAnalyzeImageImpl.ANALYZE_HDR_EXT.equals(ext))
                            header = auxFile;
                        if (ComplexAnalyzeImageImpl.ANALYZE_IMG_EXT.equals(ext))
                            data = auxFile;
                    }

                if (header != null && data != null) {
                    if (checkFormat(header)) {
                        ComplexAnalyzeImageImpl aux = new ComplexAnalyzeImageImpl();
                        aux.setHeader(header);
                        aux.setData(data);
                        aux.setId(name);
                        result = aux;
                    }
                }
            } else if (file.isFile()) {
                if (checkFormat(file) && isNifti(file)) {
                    SingleAnalyzeImageImpl aux = new SingleAnalyzeImageImpl();
                    aux.setContent(file);
                    aux.setId(name);
                    result = aux;
                }
            }
        } catch (IOException e) {
            logger.error(e.getLocalizedMessage());
        }
    }

    return result;
}

From source file:de.dev.eth0.elasticsearch.aem.indexing.ElasticSearchTransportHandler.java

/**
 *
 * @param ctx//w  w  w  .jav  a  2  s .c  o  m
 * @param tx
 * @return
 * @throws ReplicationException
 */
@Override
public ReplicationResult deliver(TransportContext ctx, ReplicationTransaction tx) throws ReplicationException {
    ReplicationLog log = tx.getLog();
    try {
        RestClient restClient = elasticSearchService.getRestClient();
        ReplicationActionType replicationType = tx.getAction().getType();
        if (replicationType == ReplicationActionType.TEST) {
            return doTest(ctx, tx, restClient);
        } else {
            log.info(getClass().getSimpleName() + ": ---------------------------------------");
            if (tx.getContent() == ReplicationContent.VOID) {
                LOG.warn("No Replication Content provided");
                return new ReplicationResult(true, 0,
                        "No Replication Content provided for path " + tx.getAction().getPath());
            }
            switch (replicationType) {
            case ACTIVATE:
                return doActivate(ctx, tx, restClient);
            case DEACTIVATE:
                return doDeactivate(ctx, tx, restClient);
            default:
                log.warn(getClass().getSimpleName() + ": Replication action type" + replicationType
                        + " not supported.");
                throw new ReplicationException(
                        "Replication action type " + replicationType + " not supported.");
            }
        }
    } catch (JSONException jex) {
        LOG.error("JSON was invalid", jex);
        return new ReplicationResult(false, 0, jex.getLocalizedMessage());
    } catch (IOException ioe) {
        log.error(getClass().getSimpleName() + ": Could not perform Indexing due to "
                + ioe.getLocalizedMessage());
        LOG.error("Could not perform Indexing", ioe);
        return new ReplicationResult(false, 0, ioe.getLocalizedMessage());
    }
}

From source file:org.deegree.maven.WorkspaceITMojo.java

@Override
public void execute() throws MojoExecutionException, MojoFailureException {
    Set<?> artifacts = project.getDependencyArtifacts();
    Set<Artifact> workspaces = new HashSet<Artifact>();
    for (Object o : artifacts) {
        Artifact a = (Artifact) o;//from   ww  w . j  av a  2 s . c  o  m
        if (a.getType() != null && a.getType().equals("deegree-workspace")) {
            workspaces.add(a);
        }
    }

    ServiceIntegrationTestHelper helper = new ServiceIntegrationTestHelper(project, getLog());
    for (Artifact a : workspaces) {
        getLog().info("Testing workspace " + a.getArtifactId());

        String url = helper.createBaseURL() + "config/upload/iut.zip";
        File file = a.getFile();
        try {
            HttpClient client = HttpUtils.getAuthenticatedHttpClient(helper);

            getLog().info("Sending against: " + helper.createBaseURL() + "config/delete/iut");
            HttpGet get = new HttpGet(helper.createBaseURL() + "config/delete/iut");
            HttpResponse resp = client.execute(get);
            String response = EntityUtils.toString(resp.getEntity(), "UTF-8").trim();
            getLog().info("Response after initially deleting iut was: " + response);

            getLog().info("Sending against: " + helper.createBaseURL() + "config/restart");
            get = new HttpGet(helper.createBaseURL() + "config/restart");
            resp = client.execute(get);
            response = EntityUtils.toString(resp.getEntity(), "UTF-8").trim();
            getLog().info("Response after initial restart was: " + response);

            getLog().info("Sending against: " + url);
            HttpPost post = new HttpPost(url);
            post.setEntity(new FileEntity(file, null));
            resp = client.execute(post);
            response = EntityUtils.toString(resp.getEntity()).trim();
            getLog().info("Response after uploading was: " + response);

            getLog().info("Sending against: " + helper.createBaseURL() + "config/restart/iut");
            get = new HttpGet(helper.createBaseURL() + "config/restart/iut");
            resp = client.execute(get);
            response = EntityUtils.toString(resp.getEntity(), "UTF-8").trim();
            getLog().info("Response after starting workspace was: " + response);
        } catch (IOException e) {
            throw new MojoFailureException(
                    "Could not test workspace " + a.getArtifactId() + ": " + e.getLocalizedMessage(), e);
        }

        try {
            String s = get(UTF8STRING, helper.createBaseURL() + "config/list/iut/services/", null, "deegree",
                    "deegree");
            String[] services = s.split("\\s");

            for (String srv : services) {
                String nm = new File(srv).getName().toLowerCase();
                if (nm.length() != 7) {
                    continue;
                }
                String service = nm.substring(0, 3).toUpperCase();
                helper.testCapabilities(service);
                helper.testLayers(service);
                getLog().info("All maps can be requested.");
            }
            String response = get(UTF8STRING, helper.createBaseURL() + "config/delete/iut", null, "deegree",
                    "deegree").trim();
            getLog().info("Response after finally deleting iut was: " + response);
        } catch (IOException e) {
            getLog().debug(e);
            throw new MojoFailureException(
                    "Could not test workspace " + a.getArtifactId() + ": " + e.getLocalizedMessage(), e);
        }
    }
}

From source file:com.willwinder.ugp.tools.GcodeTilerTopComponent.java

private void generateGcode() {
    if (!loadDimensions())
        return;/*from w  w w. j  av  a  2s  . com*/

    Path path = null;
    try {
        path = Files.createTempFile("dowel_program", ".gcode");
        File file = path.toFile();
        generateAndLoadGcode(file);
    } catch (IOException e) {
        GUIHelpers.displayErrorDialog(ERROR_LOADING + e.getLocalizedMessage());
    }
}

From source file:es.urjc.mctwp.image.impl.analyze.AnalyzeImagePlugin.java

@Override
public Image createImage(File file) throws ImageException {
    Image res = null;/*ww  w. j  a  v  a 2  s .  c  o m*/

    //Check extension and image. It can not be null
    String ext = ImageUtils.getFileExtension(file);

    if (ext != null && !ext.isEmpty()) {
        String name = ImageUtils.getFileName(file);
        boolean isSingle = ext.equals(SingleAnalyzeImageImpl.NIFIT_EXT);
        boolean isComplex = ext.equals(ComplexAnalyzeImageImpl.ANALYZE_HDR_EXT);

        try {
            if (isSingle || isComplex) {
                if (checkFormat(file)) {
                    if (isSingle) {
                        if (isNifti(file)) {
                            SingleAnalyzeImageImpl aux = new SingleAnalyzeImageImpl();
                            aux.setContent(file);
                            aux.setId(getUniqueImageId());
                            res = aux;
                        } else {
                            String error = "File : [" + file.getAbsolutePath() + "] is not NIFTI compliant";
                            logger.error(error);
                            throw new ImageException(error);
                        }
                    } else {
                        filter.setBaseName(name);
                        File[] list = file.getParentFile().listFiles(filter);

                        if (list != null && list.length == 1) {
                            File data = list[0];
                            ComplexAnalyzeImageImpl aux = new ComplexAnalyzeImageImpl();
                            aux.setHeader(file);
                            aux.setData(data);
                            aux.setId(getUniqueImageId());
                            res = aux;
                        } else {
                            String error = "There is no image data for file : [" + file.getName() + "]";
                            logger.error(error);
                            throw new ImageException(error);
                        }
                    }
                }
            }
        } catch (IOException e) {
            logger.error(e.getLocalizedMessage());
        }
    }

    return res;
}